[cairo-commit] 10 commits - boilerplate/cairo-boilerplate-beos.cpp boilerplate/cairo-boilerplate-cogl.c boilerplate/cairo-boilerplate-directfb.c boilerplate/cairo-boilerplate-drm.c boilerplate/cairo-boilerplate-qt.cpp boilerplate/cairo-boilerplate-skia.c boilerplate/cairo-boilerplate-vg.c boilerplate/Makefile.am boilerplate/Makefile.sources boilerplate/Makefile.win32.features boilerplate/meson.build build/configure.ac.features build/configure.ac.tools build/Makefile.win32.features build/Makefile.win32.features-h configure.ac doc/public .gitlab-ci.yml meson.build meson_options.txt perf/cairo-perf.c README src/cairo-beos.h src/cairo-beos-surface.cpp src/cairo-cogl-gradient.c src/cairo-cogl-gradient-private.h src/cairo-cogl.h src/cairo-cogl-private.h src/cairo-cogl-surface.c src/cairo-debug.c src/cairo-directfb.h src/cairo-directfb-surface.c src/cairo-drm.h src/cairoint.h src/cairo-mutex-impl-private.h src/cairo-mutex-list-private.h src/cairo-os2.h src/cairo-os2-private.h src/cairo-os2-surfac e.c src/cairo-qt.h src/cairo-qt-surface.cpp src/cairo-time.c src/cairo-vg.h src/cairo-vg-surface.c src/check-headers.sh src/drm src/Makefile.am src/Makefile.am.analysis src/Makefile.sources src/Makefile.win32.features src/meson.build test/api-special-cases.c test/error-setters.c util/cairo-trace

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Feb 25 15:44:54 UTC 2022


 .gitlab-ci.yml                            |    4 
 README                                    |   16 
 boilerplate/Makefile.am                   |   26 
 boilerplate/Makefile.sources              |    7 
 boilerplate/Makefile.win32.features       |  170 -
 boilerplate/cairo-boilerplate-beos.cpp    |  273 -
 boilerplate/cairo-boilerplate-cogl.c      |  217 -
 boilerplate/cairo-boilerplate-directfb.c  |  235 -
 boilerplate/cairo-boilerplate-drm.c       |  112 
 boilerplate/cairo-boilerplate-qt.cpp      |  114 
 boilerplate/cairo-boilerplate-skia.c      |   55 
 boilerplate/cairo-boilerplate-vg.c        |  364 --
 boilerplate/meson.build                   |    5 
 build/Makefile.win32.features             |    7 
 build/Makefile.win32.features-h           |   21 
 build/configure.ac.features               |   14 
 build/configure.ac.tools                  |    1 
 configure.ac                              |  101 
 doc/public/Makefile.am                    |    1 
 doc/public/cairo-docs.xml                 |    1 
 doc/public/cairo-sections.txt             |   12 
 doc/public/language-bindings.xml          |    1 
 doc/public/meson.build                    |    1 
 meson.build                               |   89 
 meson_options.txt                         |    5 
 perf/cairo-perf.c                         |    9 
 src/Makefile.am                           |   22 
 src/Makefile.am.analysis                  |    4 
 src/Makefile.sources                      |   56 
 src/Makefile.win32.features               |  202 -
 src/cairo-beos-surface.cpp                |  984 -------
 src/cairo-beos.h                          |   60 
 src/cairo-cogl-gradient-private.h         |   90 
 src/cairo-cogl-gradient.c                 |  678 ----
 src/cairo-cogl-private.h                  |  164 -
 src/cairo-cogl-surface.c                  | 4106 ------------------------------
 src/cairo-cogl.h                          |   86 
 src/cairo-debug.c                         |    4 
 src/cairo-directfb-surface.c              |  545 ---
 src/cairo-directfb.h                      |   67 
 src/cairo-drm.h                           |  120 
 src/cairo-mutex-impl-private.h            |   26 
 src/cairo-mutex-list-private.h            |    3 
 src/cairo-os2-private.h                   |   67 
 src/cairo-os2-surface.c                   | 1416 ----------
 src/cairo-os2.h                           |  110 
 src/cairo-qt-surface.cpp                  | 1741 ------------
 src/cairo-qt.h                            |   85 
 src/cairo-time.c                          |   28 
 src/cairo-vg-surface.c                    | 1854 -------------
 src/cairo-vg.h                            |  103 
 src/cairoint.h                            |   12 
 src/check-headers.sh                      |    2 
 src/drm/cairo-drm-bo.c                    |   99 
 src/drm/cairo-drm-gallium-surface.c       |  826 ------
 src/drm/cairo-drm-i915-glyphs.c           |  566 ----
 src/drm/cairo-drm-i915-private.h          | 1270 ---------
 src/drm/cairo-drm-i915-shader.c           | 2859 --------------------
 src/drm/cairo-drm-i915-spans.c            |  799 -----
 src/drm/cairo-drm-i915-surface.c          | 2942 ---------------------
 src/drm/cairo-drm-i965-glyphs.c           |  506 ---
 src/drm/cairo-drm-i965-private.h          |  737 -----
 src/drm/cairo-drm-i965-shader.c           | 2825 --------------------
 src/drm/cairo-drm-i965-spans.c            |  407 --
 src/drm/cairo-drm-i965-surface.c          | 1926 --------------
 src/drm/cairo-drm-intel-brw-defines.h     |  824 ------
 src/drm/cairo-drm-intel-brw-eu-emit.c     | 1089 -------
 src/drm/cairo-drm-intel-brw-eu-util.c     |  121 
 src/drm/cairo-drm-intel-brw-eu.c          |  250 -
 src/drm/cairo-drm-intel-brw-eu.h          | 1044 -------
 src/drm/cairo-drm-intel-brw-structs.h     | 1329 ---------
 src/drm/cairo-drm-intel-command-private.h |  909 ------
 src/drm/cairo-drm-intel-debug.c           | 1209 --------
 src/drm/cairo-drm-intel-ioctl-private.h   |   45 
 src/drm/cairo-drm-intel-private.h         |  515 ---
 src/drm/cairo-drm-intel-surface.c         |  454 ---
 src/drm/cairo-drm-intel.c                 | 1348 ---------
 src/drm/cairo-drm-private.h               |  238 -
 src/drm/cairo-drm-radeon-private.h        |  103 
 src/drm/cairo-drm-radeon-surface.c        |  454 ---
 src/drm/cairo-drm-radeon.c                |  331 --
 src/drm/cairo-drm-surface.c               |  369 --
 src/drm/cairo-drm.c                       |  390 --
 src/meson.build                           |   38 
 test/api-special-cases.c                  |    3 
 test/error-setters.c                      |    9 
 util/cairo-trace/trace.c                  |   79 
 87 files changed, 14 insertions(+), 41395 deletions(-)

New commits:
commit 1781e59c570f6eb85456e5ee9119dbce017f1a79
Merge: ebba42b19 9cfa51046
Author: Uli Schlachter <psychon at znc.in>
Date:   Fri Feb 25 15:44:51 2022 +0000

    Merge branch 'drop-backends' into 'master'
    
    Remove old backends
    
    See merge request cairo/cairo!285

commit 9cfa5104648bb6ebaa264a2b427a8a991faee570
Author: Emmanuele Bassi <ebassi at gnome.org>
Date:   Fri Feb 25 12:54:11 2022 +0000

    ci: Make Windows jobs manual
    
    The CI runners for Windows are currently timing out on the fd.o
    infrastructure. The issue is being worked on, but we should avoid
    blocking our entire CI pipeline until it's fixed, as it sounds it is
    going to take a while.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 291898c6f..46cc5f0cf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -263,11 +263,13 @@ meson vs2017 amd64:
   extends: '.build meson windows'
   variables:
     ARCH: 'amd64'
+  when: 'manual'
 
 meson vs2017 x86:
   extends: '.build meson windows'
   variables:
     ARCH: 'x86'
+  when: 'manual'
 
 meson android arm64 fedora:
   # TODO: should probably build our own image here some day
commit 9b9028c160a404771fe0caeecda8f4248997a808
Author: Emmanuele Bassi <ebassi at gnome.org>
Date:   Sun Apr 18 00:02:45 2021 +0100

    Drop cairo-vg surface
    
    OpenVG is a failed experiment from 10 years ago, and nobody has been
    using the cairo-vg surface in pretty much the same amount of time.

diff --git a/boilerplate/Makefile.sources b/boilerplate/Makefile.sources
index ad96a89bc..a9bc20ccb 100644
--- a/boilerplate/Makefile.sources
+++ b/boilerplate/Makefile.sources
@@ -32,4 +32,3 @@ cairo_boilerplate_win32_sources = cairo-boilerplate-win32.c cairo-boilerplate-wi
 cairo_boilerplate_xcb_sources = cairo-boilerplate-xcb.c
 cairo_boilerplate_xlib_headers = cairo-boilerplate-xlib.h
 cairo_boilerplate_xlib_sources = cairo-boilerplate-xlib.c
-cairo_boilerplate_vg_sources = cairo-boilerplate-vg.c
diff --git a/boilerplate/Makefile.win32.features b/boilerplate/Makefile.win32.features
index 0dc297a28..c2415afae 100644
--- a/boilerplate/Makefile.win32.features
+++ b/boilerplate/Makefile.win32.features
@@ -157,16 +157,6 @@ enabled_cairo_boilerplate_private += $(cairo_boilerplate_glesv3_private)
 enabled_cairo_boilerplate_sources += $(cairo_boilerplate_glesv3_sources)
 endif
 
-unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_vg_headers)
-all_cairo_boilerplate_headers += $(cairo_boilerplate_vg_headers)
-all_cairo_boilerplate_private += $(cairo_boilerplate_vg_private)
-all_cairo_boilerplate_sources += $(cairo_boilerplate_vg_sources)
-ifeq ($(CAIRO_HAS_VG_SURFACE),1)
-enabled_cairo_boilerplate_headers += $(cairo_boilerplate_vg_headers)
-enabled_cairo_boilerplate_private += $(cairo_boilerplate_vg_private)
-enabled_cairo_boilerplate_sources += $(cairo_boilerplate_vg_sources)
-endif
-
 supported_cairo_boilerplate_headers += $(cairo_boilerplate_egl_headers)
 all_cairo_boilerplate_headers += $(cairo_boilerplate_egl_headers)
 all_cairo_boilerplate_private += $(cairo_boilerplate_egl_private)
diff --git a/boilerplate/cairo-boilerplate-vg.c b/boilerplate/cairo-boilerplate-vg.c
deleted file mode 100644
index 4ea6ba46b..000000000
--- a/boilerplate/cairo-boilerplate-vg.c
+++ /dev/null
@@ -1,364 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Chris Wilson.
- */
-
-#include "cairo-boilerplate-private.h"
-#include "cairo-malloc-private.h"
-
-#include <cairo-vg.h>
-
- /* XXX Not sure how to handle library specific context initialization */
-//#define USE_SHIVA
-//#define USE_AMANITH
-
-#if CAIRO_HAS_GLX_FUNCTIONS
-
-#include <X11/Xlib.h>
-#include <GL/glx.h>
-
-typedef struct _vg_closure {
-    Display *dpy;
-    int screen;
-    Window win;
-
-    GLXContext ctx;
-    cairo_surface_t *surface;
-} vg_closure_glx_t;
-
-static void
-_cairo_boilerplate_vg_cleanup_glx (void *closure)
-{
-    vg_closure_glx_t *vgc = closure;
-
-#ifdef USE_AMANITH
-    vgDestroyContextAM ();
-#endif
-#ifdef USE_SHIVA
-    vgDestroyContextSH ();
-#endif
-
-    glXDestroyContext (vgc->dpy, vgc->ctx);
-    XDestroyWindow (vgc->dpy, vgc->win);
-    XCloseDisplay (vgc->dpy);
-    free (vgc);
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_vg_create_surface_glx (const char		    *name,
-					  cairo_content_t	     content,
-					  double		     width,
-					  double		     height,
-					  double		     max_width,
-					  double		     max_height,
-					  cairo_boilerplate_mode_t   mode,
-					  void			   **closure)
-{
-    int rgba_attribs[] = {
-	GLX_RGBA,
-	GLX_RED_SIZE, 1,
-	GLX_GREEN_SIZE, 1,
-	GLX_BLUE_SIZE, 1,
-	GLX_ALPHA_SIZE, 1,
-	GLX_DOUBLEBUFFER,
-	GLX_NONE
-    };
-    int rgb_attribs[] = {
-	GLX_RGBA,
-	GLX_RED_SIZE, 1,
-	GLX_GREEN_SIZE, 1,
-	GLX_BLUE_SIZE, 1,
-	GLX_DOUBLEBUFFER,
-	GLX_NONE
-    };
-    XVisualInfo *vi;
-    Display *dpy;
-    Colormap cmap;
-    XSetWindowAttributes swa;
-    cairo_surface_t *surface;
-    cairo_vg_context_t *context;
-    vg_closure_glx_t *vgc;
-
-    vgc = _cairo_malloc (sizeof (vg_closure_glx_t));
-    *closure = vgc;
-
-    if (width == 0)
-	width = 1;
-    if (height == 0)
-	height = 1;
-
-    dpy = XOpenDisplay (NULL);
-    vgc->dpy = dpy;
-    if (vgc->dpy == NULL) {
-	fprintf (stderr, "Failed to open display: %s\n", XDisplayName(0));
-	free (vgc);
-	return NULL;
-    }
-
-    if (content == CAIRO_CONTENT_COLOR)
-	vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgb_attribs);
-    else
-	vi = glXChooseVisual (dpy, DefaultScreen (dpy), rgba_attribs);
-
-    if (vi == NULL) {
-	fprintf (stderr, "Failed to create RGB, double-buffered visual\n");
-	XCloseDisplay (dpy);
-	free (vgc);
-	return NULL;
-    }
-
-    vgc->ctx = glXCreateContext (dpy, vi, NULL, True);
-    cmap = XCreateColormap (dpy,
-			    RootWindow (dpy, vi->screen),
-			    vi->visual,
-			    AllocNone);
-    swa.colormap = cmap;
-    swa.border_pixel = 0;
-    vgc->win = XCreateWindow (dpy, RootWindow (dpy, vi->screen),
-			      -1, -1, 1, 1, 0,
-			      vi->depth,
-			      InputOutput,
-			      vi->visual,
-			      CWBorderPixel | CWColormap, &swa);
-    XFreeColormap (dpy, cmap);
-    XFree (vi);
-
-    XMapWindow (dpy, vgc->win);
-
-    /* we need an active context to initialise VG */
-    glXMakeContextCurrent (dpy, vgc->win, vgc->win, vgc->ctx);
-
-#ifdef USE_AMANITH
-    vgInitContextAM (width, height, VG_FALSE, VG_TRUE);
-#endif
-#ifdef USE_SHIVA
-    vgCreateContextSH (width, height);
-#endif
-
-    context = cairo_vg_context_create_for_glx (dpy, vgc->ctx);
-    vgc->surface = cairo_vg_surface_create (context, content, width, height);
-    cairo_vg_context_destroy (context);
-
-    surface = vgc->surface;
-    if (cairo_surface_status (surface))
-	_cairo_boilerplate_vg_cleanup_glx (vgc);
-
-    return surface;
-}
-#endif
-
-#if CAIRO_HAS_EGL_FUNCTIONS
-typedef struct _vg_closure_egl {
-    EGLDisplay *dpy;
-    EGLContext *ctx;
-    EGLSurface *dummy;
-} vg_closure_egl_t;
-
-static void
-_cairo_boilerplate_vg_cleanup_egl (void *closure)
-{
-    vg_closure_egl_t *vgc = closure;
-
-#ifdef USE_AMANITH
-    vgDestroyContextAM ();
-#endif
-#ifdef USE_SHIVA
-    vgDestroyContextSH ();
-#endif
-
-    eglDestroyContext (vgc->dpy, vgc->ctx);
-    eglDestroySurface (vgc->dpy, vgc->dummy);
-    eglTerminate (vgc->dpy);
-    free (vgc);
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_vg_create_surface_egl (const char		    *name,
-					  cairo_content_t	     content,
-					  double		     width,
-					  double		     height,
-					  double		     max_width,
-					  double		     max_height,
-					  cairo_boilerplate_mode_t   mode,
-					  void			   **closure)
-{
-    int rgba_attribs[] = {
-	EGL_RED_SIZE, 8,
-	EGL_GREEN_SIZE, 8,
-	EGL_BLUE_SIZE, 8,
-	EGL_ALPHA_SIZE, 8,
-	EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
-	EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
-	EGL_NONE
-    };
-    int rgb_attribs[] = {
-	EGL_RED_SIZE, 8,
-	EGL_GREEN_SIZE, 8,
-	EGL_BLUE_SIZE, 8,
-	EGL_ALPHA_SIZE, 8,
-	EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE_BIT,
-	EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
-	EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
-	EGL_NONE
-    };
-    int dummy_attribs[] = {
-	EGL_WIDTH, 8, EGL_HEIGHT, 8,
-	EGL_NONE
-    };
-    EGLDisplay *dpy;
-    int major, minor;
-    EGLConfig config;
-    int num_configs;
-    EGLContext *egl_context;
-    EGLSurface *dummy;
-    cairo_vg_context_t *context;
-    cairo_surface_t *surface;
-    vg_closure_egl_t *vgc;
-
-    dpy = eglGetDisplay (EGL_DEFAULT_DISPLAY);
-
-    if (! eglInitialize (dpy, &major, &minor))
-	return NULL;
-
-    eglBindAPI (EGL_OPENVG_API);
-
-    if (! eglChooseConfig (dpy,
-			   content == CAIRO_CONTENT_COLOR_ALPHA ?
-			   rgba_attribs : rgb_attribs,
-			   &config, 1, &num_configs) ||
-	num_configs != 1)
-    {
-	return NULL;
-    }
-
-    egl_context = eglCreateContext (dpy, config, NULL, NULL);
-    if (egl_context == NULL)
-	return NULL;
-
-    /* Create a dummy surface in order to enable a context to initialise VG */
-    dummy = eglCreatePbufferSurface (dpy, config, dummy_attribs);
-    if (dummy == NULL)
-	return NULL;
-    if (! eglMakeCurrent (dpy, dummy, dummy, egl_context))
-	return NULL;
-
-#ifdef USE_AMANITH
-    vgInitContextAM (width, height, VG_FALSE, VG_TRUE);
-#endif
-#ifdef USE_SHIVA
-    vgCreateContextSH (width, height);
-#endif
-
-    vgc = xmalloc (sizeof (vg_closure_egl_t));
-    vgc->dpy = dpy;
-    vgc->ctx = egl_context;
-    vgc->dummy = dummy;
-    *closure = vgc;
-
-    context = cairo_vg_context_create_for_egl (vgc->dpy, vgc->ctx);
-    surface = cairo_vg_surface_create (context, content, width, height);
-    cairo_vg_context_destroy (context);
-
-    if (cairo_surface_status (surface))
-	_cairo_boilerplate_vg_cleanup_egl (vgc);
-
-    return surface;
-}
-#endif
-
-static void
-_cairo_boilerplate_vg_synchronize (void *closure)
-{
-    vgFinish ();
-}
-
-static const cairo_boilerplate_target_t targets[] = {
-#if CAIRO_HAS_GLX_FUNCTIONS
-    {
-	"vg-glx", "vg", NULL, NULL,
-	CAIRO_SURFACE_TYPE_VG, CAIRO_CONTENT_COLOR_ALPHA, 1,
-	"cairo_vg_context_create_for_glx",
-	_cairo_boilerplate_vg_create_surface_glx,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_vg_cleanup_glx,
-	_cairo_boilerplate_vg_synchronize,
-        NULL,
-	TRUE, FALSE, FALSE
-    },
-    {
-	"vg-glx", "vg", NULL, NULL,
-	CAIRO_SURFACE_TYPE_VG, CAIRO_CONTENT_COLOR, 1,
-	"cairo_vg_context_create_for_glx",
-	_cairo_boilerplate_vg_create_surface_glx,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_vg_cleanup_glx,
-	_cairo_boilerplate_vg_synchronize,
-        NULL,
-	FALSE, FALSE, FALSE
-    },
-#endif
-#if CAIRO_HAS_EGL_FUNCTIONS
-    {
-	"vg-egl", "vg", NULL, NULL,
-	CAIRO_SURFACE_TYPE_VG, CAIRO_CONTENT_COLOR_ALPHA, 1,
-	"cairo_vg_context_create_for_egl",
-	_cairo_boilerplate_vg_create_surface_egl,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_vg_cleanup_egl,
-	_cairo_boilerplate_vg_synchronize,
-        NULL,
-	TRUE, FALSE, FALSE
-    },
-    {
-	"vg-egl", "vg", NULL, NULL,
-	CAIRO_SURFACE_TYPE_VG, CAIRO_CONTENT_COLOR, 1,
-	"cairo_vg_context_create_for_egl",
-	_cairo_boilerplate_vg_create_surface_egl,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_vg_cleanup_egl,
-	_cairo_boilerplate_vg_synchronize,
-        NULL,
-	FALSE, FALSE, FALSE
-    },
-#endif
-};
-CAIRO_BOILERPLATE (vg, targets)
diff --git a/boilerplate/meson.build b/boilerplate/meson.build
index 39432fc16..7f663c273 100644
--- a/boilerplate/meson.build
+++ b/boilerplate/meson.build
@@ -12,7 +12,6 @@ cairo_boilerplate_feature_sources = {
   'cairo-pdf': ['cairo-boilerplate-pdf.c'],
   'cairo-ps': ['cairo-boilerplate-ps.c'],
   'cairo-svg': ['cairo-boilerplate-svg.c'],
-  'cairo-vg': ['cairo-boilerplate-vg.c'],
   'cairo-script': ['cairo-boilerplate-script.c'],
   # All tests crash with FPE
   # 'cairo-egl': ['cairo-boilerplate-egl.c'],
diff --git a/build/Makefile.win32.features b/build/Makefile.win32.features
index c398bcba5..2b4908bc0 100644
--- a/build/Makefile.win32.features
+++ b/build/Makefile.win32.features
@@ -15,7 +15,6 @@ CAIRO_HAS_GL_SURFACE=0
 CAIRO_HAS_GLESV2_SURFACE=0
 CAIRO_HAS_GLESV3_SURFACE=0
 CAIRO_HAS_DIRECTFB_SURFACE=0
-CAIRO_HAS_VG_SURFACE=0
 CAIRO_HAS_EGL_FUNCTIONS=0
 CAIRO_HAS_GLX_FUNCTIONS=0
 CAIRO_HAS_WGL_FUNCTIONS=0
diff --git a/build/Makefile.win32.features-h b/build/Makefile.win32.features-h
index 62c8f8849..f4ebfb98a 100644
--- a/build/Makefile.win32.features-h
+++ b/build/Makefile.win32.features-h
@@ -50,9 +50,6 @@ endif
 ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1)
 	@echo "#define CAIRO_HAS_DIRECTFB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
 endif
-ifeq ($(CAIRO_HAS_VG_SURFACE),1)
-	@echo "#define CAIRO_HAS_VG_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
-endif
 ifeq ($(CAIRO_HAS_EGL_FUNCTIONS),1)
 	@echo "#define CAIRO_HAS_EGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h
 endif
diff --git a/build/configure.ac.features b/build/configure.ac.features
index 14debb849..14573143a 100644
--- a/build/configure.ac.features
+++ b/build/configure.ac.features
@@ -378,7 +378,6 @@ AC_DEFUN([CAIRO_REPORT],
 	echo "  OpenGL:        $use_gl"
 	echo "  OpenGL ES 2.0: $use_glesv2"
 	echo "  OpenGL ES 3.0: $use_glesv3"
-	echo "  OpenVG:        $use_vg"
 	echo ""
 	echo "The following font backends:"
 	echo "  User:          yes (always builtin)"
diff --git a/configure.ac b/configure.ac
index 845f07b24..209df4fb8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -332,17 +332,6 @@ CAIRO_ENABLE_SURFACE_BACKEND(glesv3, OpenGLESv3, no, [
 
 dnl ===========================================================================
 
-CAIRO_ENABLE_SURFACE_BACKEND(vg, OpenVG, no, [
-  dnl There is no pkgconfig for OpenVG; lets do a header check
-  AC_CHECK_HEADER(VG/openvg.h,, [use_vg="no (OpenVG headers not found)"])
-  if test "x$use_vg" = "xyes"; then
-      vg_NONPKGCONFIG_CFLAGS=
-      vg_NONPKGCONFIG_LIBS="-lOpenVG"
-      need_egl_functions=yes
-      need_glx_functions=yes
-  fi
-])
-
 CAIRO_ENABLE_FUNCTIONS(egl, EGL, auto, [
   if test "x$need_egl_functions" = "xyes"; then
       egl_REQUIRES="egl"
diff --git a/meson.build b/meson.build
index ab2f96f99..75a7bdfa7 100644
--- a/meson.build
+++ b/meson.build
@@ -576,22 +576,6 @@ if feature_conf.get('CAIRO_HAS_GL_SURFACE', 0) == 0 and feature_conf.get('CAIRO_
   endif
 endif
 
-# Untested
-openvg_dep = cc.find_library('OpenVG', has_headers: 'VG/openvg.h', required: get_option('openvg'))
-if openvg_dep.found()
-  deps += [openvg_dep]
-
-  need_egl_functions = true
-  need_glx_functions = true
-
-  feature_conf.set('CAIRO_HAS_VG_SURFACE', 1)
-  built_features += [{
-    'name': 'cairo-vg',
-    'description': 'OpenVG surface backend',
-    'deps': [openvg_dep],
-  }]
-endif
-
 if need_egl_functions
   # FIXME: automagic
   egl_extra_deps = []
@@ -950,7 +934,6 @@ summary({
         'OpenGL': feature_conf.get('CAIRO_HAS_GL_SURFACE', 0) == 1,
         'OpenGL ES 2.0': feature_conf.get('CAIRO_HAS_GLESV2_SURFACE', 0) == 1,
         'OpenGL ES 3.0': feature_conf.get('CAIRO_HAS_GLESV3_SURFACE', 0) == 1,
-        'OpenVG': feature_conf.get('CAIRO_HAS_VG_SURFACE', 0) == 1,
         }, section: 'Surface Backends', bool_yn: true)
 
 summary({
diff --git a/meson_options.txt b/meson_options.txt
index cd0707e6e..ebc65c77e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -8,7 +8,6 @@ option('gl-backend', type : 'combo', value : 'disabled',
        choices : ['auto', 'gl', 'glesv2', 'glesv3', 'disabled'])
 option('glesv2', type : 'feature', value : 'disabled')
 option('glesv3', type : 'feature', value : 'disabled')
-option('openvg', type : 'feature', value : 'disabled')
 option('png', type : 'feature', value : 'auto') # png and svg surfaces
 option('quartz', type : 'feature', value : 'auto')
 option('tee', type : 'feature', value : 'disabled')
diff --git a/src/Makefile.sources b/src/Makefile.sources
index 9e9b64eec..9328fca97 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -403,6 +403,3 @@ cairo_tee_sources = cairo-tee-surface.c
 
 cairo_xml_headers = cairo-xml.h
 cairo_xml_sources = cairo-xml-surface.c
-
-cairo_vg_headers = cairo-vg.h
-cairo_vg_sources = cairo-vg-surface.c
diff --git a/src/Makefile.win32.features b/src/Makefile.win32.features
index cbf259f9e..fbc774d4f 100644
--- a/src/Makefile.win32.features
+++ b/src/Makefile.win32.features
@@ -215,20 +215,6 @@ ifeq ($(CAIRO_HAS_GLESV3_SURFACE),1)
 enabled_cairo_pkgconf += cairo-glesv3.pc
 endif
 
-unsupported_cairo_headers += $(cairo_vg_headers)
-all_cairo_headers += $(cairo_vg_headers)
-all_cairo_private += $(cairo_vg_private)
-all_cairo_sources += $(cairo_vg_sources)
-ifeq ($(CAIRO_HAS_VG_SURFACE),1)
-enabled_cairo_headers += $(cairo_vg_headers)
-enabled_cairo_private += $(cairo_vg_private)
-enabled_cairo_sources += $(cairo_vg_sources)
-endif
-all_cairo_pkgconf += cairo-vg.pc
-ifeq ($(CAIRO_HAS_VG_SURFACE),1)
-enabled_cairo_pkgconf += cairo-vg.pc
-endif
-
 supported_cairo_headers += $(cairo_egl_headers)
 all_cairo_headers += $(cairo_egl_headers)
 all_cairo_private += $(cairo_egl_private)
diff --git a/src/cairo-vg-surface.c b/src/cairo-vg-surface.c
deleted file mode 100644
index 6e1f11e2d..000000000
--- a/src/cairo-vg-surface.c
+++ /dev/null
@@ -1,1854 +0,0 @@
-/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2008 Opened Hand Ltd.
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.og/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * Contributor(s):
- *      Pierre Tardy      <tardyp at gmail.com>
- *      Øyvind Kolås      <pippin at gimp.org>
- *      Vladimi Vukicevic <vladimir at mozilla.com> (stubbed out base backend)
- *      Chris Wilson      <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-
-#include "cairo-vg.h"
-
-#include "cairo-cache-private.h"
-#include "cairo-default-context-private.h"
-#include "cairo-error-private.h"
-#include "cairo-image-surface-private.h"
-#include "cairo-path-fixed-private.h"
-#include "cairo-recording-surface-inline.h"
-#include "cairo-surface-clipper-private.h"
-
-#include <pixman.h>
-#include <VG/openvg.h>
-
-//#define OPENVG_DEBUG
-
-/*
- * Work that needs to be done:
- *  - Glyph cache / proper font support
- *
- *  - First-class paths
- *    Paths are expensive for OpenVG, reuse paths whenever possible.
- *    So add a path cache, and first class paths!
- */
-
-typedef struct _cairo_vg_surface cairo_vg_surface_t;
-
-/* XXX need GL specific context control. :( */
-struct _cairo_vg_context {
-    cairo_status_t status;
-    cairo_reference_count_t ref_count;
-
-    uintptr_t           target_id;
-
-    VGPaint		paint;
-    cairo_vg_surface_t *source;
-    double		alpha;
-
-    cairo_cache_t snapshot_cache;
-
-    void *display;
-    void *context;
-
-    cairo_status_t (*create_target) (cairo_vg_context_t *,
-				     cairo_vg_surface_t *);
-    cairo_status_t (*set_target) (cairo_vg_context_t *,
-				  cairo_vg_surface_t *);
-    void (*destroy_target) (cairo_vg_context_t *, cairo_vg_surface_t *);
-};
-
-struct _cairo_vg_surface {
-    cairo_surface_t base;
-
-    cairo_vg_context_t *context;
-
-    VGImage	    image;
-    VGImageFormat   format;
-    int             width;
-    int             height;
-    cairo_bool_t    own_image;
-
-    cairo_cache_entry_t snapshot_cache_entry;
-
-    cairo_surface_clipper_t clipper;
-
-    uintptr_t target_id;
-};
-
-static const cairo_surface_backend_t cairo_vg_surface_backend;
-
-slim_hidden_proto (cairo_vg_surface_create);
-
-static cairo_surface_t *
-_vg_surface_create_internal (cairo_vg_context_t *context,
-			     VGImage image,
-			     VGImageFormat format,
-			     int width, int height);
-
-static cairo_vg_context_t *
-_vg_context_reference (cairo_vg_context_t *context)
-{
-    assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&context->ref_count));
-
-    _cairo_reference_count_inc (&context->ref_count);
-
-    return context;
-}
-
-static cairo_vg_context_t *
-_vg_context_lock (cairo_vg_context_t *context)
-{
-    /* XXX if we need to add locking, then it has to be recursive */
-    return context;
-}
-
-static cairo_int_status_t
-_vg_context_set_target (cairo_vg_context_t *context,
-			cairo_vg_surface_t *surface)
-{
-    cairo_status_t status;
-
-    if (surface->target_id == 0) {
-	status = context->create_target (context, surface);
-	if (unlikely (status))
-	    return status;
-    }
-
-    if (context->target_id == surface->target_id)
-	return CAIRO_STATUS_SUCCESS;
-
-    context->target_id = surface->target_id;
-
-    return context->set_target (context, surface);
-}
-
-static void
-_vg_context_destroy_target (cairo_vg_context_t *context,
-			    cairo_vg_surface_t *surface)
-{
-    if (surface->target_id == 0)
-	return;
-
-    if (context->target_id == surface->target_id)
-	context->set_target (context, NULL);
-
-    context->destroy_target (context, surface);
-}
-
-static cairo_bool_t
-_vg_snapshot_cache_can_remove (const void *entry)
-{
-    return TRUE;
-}
-
-static void
-_vg_snapshot_cache_remove (void *cache_entry)
-{
-    cairo_vg_surface_t *surface = cairo_container_of (cache_entry,
-						      cairo_vg_surface_t,
-						      snapshot_cache_entry);
-    surface->snapshot_cache_entry.hash = 0;
-    cairo_surface_destroy (&surface->base);
-}
-
-static cairo_status_t
-_vg_context_init (cairo_vg_context_t *context)
-{
-    cairo_status_t status;
-
-    context->status = CAIRO_STATUS_SUCCESS;
-    CAIRO_REFERENCE_COUNT_INIT (&context->ref_count, 1);
-
-    status = _cairo_cache_init (&context->snapshot_cache,
-				NULL,
-				_vg_snapshot_cache_can_remove,
-				_vg_snapshot_cache_remove,
-				16*1024*1024);
-    if (unlikely (status))
-	return status;
-
-    context->target_id = 0;
-    context->source = NULL;
-    context->alpha = 1.0;
-
-    context->paint = vgCreatePaint ();
-    vgLoadIdentity ();
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-_vg_context_destroy (cairo_vg_context_t *context)
-{
-    assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&context->ref_count));
-
-    if (! _cairo_reference_count_dec_and_test (&context->ref_count))
-	return;
-
-    if (context->paint != VG_INVALID_HANDLE)
-	vgDestroyPaint (context->paint);
-
-    _cairo_cache_fini (&context->snapshot_cache);
-    free (context);
-}
-
-static void
-_vg_context_unlock (cairo_vg_context_t *context)
-{
-}
-
-#ifdef OPENVG_DEBUG
-static void check_vg_errors(const char*function,int line)
-{
-    int err = vgGetError();
-    if (err != VG_NO_ERROR){
-	printf("%s+%d:vgError detected: 0x%08x.\n",function, line,err);
-	assert(err == VG_NO_ERROR);
-    }
-
-}
-#define CHECK_VG_ERRORS() check_vg_errors(__FILE__,__LINE__)
-#else
-#define CHECK_VG_ERRORS() do{}while(0)
-#endif //OPENVG_DEBUG
-
-static pixman_format_code_t
-_vg_format_to_pixman (VGImageFormat format,
-		      cairo_bool_t *needs_premult_fixup)
-{
-    *needs_premult_fixup = FALSE;
-    switch (format) {
-	/* RGB{A,X} channel ordering */
-    case VG_sRGBX_8888: return PIXMAN_r8g8b8x8;
-    case VG_sRGBA_8888: *needs_premult_fixup = TRUE; return PIXMAN_r8g8b8a8;
-    case VG_sRGBA_8888_PRE: return PIXMAN_r8g8b8a8;
-    case VG_sRGB_565: return PIXMAN_r5g6b5;
-    case VG_sRGBA_5551: return 0;
-    case VG_sRGBA_4444: return 0;
-    case VG_sL_8: return PIXMAN_g8;
-    case VG_lRGBX_8888: return 0;
-    case VG_lRGBA_8888: return 0;
-    case VG_lRGBA_8888_PRE: return 0;
-    case VG_lL_8: return 0;
-    case VG_A_8: return PIXMAN_a8;
-    case VG_BW_1: return PIXMAN_a1;
-    case VG_A_1: return PIXMAN_a1;
-    case VG_A_4: return PIXMAN_a4;
-
-	/* {A,X}RGB channel ordering */
-    case VG_sXRGB_8888: return PIXMAN_x8r8g8b8;
-    case VG_sARGB_8888: *needs_premult_fixup = TRUE; return PIXMAN_a8r8g8b8;
-    case VG_sARGB_8888_PRE: return PIXMAN_a8r8g8b8;
-    case VG_sARGB_1555: return 0;
-    case VG_sARGB_4444: return 0;
-    case VG_lXRGB_8888: return 0;
-    case VG_lARGB_8888: return 0;
-    case VG_lARGB_8888_PRE: return 0;
-
-	/* BGR{A,X} channel ordering */
-    case VG_sBGRX_8888: return PIXMAN_b8g8r8x8;
-    case VG_sBGRA_8888: *needs_premult_fixup = TRUE; return PIXMAN_b8g8r8a8;
-    case VG_sBGRA_8888_PRE: return PIXMAN_b8g8r8a8;
-    case VG_sBGR_565: return PIXMAN_b5g6r5;
-    case VG_sBGRA_5551: return 0;
-    case VG_sBGRA_4444: return 0;
-    case VG_lBGRX_8888: return 0;
-    case VG_lBGRA_8888: return 0;
-    case VG_lBGRA_8888_PRE: return 0;
-
-	/* {A,X}BGR channel ordering */
-    case VG_sXBGR_8888: return PIXMAN_x8b8g8r8;
-    case VG_sABGR_8888: *needs_premult_fixup = TRUE; return PIXMAN_a8b8g8r8;
-    case VG_sABGR_8888_PRE: return PIXMAN_a8b8g8r8;
-    case VG_sABGR_1555: return 0;
-    case VG_sABGR_4444: return 0;
-    case VG_lXBGR_8888: return 0;
-    case VG_lABGR_8888: return 0;
-    case VG_lABGR_8888_PRE: return 0;
-    default: return 0;
-    }
-}
-
-static pixman_format_code_t
-_vg_format_to_content (VGImageFormat format)
-{
-    /* XXX could use more simple bit tests */
-    switch (format) {
-	/* RGB{A,X} channel ordering */
-    case VG_sRGBX_8888: return CAIRO_CONTENT_COLOR;
-    case VG_sRGBA_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sRGBA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sRGB_565: return CAIRO_CONTENT_COLOR;
-    case VG_sRGBA_5551: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sRGBA_4444: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sL_8: return CAIRO_CONTENT_ALPHA;
-    case VG_lRGBX_8888: return CAIRO_CONTENT_COLOR;
-    case VG_lRGBA_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lRGBA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lL_8: return CAIRO_CONTENT_ALPHA;
-    case VG_A_8: return CAIRO_CONTENT_ALPHA;
-    case VG_A_4: return CAIRO_CONTENT_ALPHA;
-    case VG_A_1: return CAIRO_CONTENT_ALPHA;
-    case VG_BW_1: return CAIRO_CONTENT_ALPHA;
-
-	/* {A,X}RGB channel ordering */
-    case VG_sXRGB_8888: return CAIRO_CONTENT_COLOR;
-    case VG_sARGB_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sARGB_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sARGB_1555: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sARGB_4444: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lXRGB_8888: return CAIRO_CONTENT_COLOR;
-    case VG_lARGB_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lARGB_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-
-	/* BGR{A,X} channel ordering */
-    case VG_sBGRX_8888: return CAIRO_CONTENT_COLOR;
-    case VG_sBGRA_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sBGRA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sBGR_565: return CAIRO_CONTENT_COLOR;
-    case VG_sBGRA_5551: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sBGRA_4444: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lBGRX_8888: return CAIRO_CONTENT_COLOR;
-    case VG_lBGRA_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lBGRA_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-
-	/* {A,X}BGR channel ordering */
-    case VG_sXBGR_8888: return CAIRO_CONTENT_COLOR;
-    case VG_sABGR_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sABGR_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sABGR_1555: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_sABGR_4444: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lXBGR_8888: return CAIRO_CONTENT_COLOR;
-    case VG_lABGR_8888: return CAIRO_CONTENT_COLOR_ALPHA;
-    case VG_lABGR_8888_PRE: return CAIRO_CONTENT_COLOR_ALPHA;
-    default: return 0;
-    }
-}
-
-static VGImageFormat
-_vg_format_from_pixman (pixman_format_code_t format)
-{
-    /* XXX _PRE needs fixup */
-    switch ((int) format) {
-    case PIXMAN_r5g6b5: return VG_sRGB_565;
-    case PIXMAN_g8: return VG_sL_8;
-    case PIXMAN_a8: return VG_A_8;
-    case PIXMAN_a1: return VG_BW_1;
-    case PIXMAN_x8r8g8b8: return VG_sXRGB_8888;
-    case PIXMAN_a8r8g8b8: return VG_sARGB_8888; // _PRE
-    case PIXMAN_b8g8r8x8: return VG_sBGRX_8888;
-    case PIXMAN_b8g8r8a8: return VG_sBGRA_8888; // _PRE
-    case PIXMAN_b5g6r5: return VG_sBGR_565;
-    case PIXMAN_x8b8g8r8: return VG_sXBGR_8888;
-    case PIXMAN_a8b8g8r8: return VG_sABGR_8888; // _PRE
-    default: return 0;
-    }
-}
-
-static VGImageFormat
-_vg_format_for_content (cairo_content_t content)
-{
-    switch (content) {
-    case CAIRO_CONTENT_ALPHA: return VG_A_8;
-    case CAIRO_CONTENT_COLOR: return VG_sXRGB_8888;
-    default: ASSERT_NOT_REACHED;
-    case CAIRO_CONTENT_COLOR_ALPHA: return VG_sARGB_8888; // _PRE
-    }
-}
-
-static cairo_surface_t *
-_vg_surface_create_similar (void            *abstract_surface,
-			    cairo_content_t  content,
-			    int              width,
-			    int              height)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-
-    if (width > vgGeti (VG_MAX_IMAGE_WIDTH) ||
-	height > vgGeti (VG_MAX_IMAGE_HEIGHT))
-    {
-	return NULL;
-    }
-
-    return cairo_vg_surface_create (surface->context, content, width, height);
-}
-
-static cairo_status_t
-_vg_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper,
-					 cairo_path_fixed_t *path,
-					 cairo_fill_rule_t   fill_rule,
-					 double              tolerance,
-					 cairo_antialias_t   antialias)
-{
-    cairo_vg_surface_t *surface = cairo_container_of (clipper,
-						      cairo_vg_surface_t,
-						      clipper);
-    cairo_vg_surface_t *mask;
-    cairo_status_t status;
-
-    if (path == NULL) {
-	vgMask (VG_INVALID_HANDLE,
-		VG_FILL_MASK, 0, 0, surface->width, surface->height);
-	vgSeti (VG_MASKING, VG_FALSE);
-	CHECK_VG_ERRORS();
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    mask = (cairo_vg_surface_t *)
-	_vg_surface_create_similar (surface, CAIRO_CONTENT_ALPHA,
-				    surface->width, surface->height);
-    if (unlikely (mask == NULL))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    if (unlikely (mask->base.status))
-	return mask->base.status;
-
-    status = _cairo_surface_fill (&mask->base,
-				  CAIRO_OPERATOR_SOURCE,
-				  &_cairo_pattern_white.base,
-				  path, fill_rule, tolerance, antialias,
-				  NULL);
-    if (status) {
-	cairo_surface_destroy (&mask->base);
-	return status;
-    }
-
-    vgSeti (VG_MASKING, VG_TRUE);
-    vgMask (mask->image, VG_INTERSECT_MASK, 0, 0, mask->width, mask->height);
-
-    cairo_surface_destroy (&mask->base);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_bool_t
-_vg_surface_get_extents (void                  *abstract_surface,
-			 cairo_rectangle_int_t *extents)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-
-    extents->x = 0;
-    extents->y = 0;
-    extents->width  = surface->width;
-    extents->height = surface->height;
-
-    return TRUE;
-}
-
-#define MAX_SEG  16  /* max number of knots to upload in a batch */
-
-typedef struct _vg_path {
-    VGPath path;
-    const cairo_matrix_t *ctm_inverse;
-
-    VGubyte gseg[MAX_SEG];
-    VGfloat gdata[MAX_SEG*3*2];
-    int dcount;
-    int scount;
-} vg_path_t;
-
-static cairo_status_t
-_vg_move_to (void          *closure,
-	     const cairo_point_t *point)
-{
-    vg_path_t *path = closure;
-    double x = _cairo_fixed_to_double (point->x);
-    double y = _cairo_fixed_to_double (point->y);
-
-    if (path->ctm_inverse)
-	cairo_matrix_transform_point (path->ctm_inverse, &x, &y);
-
-    path->gseg[path->scount++] = VG_MOVE_TO;
-    path->gdata[path->dcount++] = x;
-    path->gdata[path->dcount++] = y;
-
-    if (path->scount >= MAX_SEG-1) {
-	vgAppendPathData (path->path, path->scount, path->gseg, path->gdata);
-	path->scount = 0;
-	path->dcount = 0;
-    }
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_vg_line_to (void          *closure,
-	     const cairo_point_t *point)
-{
-    vg_path_t *path = closure;
-    double x = _cairo_fixed_to_double (point->x);
-    double y = _cairo_fixed_to_double (point->y);
-
-    if (path->ctm_inverse)
-	cairo_matrix_transform_point (path->ctm_inverse, &x, &y);
-
-    path->gseg[path->scount++] = VG_LINE_TO;
-    path->gdata[path->dcount++] = x;
-    path->gdata[path->dcount++] = y;
-
-    if (path->scount >= MAX_SEG-1) {
-	vgAppendPathData (path->path, path->scount, path->gseg, path->gdata);
-	path->scount = 0;
-	path->dcount = 0;
-    }
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_vg_curve_to (void          *closure,
-	      const cairo_point_t *p0,
-	      const cairo_point_t *p1,
-	      const cairo_point_t *p2)
-{
-    vg_path_t *path = closure;
-    double x0 = _cairo_fixed_to_double (p0->x);
-    double y0 = _cairo_fixed_to_double (p0->y);
-    double x1 = _cairo_fixed_to_double (p1->x);
-    double y1 = _cairo_fixed_to_double (p1->y);
-    double x2 = _cairo_fixed_to_double (p2->x);
-    double y2 = _cairo_fixed_to_double (p2->y);
-
-    if (path->ctm_inverse) {
-	cairo_matrix_transform_point (path->ctm_inverse, &x0, &y0);
-	cairo_matrix_transform_point (path->ctm_inverse, &x1, &y1);
-	cairo_matrix_transform_point (path->ctm_inverse, &x2, &y2);
-    }
-
-    path->gseg[path->scount++] = VG_CUBIC_TO;
-    path->gdata[path->dcount++] = x0;
-    path->gdata[path->dcount++] = y0;
-    path->gdata[path->dcount++] = x1;
-    path->gdata[path->dcount++] = y1;
-    path->gdata[path->dcount++] = x2;
-    path->gdata[path->dcount++] = y2;
-
-    if (path->scount >= MAX_SEG-1) {
-	vgAppendPathData(path->path, path->scount, path->gseg, path->gdata);
-	path->scount = 0;
-	path->dcount = 0;
-    }
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_vg_close_path (void *closure)
-{
-    vg_path_t *path = closure;
-
-    path->gseg[path->scount++] = VG_CLOSE_PATH;
-
-    if (path->scount >= MAX_SEG-1) {
-	vgAppendPathData (path->path, path->scount, path->gseg, path->gdata);
-	path->scount = 0;
-	path->dcount = 0;
-    }
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-_vg_path_from_cairo (vg_path_t    *vg_path,
-		     const cairo_path_fixed_t *path)
-{
-    cairo_status_t status;
-
-    vg_path->scount = 0;
-    vg_path->dcount = 0;
-
-    status = _cairo_path_fixed_interpret (path,
-					  _vg_move_to,
-					  _vg_line_to,
-					  _vg_curve_to,
-					  _vg_close_path,
-					  vg_path);
-    assert (status == CAIRO_STATUS_SUCCESS);
-
-    vgAppendPathData (vg_path->path,
-		      vg_path->scount, vg_path->gseg, vg_path->gdata);
-    CHECK_VG_ERRORS();
-}
-
-static cairo_bool_t
-_vg_is_supported_operator (cairo_operator_t op)
-{
-    switch ((int) op) {
-    case CAIRO_OPERATOR_SOURCE:
-    case CAIRO_OPERATOR_OVER:
-    case CAIRO_OPERATOR_IN:
-    case CAIRO_OPERATOR_DEST_OVER:
-    case CAIRO_OPERATOR_DEST_IN:
-    case CAIRO_OPERATOR_ADD:
-	return TRUE;
-
-    default:
-	return FALSE;
-    }
-}
-
-static VGBlendMode
-_vg_operator (cairo_operator_t op)
-{
-    switch ((int) op) {
-    case CAIRO_OPERATOR_SOURCE:
-	return VG_BLEND_SRC;
-    case CAIRO_OPERATOR_OVER:
-	return VG_BLEND_SRC_OVER;
-    case CAIRO_OPERATOR_IN:
-	return VG_BLEND_SRC_IN;
-    case CAIRO_OPERATOR_DEST_OVER:
-	return VG_BLEND_DST_OVER;
-    case CAIRO_OPERATOR_DEST_IN:
-	return VG_BLEND_DST_IN;
-    case CAIRO_OPERATOR_ADD:
-	return VG_BLEND_ADDITIVE;
-    default:
-	ASSERT_NOT_REACHED;
-	return VG_BLEND_SRC_OVER;
-    }
-}
-
-static VGFillRule
-_vg_fill_rule_from_cairo (cairo_fill_rule_t rule)
-{
-    switch (rule) {
-    case CAIRO_FILL_RULE_EVEN_ODD: return VG_EVEN_ODD;
-    case CAIRO_FILL_RULE_WINDING: return VG_NON_ZERO;
-    }
-
-    ASSERT_NOT_REACHED;
-    return VG_NON_ZERO;
-}
-
-static VGRenderingQuality
-_vg_rendering_quality_from_cairo (cairo_antialias_t aa)
-{
-    switch (aa) {
-    case CAIRO_ANTIALIAS_DEFAULT:
-    case CAIRO_ANTIALIAS_SUBPIXEL:
-    case CAIRO_ANTIALIAS_GOOD:
-    case CAIRO_ANTIALIAS_BEST:
-	return VG_RENDERING_QUALITY_BETTER;
-
-    case CAIRO_ANTIALIAS_GRAY:
-    case CAIRO_ANTIALIAS_FAST:
-	return VG_RENDERING_QUALITY_FASTER;
-
-    case CAIRO_ANTIALIAS_NONE:
-	return VG_RENDERING_QUALITY_NONANTIALIASED;
-    }
-
-    ASSERT_NOT_REACHED;
-    return VG_RENDERING_QUALITY_BETTER;
-}
-
-static VGCapStyle
-_vg_line_cap_from_cairo (cairo_line_cap_t cap)
-{
-    switch (cap) {
-    case CAIRO_LINE_CAP_BUTT:   return VG_CAP_BUTT;
-    case CAIRO_LINE_CAP_ROUND:  return VG_CAP_ROUND;
-    case CAIRO_LINE_CAP_SQUARE: return VG_CAP_SQUARE;
-    }
-
-    ASSERT_NOT_REACHED;
-    return VG_CAP_BUTT;
-}
-
-static VGJoinStyle
-_vg_line_join_from_cairo (cairo_line_join_t join)
-{
-    switch (join) {
-    case CAIRO_LINE_JOIN_MITER: return VG_JOIN_MITER;
-    case CAIRO_LINE_JOIN_ROUND: return VG_JOIN_ROUND;
-    case CAIRO_LINE_JOIN_BEVEL: return VG_JOIN_BEVEL;
-    }
-
-    ASSERT_NOT_REACHED;
-    return VG_JOIN_MITER;
-}
-
-static void
-_vg_matrix_from_cairo (VGfloat *dst, const cairo_matrix_t *src)
-{
-    dst[0] = /* sx  */ src->xx;
-    dst[1] = /* shy */ src->yx;
-    dst[2] = /* w0  */ 0;
-    dst[3] = /* shx */ src->xy;
-    dst[4] = /* sy  */ src->yy;
-    dst[5] = /* w1  */ 0;
-    dst[6] = /* tx  */ src->x0;
-    dst[7] = /* ty  */ src->y0;
-    dst[8] = /* w2  */ 0;
-}
-
-static cairo_status_t
-_vg_setup_gradient_stops (cairo_vg_context_t *context,
-			  const cairo_gradient_pattern_t *pattern)
-{
-    VGint numstops = pattern->n_stops;
-    VGfloat *stops, stack_stops[CAIRO_STACK_ARRAY_LENGTH (VGfloat)];
-    int i;
-
-    if (numstops*5 < ARRAY_LENGTH (stack_stops)) {
-	stops = stack_stops;
-    } else {
-	stops = _cairo_malloc_ab (numstops, 5*sizeof (VGfloat));
-	if (unlikely (stops == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
-
-    for (i = 0; i < numstops; i++) {
-	stops[i*5 + 0] = pattern->stops[i].offset;
-	stops[i*5 + 1] = pattern->stops[i].color.red;
-	stops[i*5 + 2] = pattern->stops[i].color.green;
-	stops[i*5 + 3] = pattern->stops[i].color.blue;
-	stops[i*5 + 4] = pattern->stops[i].color.alpha * context->alpha;
-    }
-
-    vgSetParameterfv (context->paint,
-		      VG_PAINT_COLOR_RAMP_STOPS, numstops * 5, stops);
-
-    if (stops != stack_stops)
-	free (stops);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-_vg_set_source_matrix (const cairo_pattern_t *pat)
-{
-    cairo_matrix_t mat;
-    cairo_status_t status;
-    VGfloat vmat[9];
-
-    mat = pat->matrix;
-    status = cairo_matrix_invert (&mat);
-    assert (status == CAIRO_STATUS_SUCCESS);
-
-    _vg_matrix_from_cairo (vmat, &mat);
-
-    vgSeti (VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER);
-    vgLoadMatrix (vmat);
-    vgSeti (VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER);
-    vgLoadMatrix (vmat);
-    vgSeti (VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
-
-    CHECK_VG_ERRORS();
-}
-
-static cairo_status_t
-_vg_setup_linear_source (cairo_vg_context_t *context,
-			 const cairo_linear_pattern_t *lpat)
-{
-    VGfloat linear[4];
-
-    linear[0] = lpat->pd1.x;
-    linear[1] = lpat->pd1.y;
-    linear[2] = lpat->pd2.x;
-    linear[3] = lpat->pd2.y;
-
-    vgSetParameteri (context->paint,
-		     VG_PAINT_COLOR_RAMP_SPREAD_MODE,
-		     VG_COLOR_RAMP_SPREAD_PAD);
-    vgSetParameteri (context->paint,
-		     VG_PAINT_TYPE,
-		     VG_PAINT_TYPE_LINEAR_GRADIENT);
-    vgSetParameterfv (context->paint,
-		      VG_PAINT_LINEAR_GRADIENT, 4, linear);
-
-    _vg_set_source_matrix (&lpat->base.base);
-
-    CHECK_VG_ERRORS();
-    return _vg_setup_gradient_stops (context, &lpat->base);
-
-}
-
-static cairo_status_t
-_vg_setup_radial_source (cairo_vg_context_t *context,
-			 const cairo_radial_pattern_t *rpat)
-{
-    VGfloat radial[5];
-
-    radial[0] = rpat->cd1.center.x;
-    radial[1] = rpat->cd1.center.y;
-    radial[2] = rpat->cd2.center.x;
-    radial[3] = rpat->cd2.center.y;
-    radial[4] = rpat->cd2.radius;
-
-    vgSetParameteri (context->paint,
-		     VG_PAINT_COLOR_RAMP_SPREAD_MODE, VG_COLOR_RAMP_SPREAD_PAD);
-    vgSetParameteri (context->paint,
-		     VG_PAINT_TYPE, VG_PAINT_TYPE_RADIAL_GRADIENT);
-    vgSetParameterfv (context->paint,
-		      VG_PAINT_RADIAL_GRADIENT, 5, radial);
-
-    _vg_set_source_matrix (&rpat->base.base);
-
-    /* FIXME: copy/adapt fixes from SVG backend to add inner radius */
-
-    CHECK_VG_ERRORS();
-    return _vg_setup_gradient_stops (context, &rpat->base);
-}
-
-static cairo_status_t
-_vg_setup_solid_source (cairo_vg_context_t *context,
-			const cairo_solid_pattern_t *spat)
-{
-    VGfloat color[] = {
-	spat->color.red,
-	spat->color.green,
-	spat->color.blue,
-	spat->color.alpha * context->alpha
-    };
-
-    vgSetParameteri (context->paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
-    vgSetParameterfv (context->paint, VG_PAINT_COLOR, 4, color);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_vg_surface_t *
-_vg_clone_recording_surface (cairo_vg_context_t *context,
-			cairo_surface_t *surface)
-{
-    VGImage vg_image;
-    VGImageFormat format;
-    cairo_status_t status;
-    cairo_rectangle_int_t extents;
-    cairo_vg_surface_t *clone;
-
-    status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
-	return NULL;
-
-    if (extents.width > vgGeti (VG_MAX_IMAGE_WIDTH) ||
-	extents.height > vgGeti (VG_MAX_IMAGE_HEIGHT))
-    {
-	return NULL;
-    }
-
-    format = _vg_format_for_content (surface->content);
-
-    /* NONALIASED, FASTER, BETTER */
-    vg_image = vgCreateImage (format,
-			      extents.width, extents.height,
-			      VG_IMAGE_QUALITY_FASTER);
-    clone = (cairo_vg_surface_t *)
-	_vg_surface_create_internal (context, vg_image, format,
-				     extents.width, extents.height);
-    cairo_surface_set_device_offset (&clone->base, -extents.x, -extents.y);
-
-    status = _cairo_recording_surface_replay (surface, &clone->base);
-    if (unlikely (status)) {
-	cairo_surface_destroy (&clone->base);
-	return (cairo_vg_surface_t *) _cairo_surface_create_in_error (status);
-    }
-
-    return clone;
-}
-
-static cairo_vg_surface_t *
-_vg_clone_image_surface (cairo_vg_context_t *context,
-			 cairo_surface_t *surface)
-{
-    cairo_image_surface_t *image;
-    void *image_extra;
-    cairo_status_t status;
-    VGImage vg_image;
-    VGImageFormat format;
-    cairo_rectangle_int_t extents;
-    cairo_vg_surface_t *clone;
-
-    if (surface->backend->acquire_source_image == NULL)
-	return NULL;
-
-    status = _cairo_surface_get_extents (surface, &extents);
-    if (status)
-	return NULL;
-
-    if (extents.width > vgGeti (VG_MAX_IMAGE_WIDTH) ||
-	extents.height > vgGeti (VG_MAX_IMAGE_HEIGHT))
-    {
-	return NULL;
-    }
-
-    status = _cairo_surface_acquire_source_image (surface,
-						  &image, &image_extra);
-    if (unlikely (status))
-	return (cairo_vg_surface_t *) _cairo_surface_create_in_error (status);
-
-    format = _vg_format_from_pixman (image->pixman_format);
-    if (format == 0)
-	format = _vg_format_for_content (image->base.content);
-
-    /* NONALIASED, FASTER, BETTER */
-    vg_image = vgCreateImage (format,
-			      image->width, image->height,
-			      VG_IMAGE_QUALITY_FASTER);
-    clone = (cairo_vg_surface_t *)
-	_vg_surface_create_internal (context, vg_image, format,
-				    image->width, image->height);
-    if (unlikely (clone->base.status))
-	return clone;
-
-    vgImageSubData (clone->image,
-		    image->data, image->stride,
-		    format, 0, 0, image->width, image->height);
-
-    _cairo_surface_release_source_image (surface, image, image_extra);
-
-    return clone;
-}
-
-static void
-_vg_surface_remove_from_cache (cairo_surface_t *abstract_surface)
-{
-    cairo_vg_surface_t *surface = (cairo_vg_surface_t *) abstract_surface;
-
-    if (surface->snapshot_cache_entry.hash) {
-	cairo_vg_context_t *context;
-
-	context = _vg_context_lock (surface->context);
-	_cairo_cache_remove (&context->snapshot_cache,
-			     &surface->snapshot_cache_entry);
-	_vg_context_unlock (context);
-
-	surface->snapshot_cache_entry.hash = 0;
-    }
-}
-
-static cairo_status_t
-_vg_setup_surface_source (cairo_vg_context_t *context,
-			  const cairo_surface_pattern_t *spat)
-{
-    cairo_surface_t *snapshot;
-    cairo_vg_surface_t *clone;
-    cairo_status_t status;
-
-    snapshot = _cairo_surface_has_snapshot (spat->surface,
-					    &cairo_vg_surface_backend);
-    if (snapshot != NULL) {
-	clone = (cairo_vg_surface_t *) cairo_surface_reference (snapshot);
-	goto DONE;
-    }
-
-    if (_cairo_surface_is_recording (spat->surface))
-	clone = _vg_clone_recording_surface (context, spat->surface);
-    else
-	clone = _vg_clone_image_surface (context, spat->surface);
-    if (clone == NULL)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    if (unlikely (clone->base.status))
-	return clone->base.status;
-
-    clone->snapshot_cache_entry.hash = clone->base.unique_id;
-    status = _cairo_cache_insert (&context->snapshot_cache,
-				  &clone->snapshot_cache_entry);
-    if (unlikely (status)) {
-	clone->snapshot_cache_entry.hash = 0;
-	cairo_surface_destroy (&clone->base);
-	return status;
-    }
-
-    _cairo_surface_attach_snapshot (spat->surface, &clone->base,
-				    _vg_surface_remove_from_cache);
-
-DONE:
-    cairo_surface_destroy (&context->source->base);
-    context->source = clone;
-
-    vgSetParameteri (context->paint, VG_PAINT_TYPE, VG_PAINT_TYPE_PATTERN);
-
-    switch (spat->base.extend) {
-    case CAIRO_EXTEND_PAD:
-	vgSetParameteri (context->paint,
-			 VG_PAINT_PATTERN_TILING_MODE,
-			 VG_TILE_PAD);
-	break;
-
-    case CAIRO_EXTEND_NONE:
-	vgSetParameteri (context->paint,
-			 VG_PAINT_PATTERN_TILING_MODE,
-			 VG_TILE_FILL);
-	{
-	    VGfloat color[] = {0,0,0,0};
-	    vgSetfv (VG_TILE_FILL_COLOR, 4, color);
-	}
-	break;
-
-    case CAIRO_EXTEND_REPEAT:
-	vgSetParameteri (context->paint,
-			 VG_PAINT_PATTERN_TILING_MODE,
-			 VG_TILE_REPEAT);
-	break;
-
-    default:
-	ASSERT_NOT_REACHED;
-    case CAIRO_EXTEND_REFLECT:
-	vgSetParameteri (context->paint,
-			 VG_PAINT_PATTERN_TILING_MODE,
-			 VG_TILE_REFLECT);
-	break;
-    }
-    vgPaintPattern (context->paint, context->source->image);
-
-    _vg_set_source_matrix (&spat->base);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-setup_source (cairo_vg_context_t *context,
-	      const cairo_pattern_t *source)
-{
-    switch (source->type) {
-    case CAIRO_PATTERN_TYPE_SOLID:
-	return _vg_setup_solid_source (context,
-				       (cairo_solid_pattern_t *) source);
-    case CAIRO_PATTERN_TYPE_LINEAR:
-	return _vg_setup_linear_source (context,
-					(cairo_linear_pattern_t *) source);
-    case CAIRO_PATTERN_TYPE_RADIAL:
-	return _vg_setup_radial_source (context,
-					(cairo_radial_pattern_t *) source);
-    case CAIRO_PATTERN_TYPE_SURFACE:
-	return _vg_setup_surface_source (context,
-					 (cairo_surface_pattern_t *) source);
-    default:
-	ASSERT_NOT_REACHED;
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-}
-
-static cairo_int_status_t
-_vg_surface_stroke (void                       *abstract_surface,
-		    cairo_operator_t            op,
-		    const cairo_pattern_t      *source,
-		    const cairo_path_fixed_t   *path,
-		    const cairo_stroke_style_t *style,
-		    const cairo_matrix_t       *ctm,
-		    const cairo_matrix_t       *ctm_inverse,
-		    double                      tolerance,
-		    cairo_antialias_t           antialias,
-		    const cairo_clip_t         *clip)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-    cairo_vg_context_t *context;
-    cairo_status_t status;
-    VGfloat state[9];
-    VGfloat strokeTransform[9];
-    vg_path_t vg_path;
-
-    if (! _vg_is_supported_operator (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    context = _vg_context_lock (surface->context);
-    status = _vg_context_set_target (context, surface);
-    if (status) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    status = setup_source (context, source);
-    if (status) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    status = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
-    if (unlikely (status)) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    vg_path.path = vgCreatePath (VG_PATH_FORMAT_STANDARD,
-				 VG_PATH_DATATYPE_F,
-				 1, 0, 0, 0,
-				 VG_PATH_CAPABILITY_ALL);
-
-    vgGetMatrix (state);
-    _vg_matrix_from_cairo (strokeTransform, ctm);
-    vgMultMatrix (strokeTransform);
-
-    vg_path.ctm_inverse = ctm_inverse;
-
-    _vg_path_from_cairo (&vg_path, path);
-
-    /* XXX DASH_PATTERN, DASH_PHASE */
-    vgSetf (VG_STROKE_LINE_WIDTH, style->line_width);
-    vgSetf (VG_STROKE_MITER_LIMIT, style->miter_limit);
-    vgSetf (VG_STROKE_JOIN_STYLE, _vg_line_join_from_cairo (style->line_join));
-    vgSetf (VG_STROKE_CAP_STYLE, _vg_line_cap_from_cairo (style->line_cap));
-
-    vgSeti (VG_BLEND_MODE, _vg_operator (op));
-
-    vgSetPaint (context->paint, VG_STROKE_PATH);
-
-    vgDrawPath (vg_path.path, VG_STROKE_PATH);
-
-    vgDestroyPath (vg_path.path);
-
-    vgLoadMatrix (state);
-
-    CHECK_VG_ERRORS();
-    _vg_context_unlock (context);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_int_status_t
-_vg_surface_fill (void                     *abstract_surface,
-		  cairo_operator_t          op,
-		  const cairo_pattern_t    *source,
-		  const cairo_path_fixed_t *path,
-		  cairo_fill_rule_t         fill_rule,
-		  double                    tolerance,
-		  cairo_antialias_t         antialias,
-		  const cairo_clip_t       *clip)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-    cairo_vg_context_t *context;
-    cairo_status_t status;
-    vg_path_t vg_path;
-
-    if (op == CAIRO_OPERATOR_DEST)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (! _vg_is_supported_operator (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    context = _vg_context_lock (surface->context);
-    status = _vg_context_set_target (context, surface);
-    if (status) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    status = setup_source (context, source);
-    if (status) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    status = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
-    if (unlikely (status)) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    vg_path.path = vgCreatePath (VG_PATH_FORMAT_STANDARD,
-				 VG_PATH_DATATYPE_F,
-				 1, 0,
-				 0, 0,
-				 VG_PATH_CAPABILITY_ALL);
-    vg_path.ctm_inverse = NULL;
-
-    _vg_path_from_cairo (&vg_path, path);
-
-    /* XXX tolerance */
-
-    vgSeti (VG_BLEND_MODE, _vg_operator (op));
-    vgSetf (VG_FILL_RULE, _vg_fill_rule_from_cairo (fill_rule));
-    vgSetf (VG_RENDERING_QUALITY, _vg_rendering_quality_from_cairo (antialias));
-
-    vgSetPaint (context->paint, VG_FILL_PATH);
-
-    vgDrawPath (vg_path.path, VG_FILL_PATH);
-
-    vgDestroyPath (vg_path.path);
-
-    _vg_context_unlock (context);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_int_status_t
-_vg_surface_paint (void                  *abstract_surface,
-		   cairo_operator_t       op,
-		   const cairo_pattern_t *source,
-		   const cairo_clip_t    *clip)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-    cairo_vg_context_t *context;
-    cairo_status_t status;
-
-    if (op == CAIRO_OPERATOR_DEST)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (! _vg_is_supported_operator (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    context = _vg_context_lock (surface->context);
-    status = _vg_context_set_target (context, surface);
-    if (status) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    status = setup_source (context, source);
-    if (status) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    status = _cairo_surface_clipper_set_clip (&surface->clipper, clip);
-    if (unlikely (status)) {
-	_vg_context_unlock (context);
-	return status;
-    }
-
-    vgSeti (VG_BLEND_MODE, _vg_operator (op));
-    vgSetPaint (context->paint, VG_FILL_PATH);
-
-    { /* creating a rectangular path that should cover the extent */
-	VGubyte segs[] = {
-	    VG_MOVE_TO_ABS, VG_LINE_TO_ABS,
-	    VG_LINE_TO_ABS, VG_LINE_TO_ABS,
-	    VG_CLOSE_PATH
-	};
-	VGfloat data[] = {
-	    0, 0,
-	    surface->width, 0,
-	    surface->width, surface->height,
-	    0, surface->height
-	};
-	VGPath fullext;
-
-	fullext = vgCreatePath (VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
-				1,0,0,0, VG_PATH_CAPABILITY_ALL);
-	vgAppendPathData (fullext, sizeof(segs), segs, data);
-
-	vgDrawPath (fullext, VG_FILL_PATH);
-
-	vgDestroyPath (fullext);
-    }
-
-    _vg_context_unlock (context);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_int_status_t
-_vg_surface_mask (void                   *abstract_surface,
-		  cairo_operator_t        op,
-		  const cairo_pattern_t  *source,
-		  const cairo_pattern_t  *mask,
-		  const cairo_clip_t     *clip)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-    cairo_status_t status;
-
-    if (! _vg_is_supported_operator (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    /* Handle paint-with-alpha to do fades cheaply */
-    if (mask->type == CAIRO_PATTERN_TYPE_SOLID) {
-	cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) mask;
-	cairo_vg_context_t *context = _vg_context_lock (surface->context);
-	double alpha = context->alpha;
-
-	context->alpha = solid->color.alpha;
-	status = _vg_surface_paint (abstract_surface, op, source, clip);
-	context->alpha = alpha;
-
-	_vg_context_unlock (context);
-
-	return status;
-    }
-
-    return CAIRO_INT_STATUS_UNSUPPORTED;
-}
-
-static void
-_vg_surface_get_font_options (void                  *abstract_surface,
-			      cairo_font_options_t  *options)
-{
-    _cairo_font_options_init_default (options);
-
-    cairo_font_options_set_hint_metrics (options, CAIRO_HINT_METRICS_ON);
-    _cairo_font_options_set_round_glyph_positions (options, CAIRO_ROUND_GLYPH_POS_OFF);
-}
-
-static cairo_int_status_t
-_vg_surface_show_glyphs (void			*abstract_surface,
-			 cairo_operator_t	 op,
-			 const cairo_pattern_t	*source,
-			 cairo_glyph_t		*glyphs,
-			 int			 num_glyphs,
-			 cairo_scaled_font_t	*scaled_font,
-			 const cairo_clip_t     *clip)
-{
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
-    cairo_path_fixed_t path;
-
-    if (num_glyphs <= 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    _cairo_path_fixed_init (&path);
-
-    /* XXX Glyph cache! OpenVG font support in 1.1? */
-
-    status = _cairo_scaled_font_glyph_path (scaled_font,
-					    glyphs, num_glyphs,
-					    &path);
-    if (unlikely (status))
-	goto BAIL;
-
-    status = _vg_surface_fill (abstract_surface,
-			       op, source, &path,
-			       CAIRO_FILL_RULE_WINDING,
-			       CAIRO_GSTATE_TOLERANCE_DEFAULT,
-			       CAIRO_ANTIALIAS_DEFAULT,
-			       clip);
-BAIL:
-    _cairo_path_fixed_fini (&path);
-    return status;
-}
-
-static inline int
-multiply_alpha (int alpha, int color)
-{
-    int temp = alpha * color + 0x80;
-    return (temp + (temp >> 8)) >> 8;
-}
-
-static void
-premultiply_argb (uint8_t   *data,
-		  int	     width,
-		  int	     height,
-		  int	     stride)
-{
-    int i;
-
-    while (height --) {
-	uint32_t *row = (uint32_t *) data;
-
-	for (i = 0; i < width; i++) {
-	    uint32_t p = row[i];
-	    uint8_t  alpha;
-
-	    alpha = p >> 24;
-	    if (alpha == 0) {
-		 row[i] = 0;
-	    } else if (alpha != 0xff) {
-		uint8_t r = multiply_alpha (alpha, (p >> 16) & 0xff);
-		uint8_t g = multiply_alpha (alpha, (p >>  8) & 0xff);
-		uint8_t b = multiply_alpha (alpha, (p >>  0) & 0xff);
-		row[i] = ((uint32_t)alpha << 24) | (r << 16) | (g << 8) | (b << 0);
-	    }
-	}
-
-	data += stride;
-    }
-}
-
-static cairo_int_status_t
-_vg_get_image (cairo_vg_surface_t *surface,
-	       int x, int y,
-	       int width, int height,
-	       cairo_image_surface_t **image_out)
-{
-    cairo_image_surface_t *image;
-    pixman_image_t *pixman_image;
-    pixman_format_code_t pixman_format;
-    cairo_bool_t needs_premultiply;
-
-    pixman_format = _vg_format_to_pixman (surface->format,
-					  &needs_premultiply);
-    if (pixman_format == 0)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    pixman_image = pixman_image_create_bits (pixman_format,
-					     width, height,
-					     NULL, 0);
-    if (unlikely (pixman_image == NULL))
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-    vgFinish ();
-    CHECK_VG_ERRORS();
-
-    vgGetImageSubData (surface->image,
-		       pixman_image_get_data (pixman_image),
-		       pixman_image_get_stride (pixman_image),
-		       surface->format,
-		       x, y, width, height);
-
-    image = (cairo_image_surface_t *)
-	_cairo_image_surface_create_for_pixman_image (pixman_image,
-						      pixman_format);
-    if (unlikely (image->base.status)) {
-	pixman_image_unref (pixman_image);
-	return image->base.status;
-    }
-
-    if (needs_premultiply)
-	premultiply_argb (image->data, width, height, image->stride);
-
-    *image_out = image;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_vg_surface_acquire_source_image (void *abstract_surface,
-				  cairo_image_surface_t **image_out,
-				  void                  **image_extra)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-
-    CHECK_VG_ERRORS();
-    *image_extra = NULL;
-    return _vg_get_image (surface,
-			  0, 0, surface->width, surface->height,
-			  image_out);
-}
-
-static void
-_vg_surface_release_source_image (void                    *abstract_surface,
-				  cairo_image_surface_t   *image,
-				  void                    *image_extra)
-{
-    cairo_surface_destroy (&image->base);
-}
-
-static cairo_status_t
-_vg_surface_finish (void *abstract_surface)
-{
-    cairo_vg_surface_t *surface = abstract_surface;
-    cairo_vg_context_t *context = _vg_context_lock (surface->context);
-
-    if (surface->snapshot_cache_entry.hash) {
-	_cairo_cache_remove (&context->snapshot_cache,
-			     &surface->snapshot_cache_entry);
-
-	surface->snapshot_cache_entry.hash = 0;
-    }
-
-    _cairo_surface_clipper_reset (&surface->clipper);
-
-    if (surface->own_image)
-	vgDestroyImage (surface->image);
-
-    _vg_context_destroy_target (context, surface);
-
-    _vg_context_unlock (context);
-    _vg_context_destroy (context);
-
-    CHECK_VG_ERRORS();
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static const cairo_surface_backend_t cairo_vg_surface_backend = {
-    CAIRO_SURFACE_TYPE_VG,
-    _vg_surface_finish,
-
-    _cairo_default_context_create, /* XXX */
-
-    _vg_surface_create_similar,
-    NULL, /* create similar image */
-    NULL, /* map to image */
-    NULL, /* unmap image */
-
-    _cairo_surface_default_source,
-    _vg_surface_acquire_source_image,
-    _vg_surface_release_source_image,
-    NULL, /* snapshot */
-
-    NULL, /* copy_page */
-    NULL, /* show_page */
-
-    _vg_surface_get_extents,
-    _vg_surface_get_font_options, /* get_font_options */
-
-    NULL, /* flush */
-    NULL, /* mark dirty */
-
-    _vg_surface_paint,
-    _vg_surface_mask,
-    _vg_surface_stroke,
-    _vg_surface_fill,
-    NULL, /* fill-stroke */
-    _vg_surface_show_glyphs,
-};
-
-static cairo_surface_t *
-_vg_surface_create_internal (cairo_vg_context_t *context,
-			     VGImage image,
-			     VGImageFormat format,
-			     int width, int height)
-{
-    cairo_vg_surface_t *surface;
-
-    surface = _cairo_malloc (sizeof (cairo_vg_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    surface->context = _vg_context_reference (context);
-
-    surface->image  = image;
-    surface->format = format;
-
-    _cairo_surface_init (&surface->base,
-			 &cairo_vg_surface_backend,
-			 NULL, /* device */
-			 _vg_format_to_content (format),
-			 FALSE); /* is_vector */
-
-    surface->width  = width;
-    surface->height = height;
-
-    _cairo_surface_clipper_init (&surface->clipper,
-				 _vg_surface_clipper_intersect_clip_path);
-
-    surface->snapshot_cache_entry.hash = 0;
-
-    surface->target_id = 0;
-
-    CHECK_VG_ERRORS();
-    return &surface->base;
-}
-
-cairo_surface_t *
-cairo_vg_surface_create_for_image (cairo_vg_context_t *context,
-				   VGImage image,
-				   VGImageFormat format,
-				   int width, int height)
-{
-    cairo_bool_t premult;
-
-    if (context->status)
-	return _cairo_surface_create_in_error (context->status);
-
-    if (image == VG_INVALID_HANDLE)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    if (_vg_format_to_pixman (format, &premult) == 0)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-
-    return _vg_surface_create_internal (context, image, format, width, height);
-}
-
-cairo_surface_t *
-cairo_vg_surface_create (cairo_vg_context_t *context,
-			 cairo_content_t  content,
-			 int              width,
-			 int              height)
-{
-    VGImage image;
-    VGImageFormat format;
-    cairo_surface_t *surface;
-
-    if (context->status)
-	return _cairo_surface_create_in_error (context->status);
-
-    if (! CAIRO_CONTENT_VALID (content))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_CONTENT));
-
-    if (width > vgGeti (VG_MAX_IMAGE_WIDTH) ||
-	height > vgGeti (VG_MAX_IMAGE_HEIGHT))
-    {
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
-    }
-
-
-    format = _vg_format_for_content (content);
-    image = vgCreateImage (format, width, height, VG_IMAGE_QUALITY_BETTER);
-    if (image == VG_INVALID_HANDLE)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    surface = _vg_surface_create_internal (context,
-					   image, format, width, height);
-    if (unlikely (surface->status))
-	return surface;
-
-    ((cairo_vg_surface_t *) surface)->own_image = TRUE;
-    return surface;
-}
-slim_hidden_def (cairo_vg_surface_create);
-
-VGImage
-cairo_vg_surface_get_image (cairo_surface_t *abstract_surface)
-{
-    cairo_vg_surface_t *surface;
-
-    if (abstract_surface->backend != &cairo_vg_surface_backend) {
-	_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-	return VG_INVALID_HANDLE;
-    }
-
-    surface = (cairo_vg_surface_t *) abstract_surface;
-    return surface->image;
-}
-
-int
-cairo_vg_surface_get_width (cairo_surface_t *abstract_surface)
-{
-    cairo_vg_surface_t *surface;
-
-    if (abstract_surface->backend != &cairo_vg_surface_backend) {
-	_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-	return 0;
-    }
-
-    surface = (cairo_vg_surface_t *) abstract_surface;
-    return surface->width;
-}
-
-int
-cairo_vg_surface_get_height (cairo_surface_t *abstract_surface)
-{
-    cairo_vg_surface_t *surface;
-
-    if (abstract_surface->backend != &cairo_vg_surface_backend) {
-	_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-	return 0;
-    }
-
-    surface = (cairo_vg_surface_t *) abstract_surface;
-    return surface->height;
-}
-
-VGImageFormat
-cairo_vg_surface_get_format (cairo_surface_t *abstract_surface)
-{
-    cairo_vg_surface_t *surface;
-
-    if (abstract_surface->backend != &cairo_vg_surface_backend) {
-	_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-	return 0;
-    }
-
-    surface = (cairo_vg_surface_t *) abstract_surface;
-    return surface->format;
-}
-
-/* GL specific context support :-(
- *
- * OpenVG like cairo defers creation of surface (and the necessary
- * paraphernalia to the application.
- */
-
-static const cairo_vg_context_t _vg_context_nil = {
-    CAIRO_STATUS_NO_MEMORY,
-    CAIRO_REFERENCE_COUNT_INVALID
-};
-
-static const cairo_vg_context_t _vg_context_nil_invalid_visual = {
-    CAIRO_STATUS_INVALID_VISUAL,
-    CAIRO_REFERENCE_COUNT_INVALID
-};
-
-#if CAIRO_HAS_GLX_FUNCTIONS
-#include <GL/glx.h>
-
-static cairo_status_t
-glx_create_target (cairo_vg_context_t *context,
-		   cairo_vg_surface_t *surface)
-{
-    /* XXX hmm, magic required for creating an FBO points to VGImage! */
-    return CAIRO_INT_STATUS_UNSUPPORTED;
-}
-
-static cairo_status_t
-glx_set_target (cairo_vg_context_t *context,
-		cairo_vg_surface_t *surface)
-{
-#if 0
-    glXMakeContextCurrent (context->display,
-			   (GLXDrawable) surface->target_id,
-			   (GLXDrawable) surface->target_id,
-			   context->context);
-#else
-    return CAIRO_INT_STATUS_UNSUPPORTED;
-#endif
-}
-
-static void
-glx_destroy_target (cairo_vg_context_t *context,
-		    cairo_vg_surface_t *surface)
-{
-}
-
-cairo_vg_context_t *
-cairo_vg_context_create_for_glx (Display *dpy, GLXContext ctx)
-{
-    cairo_vg_context_t *context;
-    cairo_status_t status;
-
-    context = _cairo_malloc (sizeof (*context));
-    if (unlikely (context == NULL))
-	return (cairo_vg_context_t *) &_vg_context_nil;
-
-    context->display = dpy;
-    context->context = ctx;
-
-    context->create_target  = glx_create_target;
-    context->set_target     = glx_set_target;
-    context->destroy_target = glx_destroy_target;
-
-    status = _vg_context_init (context);
-    if (unlikely (status)) {
-	free (context);
-	return (cairo_vg_context_t *) &_vg_context_nil;
-    }
-
-    return context;
-}
-#endif
-
-#if CAIRO_HAS_EGL_FUNCTIONS
-static cairo_status_t
-egl_create_target (cairo_vg_context_t *context,
-		   cairo_vg_surface_t *surface)
-{
-    EGLSurface *egl_surface;
-#define RED 1
-#define GREEN 3
-#define BLUE 5
-#define ALPHA 7
-    int attribs[] = {
-	EGL_RED_SIZE, 0,
-	EGL_GREEN_SIZE, 0,
-	EGL_BLUE_SIZE, 0,
-	EGL_ALPHA_SIZE, 0,
-	EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
-	EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
-	EGL_NONE
-    };
-    pixman_format_code_t pixman_format;
-    EGLConfig config;
-    int num_configs = 0;
-    cairo_bool_t needs_premultiply;
-
-    pixman_format = _vg_format_to_pixman (surface->format, &needs_premultiply);
-    if (pixman_format == 0)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    /* XXX no control over pixel ordering! */
-    attribs[RED]   = PIXMAN_FORMAT_R (pixman_format);
-    attribs[GREEN] = PIXMAN_FORMAT_G (pixman_format);
-    attribs[BLUE]  = PIXMAN_FORMAT_B (pixman_format);
-    attribs[ALPHA] = PIXMAN_FORMAT_A (pixman_format);
-
-    if (! eglChooseConfig (context->display,
-			   attribs,
-			   &config, 1, &num_configs) ||
-	num_configs != 1)
-    {
-	fprintf(stderr, "Error: eglChooseConfig() failed.\n");
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    egl_surface =
-	eglCreatePbufferFromClientBuffer (context->display,
-					  EGL_OPENVG_IMAGE,
-					  (EGLClientBuffer) surface->image,
-					  config,
-					  NULL);
-    surface->target_id = (uintptr_t) egl_surface;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-egl_set_target (cairo_vg_context_t *context,
-		cairo_vg_surface_t *surface)
-{
-    if (! eglMakeCurrent (context->display,
-			  (EGLSurface *) surface->target_id,
-			  (EGLSurface *) surface->target_id,
-			  context->context))
-    {
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-egl_destroy_target (cairo_vg_context_t *context,
-		    cairo_vg_surface_t *surface)
-{
-    eglDestroySurface (context->display,
-		       (EGLSurface *) surface->target_id);
-}
-
-cairo_vg_context_t *
-cairo_vg_context_create_for_egl (EGLDisplay egl_display,
-				 EGLContext egl_context)
-{
-    cairo_vg_context_t *context;
-    cairo_status_t status;
-
-    context = _cairo_malloc (sizeof (*context));
-    if (unlikely (context == NULL))
-	return (cairo_vg_context_t *) &_vg_context_nil;
-
-    status = _vg_context_init (context);
-    if (unlikely (status)) {
-	free (context);
-	return (cairo_vg_context_t *) &_vg_context_nil;
-    }
-
-    context->display = egl_display;
-    context->context = egl_context;
-
-    context->create_target  = egl_create_target;
-    context->set_target     = egl_set_target;
-    context->destroy_target = egl_destroy_target;
-
-    return context;
-}
-#endif
-
-cairo_status_t
-cairo_vg_context_status (cairo_vg_context_t *context)
-{
-    return context->status;
-}
-
-void
-cairo_vg_context_destroy (cairo_vg_context_t *context)
-{
-    if (context == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID (&context->ref_count))
-	return;
-
-    _vg_context_destroy (context);
-}
diff --git a/src/cairo-vg.h b/src/cairo-vg.h
deleted file mode 100644
index a2701db3b..000000000
--- a/src/cairo-vg.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2007 * Mozilla Corporation
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Mozilla Corporation.
- *
- * Contributor(s):
- *      Vladimir Vukicevic <vladimir at mozilla.com>
- *      Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#ifndef CAIRO_VG_H
-#define CAIRO_VG_H
-
-#include "cairo.h"
-
-#if CAIRO_HAS_VG_SURFACE
-
-#include <VG/openvg.h>
-
-CAIRO_BEGIN_DECLS
-
-typedef struct _cairo_vg_context cairo_vg_context_t;
-
-#if CAIRO_HAS_GLX_FUNCTIONS
-typedef struct __GLXcontextRec *GLXContext;
-typedef struct _XDisplay Display;
-
-cairo_public cairo_vg_context_t *
-cairo_vg_context_create_for_glx (Display *dpy,
-				 GLXContext ctx);
-#endif
-
-#if CAIRO_HAS_EGL_FUNCTIONS
-#include <EGL/egl.h>
-
-cairo_public cairo_vg_context_t *
-cairo_vg_context_create_for_egl (EGLDisplay egl_display,
-				 EGLContext egl_context);
-#endif
-
-cairo_public cairo_status_t
-cairo_vg_context_status (cairo_vg_context_t *context);
-
-cairo_public void
-cairo_vg_context_destroy (cairo_vg_context_t *context);
-
-cairo_public cairo_surface_t *
-cairo_vg_surface_create (cairo_vg_context_t *context,
-			 cairo_content_t content, int width, int height);
-
-cairo_public cairo_surface_t *
-cairo_vg_surface_create_for_image (cairo_vg_context_t *context,
-				   VGImage image,
-				   VGImageFormat format,
-				   int width, int height);
-
-cairo_public VGImage
-cairo_vg_surface_get_image (cairo_surface_t *abstract_surface);
-
-cairo_public VGImageFormat
-cairo_vg_surface_get_format (cairo_surface_t *abstract_surface);
-
-cairo_public int
-cairo_vg_surface_get_height (cairo_surface_t *abstract_surface);
-
-cairo_public int
-cairo_vg_surface_get_width (cairo_surface_t *abstract_surface);
-
-CAIRO_END_DECLS
-
-#else  /* CAIRO_HAS_VG_SURFACE*/
-# error Cairo was not compiled with support for the OpenVG backend
-#endif /* CAIRO_HAS_VG_SURFACE*/
-
-#endif /* CAIRO_VG_H */
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index bb79c85b9..5fe4935ee 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -5320,85 +5320,6 @@ cairo_recording_surface_create (cairo_content_t content,
     return ret;
 }
 
-#if CAIRO_HAS_VG_SURFACE
-#include <cairo-vg.h>
-cairo_surface_t *
-cairo_vg_surface_create (cairo_vg_context_t *context,
-			 cairo_content_t content,
-			 int width, int height)
-{
-    cairo_surface_t *ret;
-
-    _enter_trace ();
-
-    ret = DLCALL (cairo_vg_surface_create, context, content, width, height);
-
-    _emit_line_info ();
-    if (_write_lock ()) {
-	Object *obj = _create_surface (ret);
-
-	_trace_printf ("dict\n"
-		       "  /type /vg set\n"
-		       "  /content //%s set\n"
-		       "  /width %d set\n"
-		       "  /height %d set\n"
-		       "  surface dup /s%ld exch def\n",
-		       _content_to_string (content),
-		       width, height,
-		       obj->token);
-	obj->width = width;
-	obj->height = height;
-	obj->defined = TRUE;
-	_push_object (obj);
-	dump_stack(__func__);
-	_write_unlock ();
-    }
-
-    _exit_trace ();
-    return ret;
-}
-
-cairo_surface_t *
-cairo_vg_surface_create_for_image (cairo_vg_context_t *context,
-				   VGImage image,
-				   VGImageFormat format,
-				   int width, int height)
-{
-    cairo_surface_t *ret;
-
-    _enter_trace ();
-
-    ret = DLCALL (cairo_vg_surface_create_for_image,
-		  context, image, format, width, height);
-
-    _emit_line_info ();
-    if (_write_lock ()) {
-	Object *obj = _create_surface (ret);
-	cairo_content_t content;
-
-	content = DLCALL (cairo_surface_get_content, ret);
-	_trace_printf ("dict\n"
-		       "  /type /vg set\n"
-		       "  /content //%s set\n"
-		       "  /width %d set\n"
-		       "  /height %d set\n"
-		       "  surface dup /s%ld exch def\n",
-		       _content_to_string (content),
-		       width, height,
-		       obj->token);
-	obj->width = width;
-	obj->height = height;
-	obj->defined = TRUE;
-	_push_object (obj);
-	dump_stack(__func__);
-	_write_unlock ();
-    }
-
-    _exit_trace ();
-    return ret;
-}
-#endif
-
 #if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE
 #include <cairo-gl.h>
 cairo_surface_t *
commit fc3437128d7b45ba34007abbbeea2a81b1b126fb
Author: Emmanuele Bassi <ebassi at gnome.org>
Date:   Sat Apr 17 23:59:28 2021 +0100

    Remove cairo-directfb
    
    Nobody cares about DirectFB any more, not even the people that registered
    and maintained the DirectFB domain.

diff --git a/README b/README
index 3cfbd98fb..40df870f2 100644
--- a/README
+++ b/README
@@ -7,7 +7,7 @@ Cairo is a 2D graphics library with support for multiple output
 devices. Currently supported output targets include the X Window
 System (via both Xlib and XCB), quartz, win32, and image buffers,
 as well as PDF, PostScript, and SVG file output. Experimental backends
-include OpenGL and DirectFB.
+include OpenGL.
 
 Cairo is designed to produce consistent output on all output media
 while taking advantage of display hardware acceleration when available
diff --git a/boilerplate/Makefile.sources b/boilerplate/Makefile.sources
index db3543116..ad96a89bc 100644
--- a/boilerplate/Makefile.sources
+++ b/boilerplate/Makefile.sources
@@ -19,7 +19,6 @@ cairo_boilerplate_private = \
 	cairo-boilerplate-private.h \
 	$(NULL)
 
-cairo_boilerplate_directfb_sources = cairo-boilerplate-directfb.c
 cairo_boilerplate_glx_sources = cairo-boilerplate-glx.c
 cairo_boilerplate_wgl_sources = cairo-boilerplate-wgl.c
 cairo_boilerplate_egl_sources = cairo-boilerplate-egl.c
diff --git a/boilerplate/Makefile.win32.features b/boilerplate/Makefile.win32.features
index d26532c5d..0dc297a28 100644
--- a/boilerplate/Makefile.win32.features
+++ b/boilerplate/Makefile.win32.features
@@ -157,16 +157,6 @@ enabled_cairo_boilerplate_private += $(cairo_boilerplate_glesv3_private)
 enabled_cairo_boilerplate_sources += $(cairo_boilerplate_glesv3_sources)
 endif
 
-unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_directfb_headers)
-all_cairo_boilerplate_headers += $(cairo_boilerplate_directfb_headers)
-all_cairo_boilerplate_private += $(cairo_boilerplate_directfb_private)
-all_cairo_boilerplate_sources += $(cairo_boilerplate_directfb_sources)
-ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1)
-enabled_cairo_boilerplate_headers += $(cairo_boilerplate_directfb_headers)
-enabled_cairo_boilerplate_private += $(cairo_boilerplate_directfb_private)
-enabled_cairo_boilerplate_sources += $(cairo_boilerplate_directfb_sources)
-endif
-
 unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_vg_headers)
 all_cairo_boilerplate_headers += $(cairo_boilerplate_vg_headers)
 all_cairo_boilerplate_private += $(cairo_boilerplate_vg_private)
diff --git a/boilerplate/cairo-boilerplate-directfb.c b/boilerplate/cairo-boilerplate-directfb.c
deleted file mode 100644
index a479011d9..000000000
--- a/boilerplate/cairo-boilerplate-directfb.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
-Test were run with the following script
-target can be directfb_bitmap or directfb
-
-export CAIRO_TEST_TARGET=directfb_bitmap
-export DFBARGS=quiet,no-banner,no-debug,log-file=dfblog,system=x11
-cd cairo/test
-make check
-
-*/
-
-#include "cairo-boilerplate-private.h"
-
-#include <cairo-directfb.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <direct/debug.h>
-
-D_DEBUG_DOMAIN (CairoDFB_Boiler, "CairoDFB/Boiler", "Cairo DirectFB Boilerplate");
-
-/* macro for a safe call to DirectFB functions */
-#define DFBCHECK(x...)	do{					\
-    err = x;							\
-    if (err != DFB_OK) {					\
-	fprintf (stderr, "%s <%d>:\n\t", __FILE__, __LINE__); \
-	goto ERROR; \
-    }								\
-} while (0)
-
-typedef struct _DFBInfo {
-    IDirectFB		   *dfb;
-    IDirectFBDisplayLayer  *layer;
-    IDirectFBWindow	   *window;
-    IDirectFBSurface	   *surface;
-} DFBInfo;
-
-static void
-_cairo_boilerplate_directfb_cleanup (void *closure)
-{
-    DFBInfo *info = (DFBInfo *) closure;
-
-    if (info->surface)
-	info->surface->Release (info->surface);
-
-    if (info->window)
-	info->window->Release (info->window);
-
-    if (info->layer)
-	info->layer->Release (info->layer);
-
-    if (info->dfb)
-	info->dfb->Release (info->dfb);
-
-    free (info);
-}
-
-static DFBInfo *
-init (void)
-{
-    DFBDisplayLayerConfig	 layer_config;
-    DFBGraphicsDeviceDescription desc;
-    int err;
-    DFBInfo *info;
-
-    info = xcalloc (1, sizeof (DFBInfo));
-    if (info == NULL)
-	return NULL;
-
-    DFBCHECK (DirectFBInit (NULL, NULL));
-    DFBCHECK (DirectFBCreate (&info->dfb));
-    info->dfb->GetDeviceDescription (info->dfb, &desc);
-
-    DFBCHECK (info->dfb->GetDisplayLayer (info->dfb,
-					  DLID_PRIMARY, &info->layer));
-    info->layer->SetCooperativeLevel (info->layer, DLSCL_ADMINISTRATIVE);
-
-    if ((desc.blitting_flags & (DSBLIT_BLEND_ALPHACHANNEL |
-				DSBLIT_BLEND_COLORALPHA)) !=
-	(DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_BLEND_COLORALPHA))
-    {
-	layer_config.flags = DLCONF_BUFFERMODE;
-	layer_config.buffermode = DLBM_BACKSYSTEM;
-	info->layer->SetConfiguration (info->layer, &layer_config);
-    }
-
-    return info;
-
-ERROR:
-    if (info != NULL)
-	_cairo_boilerplate_directfb_cleanup (info);
-    return NULL;
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_directfb_window_create_surface (DFBInfo	   *info,
-						   cairo_content_t  content,
-						   int		    width,
-						   int		    height)
-{
-    DFBWindowDescription desc;
-    int err;
-
-    D_DEBUG_AT (CairoDFB_Boiler, "%s (%p, %s, %dx%d)\n", __FUNCTION__, info,
-		content == CAIRO_CONTENT_ALPHA	     ? "ALPHA" :
-		content == CAIRO_CONTENT_COLOR	     ? "RGB"   :
-		content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB"  : "unknown content!",
-		width, height);
-
-    desc.flags	= DWDESC_POSX | DWDESC_POSY |
-		  DWDESC_WIDTH | DWDESC_HEIGHT;
-    desc.caps	= DSCAPS_NONE;
-    desc.posx	= 0;
-    desc.posy	= 0;
-    desc.width	= width;
-    desc.height = height;
-    if (content == CAIRO_CONTENT_COLOR_ALPHA) {
-	desc.flags |= DWDESC_CAPS | DWDESC_PIXELFORMAT;
-	desc.caps  |= DWCAPS_DOUBLEBUFFER | DWCAPS_ALPHACHANNEL;
-	desc.pixelformat = DSPF_ARGB;
-    }
-
-    DFBCHECK (info->layer->CreateWindow (info->layer, &desc, &info->window));
-    info->window->SetOpacity (info->window, 0xFF);
-    info->window->GetSurface (info->window, &info->surface);
-    info->surface->SetColor (info->surface, 0xFF, 0xFF, 0xFF, 0xFF);
-    info->surface->FillRectangle (info->surface,0, 0, desc.width, desc.height);
-    info->surface->Flip (info->surface, NULL, 0);
-
-    return cairo_directfb_surface_create (info->dfb, info->surface);
-
-ERROR:
-    _cairo_boilerplate_directfb_cleanup (info);
-    return NULL;
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_directfb_bitmap_create_surface (DFBInfo	   *info,
-						   cairo_content_t  content,
-						   int		    width,
-						   int		    height)
-{
-    int  err;
-    DFBSurfaceDescription  desc;
-
-    D_DEBUG_AT (CairoDFB_Boiler, "%s (%p, %s, %dx%d)\n", __FUNCTION__, info,
-		content == CAIRO_CONTENT_ALPHA	     ? "ALPHA" :
-		content == CAIRO_CONTENT_COLOR	     ? "RGB"   :
-		content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB"  : "unknown content!",
-		width, height);
-
-    desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT;
-    desc.caps = DSCAPS_NONE;
-    desc.width	= width;
-    desc.height = height;
-    if (content == CAIRO_CONTENT_COLOR_ALPHA) {
-	desc.flags |= DSDESC_PIXELFORMAT;
-	desc.pixelformat = DSPF_ARGB;
-    }
-    DFBCHECK (info->dfb->CreateSurface (info->dfb, &desc, &info->surface));
-
-    return cairo_directfb_surface_create (info->dfb, info->surface);
-
-ERROR:
-    _cairo_boilerplate_directfb_cleanup (info);
-    return NULL;
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_directfb_create_surface (const char		      *name,
-					    cairo_content_t	       content,
-					    double		       width,
-					    double		       height,
-					    double		       max_width,
-					    double		       max_height,
-					    cairo_boilerplate_mode_t   mode,
-					    void		     **closure)
-{
-
-    DFBInfo *info;
-
-    info = init ();
-    if (info == NULL)
-	return NULL;
-
-    *closure = info;
-
-    D_DEBUG_AT (CairoDFB_Boiler, "%s ('%s', %s, %dx%d, %s)\n",
-		__FUNCTION__, name,
-		content == CAIRO_CONTENT_ALPHA	     ? "ALPHA" :
-		content == CAIRO_CONTENT_COLOR	     ? "RGB"   :
-		content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB"  : "unknown content!",
-		width, height,
-		mode == CAIRO_BOILERPLATE_MODE_TEST ? "TEST" :
-		mode == CAIRO_BOILERPLATE_MODE_PERF ? "PERF" : "unknown mode!");
-
-    if (width == 0)
-	width = 1;
-    if (height == 0)
-	height = 1;
-
-    if (mode == CAIRO_BOILERPLATE_MODE_TEST)
-	return _cairo_boilerplate_directfb_bitmap_create_surface (info, content, width, height);
-    else /* mode == CAIRO_BOILERPLATE_MODE_PERF */
-	return _cairo_boilerplate_directfb_window_create_surface (info, content, width, height);
-}
-
-static const cairo_boilerplate_target_t targets[] = {
-    {
-	"directfb", "directfb", NULL, NULL,
-	CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR, 0,
-	"cairo_directfb_surface_create",
-	_cairo_boilerplate_directfb_create_surface,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_directfb_cleanup,
-	NULL, NULL, TRUE, FALSE, FALSE
-    },
-    {
-	"directfb-bitmap", "directfb", NULL, NULL,
-	CAIRO_SURFACE_TYPE_DIRECTFB, CAIRO_CONTENT_COLOR_ALPHA, 0,
-	"cairo_directfb_surface_create",
-	_cairo_boilerplate_directfb_create_surface,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_directfb_cleanup,
-	NULL, NULL, FALSE, FALSE, FALSE
-    },
-};
-CAIRO_BOILERPLATE (directfb, targets);
diff --git a/boilerplate/meson.build b/boilerplate/meson.build
index 1ff373bb5..39432fc16 100644
--- a/boilerplate/meson.build
+++ b/boilerplate/meson.build
@@ -9,7 +9,6 @@ cairo_boilerplate_feature_sources = {
   'cairo-quartz': ['cairo-boilerplate-quartz.c'],
   'cairo-xcb': ['cairo-boilerplate-xcb.c'],
   'cairo-win32': ['cairo-boilerplate-win32.c', 'cairo-boilerplate-win32-printing.c'],
-  'cairo-directfb': ['cairo-boilerplate-directfb.c'],
   'cairo-pdf': ['cairo-boilerplate-pdf.c'],
   'cairo-ps': ['cairo-boilerplate-ps.c'],
   'cairo-svg': ['cairo-boilerplate-svg.c'],
diff --git a/build/configure.ac.features b/build/configure.ac.features
index a8b37e47c..14debb849 100644
--- a/build/configure.ac.features
+++ b/build/configure.ac.features
@@ -378,7 +378,6 @@ AC_DEFUN([CAIRO_REPORT],
 	echo "  OpenGL:        $use_gl"
 	echo "  OpenGL ES 2.0: $use_glesv2"
 	echo "  OpenGL ES 3.0: $use_glesv3"
-	echo "  DirectFB:      $use_directfb"
 	echo "  OpenVG:        $use_vg"
 	echo ""
 	echo "The following font backends:"
diff --git a/configure.ac b/configure.ac
index 6235530a4..845f07b24 100644
--- a/configure.ac
+++ b/configure.ac
@@ -332,14 +332,6 @@ CAIRO_ENABLE_SURFACE_BACKEND(glesv3, OpenGLESv3, no, [
 
 dnl ===========================================================================
 
-CAIRO_ENABLE_SURFACE_BACKEND(directfb, directfb, no, [
-  directfb_REQUIRES=directfb
-  PKG_CHECK_MODULES(directfb, $directfb_REQUIRES, ,
-		    [use_directfb="no (requires $directfb_REQUIRES http://www.directfb.org)"])
-])
-
-dnl ===========================================================================
-
 CAIRO_ENABLE_SURFACE_BACKEND(vg, OpenVG, no, [
   dnl There is no pkgconfig for OpenVG; lets do a header check
   AC_CHECK_HEADER(VG/openvg.h,, [use_vg="no (OpenVG headers not found)"])
diff --git a/meson.build b/meson.build
index 3a776f6e9..ab2f96f99 100644
--- a/meson.build
+++ b/meson.build
@@ -576,19 +576,6 @@ if feature_conf.get('CAIRO_HAS_GL_SURFACE', 0) == 0 and feature_conf.get('CAIRO_
   endif
 endif
 
-# Untested
-directfb_dep = dependency('directfb', required: get_option('directfb'))
-if directfb_dep.found()
-  deps += [directfb_dep]
-
-  feature_conf.set('CAIRO_HAS_DIRECTFB_SURFACE', 1)
-  built_features += [{
-    'name': 'cairo-directfb',
-    'description': 'directfb surface backend',
-    'deps': [directfb_dep],
-  }]
-endif
-
 # Untested
 openvg_dep = cc.find_library('OpenVG', has_headers: 'VG/openvg.h', required: get_option('openvg'))
 if openvg_dep.found()
@@ -963,7 +950,6 @@ summary({
         'OpenGL': feature_conf.get('CAIRO_HAS_GL_SURFACE', 0) == 1,
         'OpenGL ES 2.0': feature_conf.get('CAIRO_HAS_GLESV2_SURFACE', 0) == 1,
         'OpenGL ES 3.0': feature_conf.get('CAIRO_HAS_GLESV3_SURFACE', 0) == 1,
-        'DirectFB': feature_conf.get('CAIRO_HAS_DIRECTFB_SURFACE', 0) == 1,
         'OpenVG': feature_conf.get('CAIRO_HAS_VG_SURFACE', 0) == 1,
         }, section: 'Surface Backends', bool_yn: true)
 
diff --git a/meson_options.txt b/meson_options.txt
index f749ff3db..cd0707e6e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,7 +3,6 @@ option('fontconfig', type : 'feature', value : 'auto')
 option('freetype', type : 'feature', value : 'auto')
 
 # Cairo surface backends
-option('directfb', type : 'feature', value : 'disabled')
 option('gl-backend', type : 'combo', value : 'disabled',
        # FIXME: https://github.com/mesonbuild/meson/issues/4566
        choices : ['auto', 'gl', 'glesv2', 'glesv3', 'disabled'])
diff --git a/src/Makefile.sources b/src/Makefile.sources
index 2c54e3a9e..9e9b64eec 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -393,9 +393,6 @@ cairo_egl_sources += cairo-egl-context.c
 cairo_glx_sources += cairo-glx-context.c
 cairo_wgl_sources += cairo-wgl-context.c
 
-cairo_directfb_headers = cairo-directfb.h
-cairo_directfb_sources = cairo-directfb-surface.c
-
 cairo_script_headers = cairo-script.h
 cairo_script_private = cairo-script-private.h
 cairo_script_sources = cairo-script-surface.c
diff --git a/src/Makefile.win32.features b/src/Makefile.win32.features
index 8592b50c8..cbf259f9e 100644
--- a/src/Makefile.win32.features
+++ b/src/Makefile.win32.features
@@ -215,20 +215,6 @@ ifeq ($(CAIRO_HAS_GLESV3_SURFACE),1)
 enabled_cairo_pkgconf += cairo-glesv3.pc
 endif
 
-unsupported_cairo_headers += $(cairo_directfb_headers)
-all_cairo_headers += $(cairo_directfb_headers)
-all_cairo_private += $(cairo_directfb_private)
-all_cairo_sources += $(cairo_directfb_sources)
-ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1)
-enabled_cairo_headers += $(cairo_directfb_headers)
-enabled_cairo_private += $(cairo_directfb_private)
-enabled_cairo_sources += $(cairo_directfb_sources)
-endif
-all_cairo_pkgconf += cairo-directfb.pc
-ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1)
-enabled_cairo_pkgconf += cairo-directfb.pc
-endif
-
 unsupported_cairo_headers += $(cairo_vg_headers)
 all_cairo_headers += $(cairo_vg_headers)
 all_cairo_private += $(cairo_vg_private)
diff --git a/src/cairo-directfb-surface.c b/src/cairo-directfb-surface.c
deleted file mode 100644
index 0deedf0d5..000000000
--- a/src/cairo-directfb-surface.c
+++ /dev/null
@@ -1,545 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2012 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Chris Wilson
- *
- * Contributor(s):
- *    Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-#include "cairo-directfb.h"
-
-#include "cairo-clip-private.h"
-#include "cairo-compositor-private.h"
-#include "cairo-default-context-private.h"
-#include "cairo-error-private.h"
-#include "cairo-image-surface-inline.h"
-#include "cairo-pattern-private.h"
-#include "cairo-surface-backend-private.h"
-#include "cairo-surface-fallback-private.h"
-
-#include <pixman.h>
-
-#include <directfb.h>
-#include <direct/types.h>
-#include <direct/debug.h>
-#include <direct/memcpy.h>
-#include <direct/util.h>
-
-slim_hidden_proto(cairo_directfb_surface_create);
-
-typedef struct _cairo_dfb_surface {
-    cairo_image_surface_t image;
-
-    IDirectFB			*dfb;
-    IDirectFBSurface		*dfb_surface;
-
-    unsigned             blit_premultiplied : 1;
-} cairo_dfb_surface_t;
-
-static cairo_content_t
-_directfb_format_to_content (DFBSurfacePixelFormat format)
-{
-    cairo_content_t content = 0;
-
-    if (DFB_PIXELFORMAT_HAS_ALPHA (format))
-	content |= CAIRO_CONTENT_ALPHA;
-    if (DFB_COLOR_BITS_PER_PIXEL (format))
-	content |= CAIRO_CONTENT_COLOR_ALPHA;
-
-    assert(content);
-    return content;
-}
-
-static inline pixman_format_code_t
-_directfb_to_pixman_format (DFBSurfacePixelFormat format)
-{
-    switch (format) {
-    case DSPF_UNKNOWN: return 0;
-    case DSPF_ARGB1555: return PIXMAN_a1r5g5b5;
-    case DSPF_RGB16: return PIXMAN_r5g6b5;
-    case DSPF_RGB24: return PIXMAN_r8g8b8;
-    case DSPF_RGB32: return PIXMAN_x8r8g8b8;
-    case DSPF_ARGB: return PIXMAN_a8r8g8b8;
-    case DSPF_A8: return PIXMAN_a8;
-    case DSPF_YUY2: return PIXMAN_yuy2;
-    case DSPF_RGB332: return PIXMAN_r3g3b2;
-    case DSPF_UYVY: return 0;
-    case DSPF_I420: return 0;
-    case DSPF_YV12: return PIXMAN_yv12;
-    case DSPF_LUT8: return 0;
-    case DSPF_ALUT44: return 0;
-    case DSPF_AiRGB: return 0;
-    case DSPF_A1: return 0; /* bit reversed, oops */
-    case DSPF_NV12: return 0;
-    case DSPF_NV16: return 0;
-    case DSPF_ARGB2554: return 0;
-    case DSPF_ARGB4444: return PIXMAN_a4r4g4b4;
-    case DSPF_NV21: return 0;
-    case DSPF_AYUV: return 0;
-    case DSPF_A4: return PIXMAN_a4;
-    case DSPF_ARGB1666: return 0;
-    case DSPF_ARGB6666: return 0;
-    case DSPF_RGB18: return 0;
-    case DSPF_LUT2: return 0;
-    case DSPF_RGB444: return PIXMAN_x4r4g4b4;
-    case DSPF_RGB555: return PIXMAN_x1r5g5b5;
-#if DFB_NUM_PIXELFORMATS >= 29
-    case DSPF_BGR555: return PIXMAN_x1b5g5r5;
-#endif
-    }
-    return 0;
-}
-
-static cairo_surface_t *
-_cairo_dfb_surface_create_similar (void            *abstract_src,
-				   cairo_content_t  content,
-				   int              width,
-				   int              height)
-{
-    cairo_dfb_surface_t *other  = abstract_src;
-    DFBSurfacePixelFormat     format;
-    IDirectFBSurface      *buffer;
-    DFBSurfaceDescription  dsc;
-    cairo_surface_t *surface;
-
-    if (width <= 0 || height <= 0)
-	return _cairo_image_surface_create_with_content (content, width, height);
-
-    switch (content) {
-    default:
-	ASSERT_NOT_REACHED;
-    case CAIRO_CONTENT_COLOR_ALPHA:
-	format = DSPF_ARGB;
-	break;
-    case CAIRO_CONTENT_COLOR:
-	format = DSPF_RGB32;
-	break;
-    case CAIRO_CONTENT_ALPHA:
-	format = DSPF_A8;
-	break;
-    }
-
-    dsc.flags       = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
-    dsc.caps        = DSCAPS_PREMULTIPLIED;
-    dsc.width       = width;
-    dsc.height      = height;
-    dsc.pixelformat = format;
-
-    if (other->dfb->CreateSurface (other->dfb, &dsc, &buffer))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_DEVICE_ERROR));
-
-    surface = cairo_directfb_surface_create (other->dfb, buffer);
-    buffer->Release (buffer);
-
-    return surface;
-}
-
-static cairo_status_t
-_cairo_dfb_surface_finish (void *abstract_surface)
-{
-    cairo_dfb_surface_t *surface = abstract_surface;
-
-    surface->dfb_surface->Release (surface->dfb_surface);
-    return _cairo_image_surface_finish (abstract_surface);
-}
-
-static cairo_image_surface_t *
-_cairo_dfb_surface_map_to_image (void *abstract_surface,
-				 const cairo_rectangle_int_t *extents)
-{
-    cairo_dfb_surface_t *surface = abstract_surface;
-
-    if (surface->image.pixman_image == NULL) {
-	IDirectFBSurface *buffer = surface->dfb_surface;
-	pixman_image_t *image;
-	void *data;
-	int pitch;
-
-	if (buffer->Lock (buffer, DSLF_READ | DSLF_WRITE, &data, &pitch))
-	    return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-	image = pixman_image_create_bits (surface->image.pixman_format,
-					  surface->image.width,
-					  surface->image.height,
-					  data, pitch);
-	if (image == NULL) {
-	    buffer->Unlock (buffer);
-	    return _cairo_image_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-	}
-	_cairo_image_surface_init (&surface->image, image, surface->image.pixman_format);
-    }
-
-    return _cairo_image_surface_map_to_image (&surface->image.base, extents);
-}
-
-static cairo_int_status_t
-_cairo_dfb_surface_unmap_image (void *abstract_surface,
-				cairo_image_surface_t *image)
-{
-    cairo_dfb_surface_t *surface = abstract_surface;
-    return _cairo_image_surface_unmap_image (&surface->image.base, image);
-}
-
-static cairo_status_t
-_cairo_dfb_surface_flush (void *abstract_surface,
-			  unsigned flags)
-{
-    cairo_dfb_surface_t *surface = abstract_surface;
-
-    if (flags)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (surface->image.pixman_image) {
-	surface->dfb_surface->Unlock (surface->dfb_surface);
-
-	pixman_image_unref (surface->image.pixman_image);
-	surface->image.pixman_image = NULL;
-	surface->image.data = NULL;
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-#if 0
-static inline DFBSurfacePixelFormat
-_directfb_from_pixman_format (pixman_format_code_t format)
-{
-    switch ((int) format) {
-    case PIXMAN_a1r5g5b5: return DSPF_ARGB1555;
-    case PIXMAN_r5g6b5: return DSPF_RGB16;
-    case PIXMAN_r8g8b8: return DSPF_RGB24;
-    case PIXMAN_x8r8g8b8: return DSPF_RGB32;
-    case PIXMAN_a8r8g8b8: return DSPF_ARGB;
-    case PIXMAN_a8: return DSPF_A8;
-    case PIXMAN_yuy2: return DSPF_YUY2;
-    case PIXMAN_r3g3b2: return DSPF_RGB332;
-    case PIXMAN_yv12: return DSPF_YV12;
-    case PIXMAN_a1: return DSPF_A1; /* bit reversed, oops */
-    case PIXMAN_a4r4g4b4: return DSPF_ARGB4444;
-    case PIXMAN_a4: return DSPF_A4;
-    case PIXMAN_x4r4g4b4: return DSPF_RGB444;
-    case PIXMAN_x1r5g5b5: return DSPF_RGB555;
-#if DFB_NUM_PIXELFORMATS >= 29
-    case PIXMAN_x1b5g5r5: return DSPF_BGR555;
-#endif
-    default: return 0;
-    }
-}
-
-static cairo_bool_t
-_directfb_get_operator (cairo_operator_t         operator,
-                        DFBSurfaceBlendFunction *ret_srcblend,
-                        DFBSurfaceBlendFunction *ret_dstblend)
-{
-    DFBSurfaceBlendFunction srcblend = DSBF_ONE;
-    DFBSurfaceBlendFunction dstblend = DSBF_ZERO;
-
-    switch (operator) {
-    case CAIRO_OPERATOR_CLEAR:
-	srcblend = DSBF_ZERO;
-	dstblend = DSBF_ZERO;
-	break;
-    case CAIRO_OPERATOR_SOURCE:
-	srcblend = DSBF_ONE;
-	dstblend = DSBF_ZERO;
-	break;
-    case CAIRO_OPERATOR_OVER:
-	srcblend = DSBF_ONE;
-	dstblend = DSBF_INVSRCALPHA;
-	break;
-    case CAIRO_OPERATOR_IN:
-	srcblend = DSBF_DESTALPHA;
-	dstblend = DSBF_ZERO;
-	break;
-    case CAIRO_OPERATOR_OUT:
-	srcblend = DSBF_INVDESTALPHA;
-	dstblend = DSBF_ZERO;
-	break;
-    case CAIRO_OPERATOR_ATOP:
-	srcblend = DSBF_DESTALPHA;
-	dstblend = DSBF_INVSRCALPHA;
-	break;
-    case CAIRO_OPERATOR_DEST:
-	srcblend = DSBF_ZERO;
-	dstblend = DSBF_ONE;
-	break;
-    case CAIRO_OPERATOR_DEST_OVER:
-	srcblend = DSBF_INVDESTALPHA;
-	dstblend = DSBF_ONE;
-	break;
-    case CAIRO_OPERATOR_DEST_IN:
-	srcblend = DSBF_ZERO;
-	dstblend = DSBF_SRCALPHA;
-	break;
-    case CAIRO_OPERATOR_DEST_OUT:
-	srcblend = DSBF_ZERO;
-	dstblend = DSBF_INVSRCALPHA;
-	break;
-    case CAIRO_OPERATOR_DEST_ATOP:
-	srcblend = DSBF_INVDESTALPHA;
-	dstblend = DSBF_SRCALPHA;
-	break;
-    case CAIRO_OPERATOR_XOR:
-	srcblend = DSBF_INVDESTALPHA;
-	dstblend = DSBF_INVSRCALPHA;
-	break;
-    case CAIRO_OPERATOR_ADD:
-	srcblend = DSBF_ONE;
-	dstblend = DSBF_ONE;
-	break;
-    case CAIRO_OPERATOR_SATURATE:
-	/* XXX This does not work. */
-#if 0
-	srcblend = DSBF_SRCALPHASAT;
-	dstblend = DSBF_ONE;
-	break;
-#endif
-    case CAIRO_OPERATOR_MULTIPLY:
-    case CAIRO_OPERATOR_SCREEN:
-    case CAIRO_OPERATOR_OVERLAY:
-    case CAIRO_OPERATOR_DARKEN:
-    case CAIRO_OPERATOR_LIGHTEN:
-    case CAIRO_OPERATOR_COLOR_DODGE:
-    case CAIRO_OPERATOR_COLOR_BURN:
-    case CAIRO_OPERATOR_HARD_LIGHT:
-    case CAIRO_OPERATOR_SOFT_LIGHT:
-    case CAIRO_OPERATOR_DIFFERENCE:
-    case CAIRO_OPERATOR_EXCLUSION:
-    case CAIRO_OPERATOR_HSL_HUE:
-    case CAIRO_OPERATOR_HSL_SATURATION:
-    case CAIRO_OPERATOR_HSL_COLOR:
-    case CAIRO_OPERATOR_HSL_LUMINOSITY:
-    default:
-	return FALSE;
-    }
-
-    *ret_srcblend = srcblend;
-    *ret_dstblend = dstblend;
-
-    return TRUE;
-}
-#define RUN_CLIPPED(surface, clip_region, clip, func) {\
-    if ((clip_region) != NULL) {\
-	int n_clips = cairo_region_num_rectangles (clip_region), n; \
-        for (n = 0; n < n_clips; n++) {\
-            if (clip) {\
-                DFBRegion  reg, *cli = (clip); \
-		cairo_rectangle_int_t rect; \
-		cairo_region_get_rectangle (clip_region, n, &rect); \
-		reg.x1 = rect.x; \
-		reg.y1 = rect.y; \
-		reg.x2 = rect.x + rect.width - 1; \
-		reg.y2 = rect.y + rect.height - 1; \
-                if (reg.x2 < cli->x1 || reg.y2 < cli->y1 ||\
-                    reg.x1 > cli->x2 || reg.y1 > cli->y2)\
-                    continue;\
-                if (reg.x1 < cli->x1)\
-                    reg.x1 = cli->x1;\
-                if (reg.y1 < cli->y1)\
-                    reg.y1 = cli->y1;\
-                if (reg.x2 > cli->x2)\
-                    reg.x2 = cli->x2;\
-                if (reg.y2 > cli->y2)\
-                    reg.y2 = cli->y2;\
-                (surface)->dfbsurface->SetClip ((surface)->dfbsurface, &reg);\
-            } else {\
-		DFBRegion reg; \
-		cairo_rectangle_int_t rect; \
-		cairo_region_get_rectangle (clip_region, n, &rect); \
-		reg.x1 = rect.x; \
-		reg.y1 = rect.y; \
-		reg.x2 = rect.x + rect.width - 1; \
-		reg.y2 = rect.y + rect.height - 1; \
-                (surface)->dfbsurface->SetClip ((surface)->dfbsurface, &reg); \
-            }\
-            func;\
-        }\
-    } else {\
-        (surface)->dfbsurface->SetClip ((surface)->dfbsurface, clip);\
-        func;\
-    }\
-}
-
-static cairo_int_status_t
-_cairo_dfb_surface_fill_rectangles (void                  *abstract_surface,
-                                         cairo_operator_t       op,
-                                         const cairo_color_t   *color,
-                                         cairo_rectangle_int_t *rects,
-                                         int                    n_rects)
-{
-    cairo_dfb_surface_t *dst   = abstract_surface;
-    DFBSurfaceDrawingFlags    flags;
-    DFBSurfaceBlendFunction   sblend;
-    DFBSurfaceBlendFunction   dblend;
-    DFBRectangle              r[n_rects];
-    int                       i;
-
-    D_DEBUG_AT (CairoDFB_Render,
-		"%s( dst=%p, op=%d, color=%p, rects=%p, n_rects=%d ).\n",
-		__FUNCTION__, dst, op, color, rects, n_rects);
-
-    if (! dst->supported_destination)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    if (! _directfb_get_operator (op, &sblend, &dblend))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    if (CAIRO_COLOR_IS_OPAQUE (color)) {
-	if (sblend == DSBF_SRCALPHA)
-	    sblend = DSBF_ONE;
-	else if (sblend == DSBF_INVSRCALPHA)
-	    sblend = DSBF_ZERO;
-
-	if (dblend == DSBF_SRCALPHA)
-	    dblend = DSBF_ONE;
-	else if (dblend == DSBF_INVSRCALPHA)
-	    dblend = DSBF_ZERO;
-    }
-    if ((dst->base.content & CAIRO_CONTENT_ALPHA) == 0) {
-	if (sblend == DSBF_DESTALPHA)
-	    sblend = DSBF_ONE;
-	else if (sblend == DSBF_INVDESTALPHA)
-	    sblend = DSBF_ZERO;
-
-	if (dblend == DSBF_DESTALPHA)
-	    dblend = DSBF_ONE;
-	else if (dblend == DSBF_INVDESTALPHA)
-	    dblend = DSBF_ZERO;
-    }
-
-    flags = (sblend == DSBF_ONE && dblend == DSBF_ZERO) ? DSDRAW_NOFX : DSDRAW_BLEND;
-    dst->dfbsurface->SetDrawingFlags (dst->dfbsurface, flags);
-    if (flags & DSDRAW_BLEND) {
-	dst->dfbsurface->SetSrcBlendFunction (dst->dfbsurface, sblend);
-	dst->dfbsurface->SetDstBlendFunction (dst->dfbsurface, dblend);
-    }
-
-    dst->dfbsurface->SetColor (dst->dfbsurface,
-			       color->red_short >> 8,
-			       color->green_short >> 8,
-			       color->blue_short >> 8,
-			       color->alpha_short >> 8);
-
-    for (i = 0; i < n_rects; i++) {
-	r[i].x = rects[i].x;
-	r[i].y = rects[i].y;
-	r[i].w = rects[i].width;
-	r[i].h = rects[i].height;
-    }
-
-    RUN_CLIPPED (dst, NULL, NULL,
-		 dst->dfbsurface->FillRectangles (dst->dfbsurface, r, n_rects));
-
-    return CAIRO_STATUS_SUCCESS;
-}
-#endif
-
-static cairo_surface_backend_t
-_cairo_dfb_surface_backend = {
-    CAIRO_SURFACE_TYPE_DIRECTFB, /*type*/
-    _cairo_dfb_surface_finish, /*finish*/
-    _cairo_default_context_create,
-
-    _cairo_dfb_surface_create_similar,/*create_similar*/
-    NULL, /* create similar image */
-    _cairo_dfb_surface_map_to_image,
-    _cairo_dfb_surface_unmap_image,
-
-    _cairo_surface_default_source,
-    _cairo_surface_default_acquire_source_image,
-    _cairo_surface_default_release_source_image,
-    NULL,
-
-    NULL, /* copy_page */
-    NULL, /* show_page */
-
-    _cairo_image_surface_get_extents,
-    _cairo_image_surface_get_font_options,
-
-    _cairo_dfb_surface_flush,
-    NULL, /* mark_dirty_rectangle */
-
-    _cairo_surface_fallback_paint,
-    _cairo_surface_fallback_mask,
-    _cairo_surface_fallback_stroke,
-    _cairo_surface_fallback_fill,
-    NULL, /* fill-stroke */
-    _cairo_surface_fallback_glyphs,
-};
-
-cairo_surface_t *
-cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *dfbsurface)
-{
-    cairo_dfb_surface_t *surface;
-    DFBSurfacePixelFormat     format;
-    DFBSurfaceCapabilities caps;
-    pixman_format_code_t pixman_format;
-    int width, height;
-
-    D_ASSERT (dfb != NULL);
-    D_ASSERT (dfbsurface != NULL);
-
-    dfbsurface->GetPixelFormat (dfbsurface, &format);
-    dfbsurface->GetSize (dfbsurface, &width, &height);
-
-    pixman_format = _directfb_to_pixman_format (format);
-    if (! pixman_format_supported_destination (pixman_format))
-        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-
-    surface = calloc (1, sizeof (cairo_dfb_surface_t));
-    if (surface == NULL)
-        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    /* XXX dfb -> device */
-    _cairo_surface_init (&surface->image.base,
-                         &_cairo_dfb_surface_backend,
-			 NULL, /* device */
-			 _directfb_format_to_content (format),
-			 FALSE); /* is_vector */
-
-    surface->image.pixman_format = pixman_format;
-    surface->image.format = _cairo_format_from_pixman_format (pixman_format);
-
-    surface->image.width = width;
-    surface->image.height = height;
-    surface->image.depth = PIXMAN_FORMAT_DEPTH(pixman_format);
-
-    surface->dfb = dfb;
-    surface->dfb_surface = dfbsurface;
-    dfbsurface->AddRef (dfbsurface);
-
-    dfbsurface->GetCapabilities (dfbsurface, &caps);
-    if (caps & DSCAPS_PREMULTIPLIED)
-	surface->blit_premultiplied = TRUE;
-
-    return &surface->image.base;
-}
-slim_hidden_def(cairo_directfb_surface_create);
diff --git a/src/cairo-directfb.h b/src/cairo-directfb.h
deleted file mode 100644
index e3d818c66..000000000
--- a/src/cairo-directfb.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2003 University of Southern California
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is University of Southern
- * California.
- *
- * Contributor(s):
- *	Carl D. Worth <cworth at isi.edu>
- */
-
-/*
- * Environment variables affecting the backend:
- *
- *  %CAIRO_DIRECTFB_NO_ACCEL (boolean)
- *      if found, disables acceleration at all
- *
- *  %CAIRO_DIRECTFB_ARGB_FONT (boolean)
- *      if found, enables using ARGB fonts instead of A8
- */
-
-#ifndef CAIRO_DIRECTFB_H
-#define CAIRO_DIRECTFB_H
-
-#include "cairo.h"
-
-#if  CAIRO_HAS_DIRECTFB_SURFACE
-
-#include <directfb.h>
-
-CAIRO_BEGIN_DECLS
-
-cairo_public cairo_surface_t *
-cairo_directfb_surface_create (IDirectFB *dfb, IDirectFBSurface *surface);
-
-CAIRO_END_DECLS
-
-#else  /*CAIRO_HAS_DIRECTFB_SURFACE*/
-# error Cairo was not compiled with support for the directfb backend
-#endif /*CAIRO_HAS_DIRECTFB_SURFACE*/
-
-#endif /*CAIRO_DIRECTFB_H*/
diff --git a/src/meson.build b/src/meson.build
index 0e2c5e80a..df8764649 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -192,12 +192,6 @@ cairo_feature_sources = {
     'cairo-gl-surface.c',
     'cairo-gl-traps-compositor.c',
   ],
-  'cairo-directfb': [
-    'cairo-directfb-surface.c',
-  ],
-  'cairo-vg': [
-    'cairo-vg-surface.c',
-  ],
   'cairo-script': [
     'cairo-script-surface.c',
   ],
@@ -240,7 +234,6 @@ cairo_feature_headers = {
   'cairo-quartz-image': ['cairo-quartz-image.h'],
   'cairo-win32': ['cairo-win32.h'],
   'cairo-gl': ['cairo-gl.h'],
-  'cairo-directfb': ['cairo-directfb.h'],
   'cairo-script': ['cairo-script.h'],
   'cairo-tee': ['cairo-tee.h'],
   'cairo-xml': ['cairo-xml.h'],
commit 803afe6edda17b97e3d12a20585e565a2d2a79a2
Author: Emmanuele Bassi <ebassi at gnome.org>
Date:   Sat Apr 17 23:56:50 2021 +0100

    tanis: Remove cairo-cogl
    
    Cogl's upstream is unmaintained, and has been for the past 6 years.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d169b397b..291898c6f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -74,7 +74,6 @@ fedora image:
       gtk2-devel
       poppler-glib-devel
       pixman-devel
-      cogl-devel
       systemd-devel
       systemd-udev
       mesa-libEGL
diff --git a/boilerplate/Makefile.sources b/boilerplate/Makefile.sources
index e219f04f7..db3543116 100644
--- a/boilerplate/Makefile.sources
+++ b/boilerplate/Makefile.sources
@@ -34,4 +34,3 @@ cairo_boilerplate_xcb_sources = cairo-boilerplate-xcb.c
 cairo_boilerplate_xlib_headers = cairo-boilerplate-xlib.h
 cairo_boilerplate_xlib_sources = cairo-boilerplate-xlib.c
 cairo_boilerplate_vg_sources = cairo-boilerplate-vg.c
-cairo_boilerplate_cogl_sources = cairo-boilerplate-cogl.c
diff --git a/boilerplate/Makefile.win32.features b/boilerplate/Makefile.win32.features
index 2325ccf5b..d26532c5d 100644
--- a/boilerplate/Makefile.win32.features
+++ b/boilerplate/Makefile.win32.features
@@ -157,16 +157,6 @@ enabled_cairo_boilerplate_private += $(cairo_boilerplate_glesv3_private)
 enabled_cairo_boilerplate_sources += $(cairo_boilerplate_glesv3_sources)
 endif
 
-unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_cogl_headers)
-all_cairo_boilerplate_headers += $(cairo_boilerplate_cogl_headers)
-all_cairo_boilerplate_private += $(cairo_boilerplate_cogl_private)
-all_cairo_boilerplate_sources += $(cairo_boilerplate_cogl_sources)
-ifeq ($(CAIRO_HAS_COGL_SURFACE),1)
-enabled_cairo_boilerplate_headers += $(cairo_boilerplate_cogl_headers)
-enabled_cairo_boilerplate_private += $(cairo_boilerplate_cogl_private)
-enabled_cairo_boilerplate_sources += $(cairo_boilerplate_cogl_sources)
-endif
-
 unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_directfb_headers)
 all_cairo_boilerplate_headers += $(cairo_boilerplate_directfb_headers)
 all_cairo_boilerplate_private += $(cairo_boilerplate_directfb_private)
diff --git a/boilerplate/cairo-boilerplate-cogl.c b/boilerplate/cairo-boilerplate-cogl.c
deleted file mode 100644
index 2339dd883..000000000
--- a/boilerplate/cairo-boilerplate-cogl.c
+++ /dev/null
@@ -1,217 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Chris Wilson.
- */
-
-#include "cairo-boilerplate-private.h"
-#include "cairo-malloc-private.h"
-
-#include <cairo-cogl.h>
-#include <cogl/cogl2-experimental.h>
-
-typedef struct _cogl_closure {
-    cairo_device_t *device;
-    cairo_surface_t *surface;
-} cogl_closure_t;
-
-static const cairo_user_data_key_t cogl_closure_key;
-
-static void
-_cairo_boilerplate_cogl_cleanup (void *abstract_closure)
-{
-    cogl_closure_t *closure = abstract_closure;
-
-    cairo_device_finish (closure->device);
-    cairo_device_destroy (closure->device);
-
-    free (closure);
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_cogl_create_offscreen_color_surface (const char		*name,
-							cairo_content_t		 content,
-							double			 width,
-							double			 height,
-							double			 max_width,
-							double			 max_height,
-							cairo_boilerplate_mode_t mode,
-							void		       **abstract_closure)
-{
-    CoglContext *context;
-    cairo_device_t *device;
-    cogl_closure_t *closure;
-    cairo_status_t status;
-
-    if (width < 1)
-        width = 1;
-    if (height < 1)
-        height = 1;
-
-    context = cogl_context_new (NULL, NULL);
-
-    device = cairo_cogl_device_create (context);
-
-    /* The device will take a reference on the context */
-    cogl_object_unref (context);
-
-    closure = _cairo_malloc (sizeof (cogl_closure_t));
-    *abstract_closure = closure;
-    closure->device = device;
-    closure->surface = cairo_cogl_offscreen_surface_create (device,
-                                                            content,
-                                                            width,
-                                                            height);
-
-    status = cairo_surface_set_user_data (closure->surface,
-					  &cogl_closure_key, closure, NULL);
-    if (status == CAIRO_STATUS_SUCCESS)
-	return closure->surface;
-
-    _cairo_boilerplate_cogl_cleanup (closure);
-    return cairo_boilerplate_surface_create_in_error (status);
-}
-
-static cairo_surface_t *
-_cairo_boilerplate_cogl_create_onscreen_color_surface (const char	       *name,
-						       cairo_content_t		content,
-						       double			width,
-						       double			height,
-						       double			max_width,
-						       double			max_height,
-						       cairo_boilerplate_mode_t mode,
-						       void		      **abstract_closure)
-{
-    CoglContext *context;
-    cairo_device_t *device;
-    cogl_closure_t *closure;
-    cairo_status_t status;
-
-    if (width < 1)
-        width = 1;
-    if (height < 1)
-        height = 1;
-
-    if (content & CAIRO_CONTENT_ALPHA) {
-	/* A hackish way to ensure that we get a framebuffer with
-	 * an alpha component */
-	CoglSwapChain *swap_chain;
-	CoglOnscreenTemplate *onscreen_template;
-	CoglRenderer *renderer;
-	CoglDisplay *display;
-
-        swap_chain = cogl_swap_chain_new ();
-        cogl_swap_chain_set_has_alpha (swap_chain, TRUE);
-
-        onscreen_template = cogl_onscreen_template_new (swap_chain);
-        renderer = cogl_renderer_new ();
-        display = cogl_display_new (renderer, onscreen_template);
-
-        /* References will be taken on the swap chain, renderer, and
-         * onscreen template by the constructors */
-        cogl_object_unref (swap_chain);
-        cogl_object_unref (renderer);
-        cogl_object_unref (onscreen_template);
-
-        context = cogl_context_new (display, NULL);
-
-        /* The context will take a reference on the display */
-        cogl_object_unref (display);
-    } else {
-        context = cogl_context_new (NULL, NULL);
-    }
-
-    device = cairo_cogl_device_create (context);
-
-    /* The device will take a reference on the context */
-    cogl_object_unref (context);
-
-    closure = _cairo_malloc (sizeof (cogl_closure_t));
-    *abstract_closure = closure;
-    closure->device = device;
-    closure->surface = cairo_cogl_onscreen_surface_create (device,
-                                                           content,
-                                                           width,
-                                                           height);
-
-    status = cairo_surface_set_user_data (closure->surface,
-					  &cogl_closure_key, closure, NULL);
-    if (status == CAIRO_STATUS_SUCCESS)
-	return closure->surface;
-
-    _cairo_boilerplate_cogl_cleanup (closure);
-    return cairo_boilerplate_surface_create_in_error (status);
-}
-
-static cairo_status_t
-_cairo_boilerplate_cogl_finish (cairo_surface_t *surface)
-{
-    return cairo_cogl_surface_end_frame (surface);
-}
-
-static void
-_cairo_boilerplate_cogl_synchronize (void *abstract_closure)
-{
-    cogl_closure_t *closure = abstract_closure;
-    cairo_cogl_surface_synchronize (closure->surface);
-}
-
-static const cairo_boilerplate_target_t targets[] = {
-    {
-	"cogl-offscreen-color", "cogl", NULL, NULL,
-	CAIRO_SURFACE_TYPE_COGL, CAIRO_CONTENT_COLOR_ALPHA, 1,
-	"cairo_cogl_device_create",
-	_cairo_boilerplate_cogl_create_offscreen_color_surface,
-	cairo_surface_create_similar,
-	NULL,
-        _cairo_boilerplate_cogl_finish,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_cogl_cleanup,
-	_cairo_boilerplate_cogl_synchronize,
-        NULL,
-	TRUE, FALSE, FALSE
-    },
-    {
-	"cogl-onscreen-color", "cogl", NULL, NULL,
-	CAIRO_SURFACE_TYPE_COGL, CAIRO_CONTENT_COLOR_ALPHA, 1,
-	"cairo_cogl_device_create",
-	_cairo_boilerplate_cogl_create_onscreen_color_surface,
-	cairo_surface_create_similar,
-	NULL,
-	_cairo_boilerplate_cogl_finish,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	_cairo_boilerplate_cogl_cleanup,
-	_cairo_boilerplate_cogl_synchronize,
-        NULL,
-	TRUE, FALSE, FALSE
-    }
-};
-CAIRO_BOILERPLATE (cogl, targets)
diff --git a/boilerplate/meson.build b/boilerplate/meson.build
index f26d3fa0b..1ff373bb5 100644
--- a/boilerplate/meson.build
+++ b/boilerplate/meson.build
@@ -9,7 +9,6 @@ cairo_boilerplate_feature_sources = {
   'cairo-quartz': ['cairo-boilerplate-quartz.c'],
   'cairo-xcb': ['cairo-boilerplate-xcb.c'],
   'cairo-win32': ['cairo-boilerplate-win32.c', 'cairo-boilerplate-win32-printing.c'],
-  'cairo-cogl': ['cairo-boilerplate-cogl.c'],
   'cairo-directfb': ['cairo-boilerplate-directfb.c'],
   'cairo-pdf': ['cairo-boilerplate-pdf.c'],
   'cairo-ps': ['cairo-boilerplate-ps.c'],
diff --git a/build/Makefile.win32.features b/build/Makefile.win32.features
index 4770571a1..c398bcba5 100644
--- a/build/Makefile.win32.features
+++ b/build/Makefile.win32.features
@@ -14,7 +14,6 @@ CAIRO_HAS_PNG_FUNCTIONS=1
 CAIRO_HAS_GL_SURFACE=0
 CAIRO_HAS_GLESV2_SURFACE=0
 CAIRO_HAS_GLESV3_SURFACE=0
-CAIRO_HAS_COGL_SURFACE=0
 CAIRO_HAS_DIRECTFB_SURFACE=0
 CAIRO_HAS_VG_SURFACE=0
 CAIRO_HAS_EGL_FUNCTIONS=0
diff --git a/build/Makefile.win32.features-h b/build/Makefile.win32.features-h
index 6b28b6faa..62c8f8849 100644
--- a/build/Makefile.win32.features-h
+++ b/build/Makefile.win32.features-h
@@ -47,9 +47,6 @@ endif
 ifeq ($(CAIRO_HAS_GLESV3_SURFACE),1)
 	@echo "#define CAIRO_HAS_GLESV3_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
 endif
-ifeq ($(CAIRO_HAS_COGL_SURFACE),1)
-	@echo "#define CAIRO_HAS_COGL_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
-endif
 ifeq ($(CAIRO_HAS_DIRECTFB_SURFACE),1)
 	@echo "#define CAIRO_HAS_DIRECTFB_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
 endif
diff --git a/build/configure.ac.features b/build/configure.ac.features
index d1fae3306..a8b37e47c 100644
--- a/build/configure.ac.features
+++ b/build/configure.ac.features
@@ -380,7 +380,6 @@ AC_DEFUN([CAIRO_REPORT],
 	echo "  OpenGL ES 3.0: $use_glesv3"
 	echo "  DirectFB:      $use_directfb"
 	echo "  OpenVG:        $use_vg"
-	echo "  Cogl:          $use_cogl"
 	echo ""
 	echo "The following font backends:"
 	echo "  User:          yes (always builtin)"
diff --git a/configure.ac b/configure.ac
index 06e421536..6235530a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -330,12 +330,6 @@ CAIRO_ENABLE_SURFACE_BACKEND(glesv3, OpenGLESv3, no, [
   need_egl_functions=yes
 ])
 
-dnl ===========================================================================
-CAIRO_ENABLE_SURFACE_BACKEND(cogl, Cogl, no, [
-  cogl_REQUIRES="cogl-2.0-experimental >= 1.17.2"
-  PKG_CHECK_MODULES(cogl, $cogl_REQUIRES,, [use_cogl="no"])
-])
-
 dnl ===========================================================================
 
 CAIRO_ENABLE_SURFACE_BACKEND(directfb, directfb, no, [
diff --git a/meson.build b/meson.build
index ad8fb19c3..3a776f6e9 100644
--- a/meson.build
+++ b/meson.build
@@ -576,21 +576,6 @@ if feature_conf.get('CAIRO_HAS_GL_SURFACE', 0) == 0 and feature_conf.get('CAIRO_
   endif
 endif
 
-cogl_dep = dependency('cogl-2.0-experimental',
-  version: '>= 1.17.2',
-  required: get_option('cogl'),
-)
-if cogl_dep.found()
-  deps += [cogl_dep]
-
-  feature_conf.set('CAIRO_HAS_COGL_SURFACE', 1)
-  built_features += [{
-    'name': 'cairo-cogl',
-    'description': 'Cogl surface backend',
-    'deps': [cogl_dep],
-  }]
-endif
-
 # Untested
 directfb_dep = dependency('directfb', required: get_option('directfb'))
 if directfb_dep.found()
@@ -980,7 +965,6 @@ summary({
         'OpenGL ES 3.0': feature_conf.get('CAIRO_HAS_GLESV3_SURFACE', 0) == 1,
         'DirectFB': feature_conf.get('CAIRO_HAS_DIRECTFB_SURFACE', 0) == 1,
         'OpenVG': feature_conf.get('CAIRO_HAS_VG_SURFACE', 0) == 1,
-        'Cogl': feature_conf.get('CAIRO_HAS_COGL_SURFACE', 0) == 1,
         }, section: 'Surface Backends', bool_yn: true)
 
 summary({
diff --git a/meson_options.txt b/meson_options.txt
index 891fb99a3..f749ff3db 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,7 +3,6 @@ option('fontconfig', type : 'feature', value : 'auto')
 option('freetype', type : 'feature', value : 'auto')
 
 # Cairo surface backends
-option('cogl', type : 'feature', value : 'disabled')
 option('directfb', type : 'feature', value : 'disabled')
 option('gl-backend', type : 'combo', value : 'disabled',
        # FIXME: https://github.com/mesonbuild/meson/issues/4566
diff --git a/src/Makefile.sources b/src/Makefile.sources
index 938abe82d..2c54e3a9e 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -409,9 +409,3 @@ cairo_xml_sources = cairo-xml-surface.c
 
 cairo_vg_headers = cairo-vg.h
 cairo_vg_sources = cairo-vg-surface.c
-
-cairo_cogl_headers = cairo-cogl.h
-cairo_cogl_private = cairo-cogl-private.h \
-		     cairo-cogl-gradient-private.h
-cairo_cogl_sources = cairo-cogl-surface.c \
-		     cairo-cogl-gradient.c
diff --git a/src/Makefile.win32.features b/src/Makefile.win32.features
index 9641ee9c6..8592b50c8 100644
--- a/src/Makefile.win32.features
+++ b/src/Makefile.win32.features
@@ -215,20 +215,6 @@ ifeq ($(CAIRO_HAS_GLESV3_SURFACE),1)
 enabled_cairo_pkgconf += cairo-glesv3.pc
 endif
 
-unsupported_cairo_headers += $(cairo_cogl_headers)
-all_cairo_headers += $(cairo_cogl_headers)
-all_cairo_private += $(cairo_cogl_private)
-all_cairo_sources += $(cairo_cogl_sources)
-ifeq ($(CAIRO_HAS_COGL_SURFACE),1)
-enabled_cairo_headers += $(cairo_cogl_headers)
-enabled_cairo_private += $(cairo_cogl_private)
-enabled_cairo_sources += $(cairo_cogl_sources)
-endif
-all_cairo_pkgconf += cairo-cogl.pc
-ifeq ($(CAIRO_HAS_COGL_SURFACE),1)
-enabled_cairo_pkgconf += cairo-cogl.pc
-endif
-
 unsupported_cairo_headers += $(cairo_directfb_headers)
 all_cairo_headers += $(cairo_directfb_headers)
 all_cairo_private += $(cairo_directfb_private)
diff --git a/src/cairo-cogl-gradient-private.h b/src/cairo-cogl-gradient-private.h
deleted file mode 100644
index 9367044f3..000000000
--- a/src/cairo-cogl-gradient-private.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.og/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * Contributor(s):
- *      Robert Bragg <robert at linux.intel.com>
- */
-
-#ifndef CAIRO_COGL_GRADIENT_PRIVATE_H
-#define CAIRO_COGL_GRADIENT_PRIVATE_H
-
-#include "cairoint.h"
-#include "cairo-pattern-private.h"
-
-#include <cogl/cogl2-experimental.h>
-
-#define CAIRO_COGL_LINEAR_GRADIENT_CACHE_SIZE (1024 * 1024)
-
-typedef enum _cairo_cogl_gradient_compatibility {
-    CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD	    = 1<<0,
-    CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT   = 1<<1,
-    CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT  = 1<<2,
-    CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE	    = 1<<3
-} cairo_cogl_gradient_compatibility_t;
-#define CAIRO_COGL_GRADIENT_CAN_EXTEND_ALL (CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD |\
-					    CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT|\
-					    CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT|\
-					    CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE)
-
-typedef struct _cairo_cogl_linear_texture_entry {
-    cairo_cogl_gradient_compatibility_t compatibility;
-    CoglTexture	*texture;
-    float translate_x;
-    float scale_x;
-} cairo_cogl_linear_texture_entry_t;
-
-typedef struct _cairo_cogl_linear_gradient {
-    cairo_cache_entry_t		 cache_entry;
-    cairo_reference_count_t	 ref_count;
-    GList			*textures;
-    int				 n_stops;
-    const cairo_gradient_stop_t	*stops;
-    cairo_gradient_stop_t	 stops_embedded[1];
-} cairo_cogl_linear_gradient_t;
-
-cairo_int_status_t
-_cairo_cogl_get_linear_gradient (cairo_cogl_device_t           *context,
-				 cairo_extend_t                 extend_mode,
-				 int                            n_stops,
-				 const cairo_gradient_stop_t   *stops,
-				 const cairo_bool_t             need_mirrored_gradient,
-				 cairo_cogl_linear_gradient_t **gradient_out);
-
-cairo_cogl_linear_texture_entry_t *
-_cairo_cogl_linear_gradient_texture_for_extend (cairo_cogl_linear_gradient_t *gradient,
-						cairo_extend_t                extend_mode);
-
-cairo_cogl_linear_gradient_t *
-_cairo_cogl_linear_gradient_reference (cairo_cogl_linear_gradient_t *gradient);
-
-void
-_cairo_cogl_linear_gradient_destroy (cairo_cogl_linear_gradient_t *gradient);
-
-cairo_bool_t
-_cairo_cogl_linear_gradient_equal (const void *key_a, const void *key_b);
-
-#endif /* CAIRO_COGL_GRADIENT_PRIVATE_H */
diff --git a/src/cairo-cogl-gradient.c b/src/cairo-cogl-gradient.c
deleted file mode 100644
index 9fb5ce740..000000000
--- a/src/cairo-cogl-gradient.c
+++ /dev/null
@@ -1,678 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.og/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * Contributor(s):
- *      Robert Bragg <robert at linux.intel.com>
- */
-//#include "cairoint.h"
-
-#include "cairo-cogl-private.h"
-#include "cairo-cogl-gradient-private.h"
-#include "cairo-image-surface-private.h"
-
-#include <cogl/cogl2-experimental.h>
-#include <glib.h>
-
-//#define DUMP_GRADIENTS_TO_PNG
-
-static uintptr_t
-_cairo_cogl_linear_gradient_hash (unsigned int                  n_stops,
-				  const cairo_gradient_stop_t  *stops)
-{
-    return _cairo_hash_bytes (n_stops, stops,
-                              sizeof (cairo_gradient_stop_t) * n_stops);
-}
-
-static cairo_cogl_linear_gradient_t *
-_cairo_cogl_linear_gradient_lookup (cairo_cogl_device_t          *ctx,
-				    uintptr_t                     hash,
-				    unsigned int                  n_stops,
-				    const cairo_gradient_stop_t  *stops)
-{
-    cairo_cogl_linear_gradient_t lookup;
-
-    lookup.cache_entry.hash = hash,
-    lookup.n_stops = n_stops;
-    lookup.stops = stops;
-
-    return _cairo_cache_lookup (&ctx->linear_cache, &lookup.cache_entry);
-}
-
-cairo_bool_t
-_cairo_cogl_linear_gradient_equal (const void *key_a, const void *key_b)
-{
-    const cairo_cogl_linear_gradient_t *a = key_a;
-    const cairo_cogl_linear_gradient_t *b = key_b;
-
-    if (a->n_stops != b->n_stops)
-        return FALSE;
-
-    return memcmp (a->stops, b->stops, a->n_stops * sizeof (cairo_gradient_stop_t)) == 0;
-}
-
-cairo_cogl_linear_gradient_t *
-_cairo_cogl_linear_gradient_reference (cairo_cogl_linear_gradient_t *gradient)
-{
-    assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count));
-
-    _cairo_reference_count_inc (&gradient->ref_count);
-
-    return gradient;
-}
-
-void
-_cairo_cogl_linear_gradient_destroy (cairo_cogl_linear_gradient_t *gradient)
-{
-    GList *l;
-
-    assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&gradient->ref_count));
-
-    if (! _cairo_reference_count_dec_and_test (&gradient->ref_count))
-	return;
-
-    for (l = gradient->textures; l; l = l->next) {
-	cairo_cogl_linear_texture_entry_t *entry = l->data;
-	cogl_object_unref (entry->texture);
-	free (entry);
-    }
-    g_list_free (gradient->textures);
-
-    free (gradient);
-}
-
-static int
-_cairo_cogl_util_next_p2 (int a)
-{
-  int rval = 1;
-
-  while (rval < a)
-    rval <<= 1;
-
-  return rval;
-}
-
-static float
-get_max_color_component_range (const cairo_color_stop_t *color0,
-                               const cairo_color_stop_t *color1)
-{
-    float range;
-    float max = 0;
-
-    range = fabs (color0->red - color1->red);
-    max = MAX (range, max);
-    range = fabs (color0->green - color1->green);
-    max = MAX (range, max);
-    range = fabs (color0->blue - color1->blue);
-    max = MAX (range, max);
-    range = fabs (color0->alpha - color1->alpha);
-    max = MAX (range, max);
-
-    return max;
-}
-
-static int
-_cairo_cogl_linear_gradient_width_for_stops (cairo_extend_t		  extend,
-					     unsigned int                 n_stops,
-					     const cairo_gradient_stop_t *stops)
-{
-    unsigned int n;
-    float max_texels_per_unit_offset = 0;
-    float total_offset_range;
-
-    /* Find the stop pair demanding the most precision because we are
-     * interpolating the largest color-component range.
-     *
-     * From that we can define the relative sizes of all the other
-     * stop pairs within our texture and thus the overall size.
-     *
-     * To determine the maximum number of texels for a given gap we
-     * look at the range of colors we are expected to interpolate (so
-     * long as the stop offsets are not degenerate) and we simply
-     * assume we want one texel for each unique color value possible
-     * for a one byte-per-component representation.
-     * XXX: maybe this is overkill and just allowing 128 levels
-     * instead of 256 would be enough and then we'd rely on the
-     * bilinear filtering to give the full range.
-     *
-     * XXX: potentially we could try and map offsets to pixels to come
-     * up with a more precise mapping, but we are aiming to cache
-     * the gradients so we can't make assumptions about how it will be
-     * scaled in the future.
-     */
-    for (n = 1; n < n_stops; n++) {
-	float color_range;
-	float offset_range;
-	float texels;
-	float texels_per_unit_offset;
-
-	/* note: degenerate stops don't need to be represented in the
-	 * texture but we want to be sure that solid gaps get at least
-	 * one texel and all other gaps get at least 2 texels.
-	 */
-
-	if (stops[n].offset == stops[n-1].offset)
-	    continue;
-
-	color_range = get_max_color_component_range (&stops[n].color, &stops[n-1].color);
-	if (color_range == 0)
-	    texels = 1;
-	else
-	    texels = MAX (2, 256.0f * color_range);
-
-	/* So how many texels would we need to map over the full [0,1]
-	 * gradient range so this gap would have enough texels? ... */
-	offset_range = stops[n].offset - stops[n - 1].offset;
-	texels_per_unit_offset = texels / offset_range;
-
-	if (texels_per_unit_offset > max_texels_per_unit_offset)
-	    max_texels_per_unit_offset = texels_per_unit_offset;
-    }
-
-    total_offset_range = fabs (stops[n_stops - 1].offset - stops[0].offset);
-    return max_texels_per_unit_offset * total_offset_range;
-}
-
-/* Aim to create gradient textures without an alpha component so we can avoid
- * needing to use blending... */
-static CoglTextureComponents
-_cairo_cogl_linear_gradient_components_for_stops (cairo_extend_t               extend,
-					          unsigned int                 n_stops,
-					          const cairo_gradient_stop_t *stops)
-{
-    unsigned int n;
-
-    /* We have to add extra transparent texels to the end of the gradient to
-     * handle CAIRO_EXTEND_NONE... */
-    if (extend == CAIRO_EXTEND_NONE)
-	return COGL_TEXTURE_COMPONENTS_RGBA;
-
-    for (n = 1; n < n_stops; n++) {
-	if (stops[n].color.alpha != 1.0)
-	    return COGL_TEXTURE_COMPONENTS_RGBA;
-    }
-
-    return COGL_TEXTURE_COMPONENTS_RGBA;
-}
-
-static cairo_cogl_gradient_compatibility_t
-_cairo_cogl_compatibility_from_extend_mode (cairo_extend_t extend_mode)
-{
-    switch (extend_mode)
-    {
-    case CAIRO_EXTEND_NONE:
-	return CAIRO_COGL_GRADIENT_CAN_EXTEND_NONE;
-    case CAIRO_EXTEND_PAD:
-	return CAIRO_COGL_GRADIENT_CAN_EXTEND_PAD;
-    case CAIRO_EXTEND_REPEAT:
-	return CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT;
-    case CAIRO_EXTEND_REFLECT:
-	return CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT;
-    }
-
-    assert (0); /* not reached */
-    return CAIRO_EXTEND_NONE;
-}
-
-cairo_cogl_linear_texture_entry_t *
-_cairo_cogl_linear_gradient_texture_for_extend (cairo_cogl_linear_gradient_t *gradient,
-						cairo_extend_t                extend_mode)
-{
-    GList *l;
-    cairo_cogl_gradient_compatibility_t compatibility =
-	_cairo_cogl_compatibility_from_extend_mode (extend_mode);
-    for (l = gradient->textures; l; l = l->next) {
-	cairo_cogl_linear_texture_entry_t *entry = l->data;
-	if (entry->compatibility & compatibility)
-	    return entry;
-    }
-    return NULL;
-}
-
-static void
-color_stop_lerp (const cairo_color_stop_t *c0,
-		 const cairo_color_stop_t *c1,
-		 float factor,
-		 cairo_color_stop_t *dest)
-{
-    /* NB: we always ignore the short members in this file so we don't need to
-     * worry about initializing them here. */
-    dest->red = c0->red * (1.0f-factor) + c1->red * factor;
-    dest->green = c0->green * (1.0f-factor) + c1->green * factor;
-    dest->blue = c0->blue * (1.0f-factor) + c1->blue * factor;
-    dest->alpha = c0->alpha * (1.0f-factor) + c1->alpha * factor;
-}
-
-static size_t
-_cairo_cogl_linear_gradient_size (cairo_cogl_linear_gradient_t *gradient)
-{
-    GList *l;
-    size_t size = 0;
-    for (l = gradient->textures; l; l = l->next) {
-	cairo_cogl_linear_texture_entry_t *entry = l->data;
-	size += cogl_texture_get_width (entry->texture) * 4;
-    }
-    return size;
-}
-
-static void
-emit_stop (CoglVertexP2C4 **position,
-	   float left,
-	   float right,
-	   const cairo_color_stop_t *left_color,
-	   const cairo_color_stop_t *right_color)
-{
-    CoglVertexP2C4 *p = *position;
-
-    guint8 lr = left_color->red * 255;
-    guint8 lg = left_color->green * 255;
-    guint8 lb = left_color->blue * 255;
-    guint8 la = left_color->alpha * 255;
-
-    guint8 rr = right_color->red * 255;
-    guint8 rg = right_color->green * 255;
-    guint8 rb = right_color->blue * 255;
-    guint8 ra = right_color->alpha * 255;
-
-    p[0].x = left;
-    p[0].y = 0;
-    p[0].r = lr; p[0].g = lg; p[0].b = lb; p[0].a = la;
-    p[1].x = left;
-    p[1].y = 1;
-    p[1].r = lr; p[1].g = lg; p[1].b = lb; p[1].a = la;
-    p[2].x = right;
-    p[2].y = 1;
-    p[2].r = rr; p[2].g = rg; p[2].b = rb; p[2].a = ra;
-
-    p[3].x = left;
-    p[3].y = 0;
-    p[3].r = lr; p[3].g = lg; p[3].b = lb; p[3].a = la;
-    p[4].x = right;
-    p[4].y = 1;
-    p[4].r = rr; p[4].g = rg; p[4].b = rb; p[4].a = ra;
-    p[5].x = right;
-    p[5].y = 0;
-    p[5].r = rr; p[5].g = rg; p[5].b = rb; p[5].a = ra;
-
-    *position = &p[6];
-}
-
-#ifdef DUMP_GRADIENTS_TO_PNG
-static void
-dump_gradient_to_png (CoglTexture *texture)
-{
-    cairo_image_surface_t *image = (cairo_image_surface_t *)
-	cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-				    cogl_texture_get_width (texture),
-				    cogl_texture_get_height (texture));
-    CoglPixelFormat format;
-    static int gradient_id = 0;
-    char *gradient_name;
-
-    if (image->base.status)
-	return;
-
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-    format = COGL_PIXEL_FORMAT_BGRA_8888_PRE;
-#else
-    format = COGL_PIXEL_FORMAT_ARGB_8888_PRE;
-#endif
-    cogl_texture_get_data (texture,
-			   format,
-			   0,
-			   image->data);
-    gradient_name = g_strdup_printf ("./gradient%d.png", gradient_id++);
-    g_print ("writing gradient: %s\n", gradient_name);
-    cairo_surface_write_to_png ((cairo_surface_t *)image, gradient_name);
-    g_free (gradient_name);
-}
-#endif
-
-cairo_int_status_t
-_cairo_cogl_get_linear_gradient (cairo_cogl_device_t           *device,
-				 cairo_extend_t                 extend_mode,
-				 int                            n_stops,
-				 const cairo_gradient_stop_t   *stops,
-				 const cairo_bool_t             need_mirrored_gradient,
-				 cairo_cogl_linear_gradient_t **gradient_out)
-{
-    uintptr_t hash;
-    cairo_cogl_linear_gradient_t *gradient;
-    cairo_cogl_linear_texture_entry_t *entry;
-    cairo_gradient_stop_t *internal_stops;
-    int stop_offset;
-    int n_internal_stops;
-    int n;
-    cairo_cogl_gradient_compatibility_t compatibilities;
-    int width;
-    int tex_width;
-    int left_padding = 0;
-    cairo_color_stop_t left_padding_color;
-    int right_padding = 0;
-    cairo_color_stop_t right_padding_color;
-    CoglTextureComponents components;
-    CoglTexture2D *tex;
-    int un_padded_width;
-    CoglFramebuffer *offscreen = NULL;
-    cairo_int_status_t status;
-    int n_quads;
-    int n_vertices;
-    float prev;
-    float right;
-    CoglVertexP2C4 *vertices;
-    CoglVertexP2C4 *p;
-    CoglPrimitive *prim;
-    CoglPipeline *pipeline;
-
-    hash = _cairo_cogl_linear_gradient_hash (n_stops, stops);
-
-    gradient = _cairo_cogl_linear_gradient_lookup (device, hash, n_stops, stops);
-    if (gradient) {
-	cairo_cogl_linear_texture_entry_t *entry =
-	    _cairo_cogl_linear_gradient_texture_for_extend (gradient, extend_mode);
-	if (entry) {
-	    *gradient_out = _cairo_cogl_linear_gradient_reference (gradient);
-	    return CAIRO_INT_STATUS_SUCCESS;
-	}
-    }
-
-    if (!gradient) {
-	gradient = _cairo_malloc (sizeof (cairo_cogl_linear_gradient_t) +
-			   sizeof (cairo_gradient_stop_t) * (n_stops - 1));
-	if (!gradient)
-	    return CAIRO_INT_STATUS_NO_MEMORY;
-
-	CAIRO_REFERENCE_COUNT_INIT (&gradient->ref_count, 1);
-	/* NB: we update the cache_entry size at the end before
-	 * [re]adding it to the cache. */
-	gradient->cache_entry.hash = hash;
-	gradient->textures = NULL;
-	gradient->n_stops = n_stops;
-	gradient->stops = gradient->stops_embedded;
-	memcpy (gradient->stops_embedded, stops, sizeof (cairo_gradient_stop_t) * n_stops);
-    } else {
-	_cairo_cogl_linear_gradient_reference (gradient);
-    }
-
-    entry = _cairo_malloc (sizeof (cairo_cogl_linear_texture_entry_t));
-    if (unlikely (!entry)) {
-	status = CAIRO_INT_STATUS_NO_MEMORY;
-	goto BAIL;
-    }
-
-    compatibilities = _cairo_cogl_compatibility_from_extend_mode (extend_mode);
-
-    n_internal_stops = n_stops;
-    stop_offset = 0;
-
-    /* We really need stops covering the full [0,1] range for repeat/reflect
-     * if we want to use sampler REPEAT/MIRROR wrap modes so we may need
-     * to add some extra stops... */
-    if (extend_mode == CAIRO_EXTEND_REPEAT || extend_mode == CAIRO_EXTEND_REFLECT)
-    {
-	/* If we don't need any extra stops then actually the texture
-	 * will be shareable for repeat and reflect... */
-	compatibilities = (CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT |
-			   CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT);
-
-	if (stops[0].offset != 0) {
-	    n_internal_stops++;
-	    stop_offset++;
-	}
-
-	if (stops[n_stops - 1].offset != 1)
-	    n_internal_stops++;
-    }
-
-    internal_stops = alloca (n_internal_stops * sizeof (cairo_gradient_stop_t));
-    memcpy (&internal_stops[stop_offset], stops, sizeof (cairo_gradient_stop_t) * n_stops);
-
-    /* cairo_color_stop_t values are all unpremultiplied but we need to
-     * interpolate premultiplied colors so we premultiply all the double
-     * components now. (skipping any extra stops added for repeat/reflect)
-     *
-     * Another thing to note is that by premultiplying the colors
-     * early we'll also reduce the range of colors to interpolate
-     * which can result in smaller gradient textures.
-     */
-    for (n = stop_offset; n < n_stops; n++) {
-	cairo_color_stop_t *color = &internal_stops[n].color;
-	color->red *= color->alpha;
-	color->green *= color->alpha;
-	color->blue *= color->alpha;
-    }
-
-    if (n_internal_stops != n_stops)
-    {
-	if (extend_mode == CAIRO_EXTEND_REPEAT) {
-	    compatibilities &= ~CAIRO_COGL_GRADIENT_CAN_EXTEND_REFLECT;
-	    if (stops[0].offset != 0) {
-		/* what's the wrap-around distance between the user's end-stops? */
-		double dx = (1.0 - stops[n_stops - 1].offset) + stops[0].offset;
-		internal_stops[0].offset = 0;
-		color_stop_lerp (&stops[0].color,
-				 &stops[n_stops - 1].color,
-				 stops[0].offset / dx,
-				 &internal_stops[0].color);
-	    }
-	    if (stops[n_stops - 1].offset != 1) {
-		internal_stops[n_internal_stops - 1].offset = 1;
-		internal_stops[n_internal_stops - 1].color = internal_stops[0].color;
-	    }
-	} else if (extend_mode == CAIRO_EXTEND_REFLECT) {
-	    compatibilities &= ~CAIRO_COGL_GRADIENT_CAN_EXTEND_REPEAT;
-	    if (stops[0].offset != 0) {
-		internal_stops[0].offset = 0;
-		internal_stops[0].color = stops[n_stops - 1].color;
-	    }
-	    if (stops[n_stops - 1].offset != 1) {
-		internal_stops[n_internal_stops - 1].offset = 1;
-		internal_stops[n_internal_stops - 1].color = stops[0].color;
-	    }
-	}
-    }
-
-    stops = internal_stops;
-    n_stops = n_internal_stops;
-
-    width = _cairo_cogl_linear_gradient_width_for_stops (extend_mode, n_stops, stops);
-
-    if (extend_mode == CAIRO_EXTEND_PAD) {
-
-	/* Here we need to guarantee that the edge texels of our
-	 * texture correspond to the desired padding color so we
-	 * can use CLAMP_TO_EDGE.
-	 *
-	 * For short stop-gaps and especially for degenerate stops
-	 * it's possible that without special consideration the
-	 * user's end stop colors would not be present in our final
-	 * texture.
-	 *
-	 * To handle this we forcibly add two extra padding texels
-	 * at the edges which extend beyond the [0,1] range of the
-	 * gradient itself and we will later report a translate and
-	 * scale transform to compensate for this.
-	 */
-
-	/* XXX: If we consider generating a mipmap for our 1d texture
-	 * at some point then we also need to consider how much
-	 * padding to add to be sure lower mipmap levels still have
-	 * the desired edge color (as opposed to a linear blend with
-	 * other colors of the gradient).
-	 */
-
-	left_padding = 1;
-	left_padding_color = stops[0].color;
-	right_padding = 1;
-	right_padding_color = stops[n_stops - 1].color;
-    } else if (extend_mode == CAIRO_EXTEND_NONE) {
-	/* We handle EXTEND_NONE by adding two extra, transparent, texels at
-	 * the ends of the texture and use CLAMP_TO_EDGE.
-	 *
-	 * We add a scale and translate transform so to account for our texels
-	 * extending beyond the [0,1] range. */
-
-	left_padding = 1;
-	left_padding_color.red = 0;
-	left_padding_color.green = 0;
-	left_padding_color.blue = 0;
-	left_padding_color.alpha = 0;
-	right_padding = 1;
-	right_padding_color = left_padding_color;
-    }
-
-    /* If we still have stops that don't cover the full [0,1] range
-     * then we need to define a texture-coordinate scale + translate
-     * transform to account for that... */
-    if (stops[n_stops - 1].offset - stops[0].offset < 1) {
-	float range = stops[n_stops - 1].offset - stops[0].offset;
-	entry->scale_x = 1.0 / range;
-	entry->translate_x = -(stops[0].offset * entry->scale_x);
-    }
-
-    width += left_padding + right_padding;
-
-    width = _cairo_cogl_util_next_p2 (width);
-    width = MIN (4096, width); /* lets not go too stupidly big! */
-
-    if (!device->has_npots)
-        width = pow (2, ceil (log2 (width)));
-
-    if (need_mirrored_gradient)
-        tex_width = width * 2;
-    else
-        tex_width = width;
-
-    components = _cairo_cogl_linear_gradient_components_for_stops (extend_mode, n_stops, stops);
-
-    do {
-	tex = cogl_texture_2d_new_with_size (device->cogl_context,
-	                                     tex_width, 1);
-    } while (tex == NULL && width >> 1 && tex_width >> 1);
-
-    if (unlikely (!tex)) {
-	status = CAIRO_INT_STATUS_NO_MEMORY;
-	goto BAIL;
-    }
-
-    cogl_texture_set_components (tex, components);
-
-    entry->texture = tex;
-    entry->compatibility = compatibilities;
-
-    un_padded_width = width - left_padding - right_padding;
-
-    /* XXX: only when we know the final texture width can we calculate the
-     * scale and translate factors needed to account for padding... */
-    if (un_padded_width != width)
-	entry->scale_x *= (float)un_padded_width / (float)width;
-    if (left_padding)
-	entry->translate_x += (entry->scale_x / (float)un_padded_width) * (float)left_padding;
-
-    offscreen = cogl_offscreen_new_with_texture (tex);
-    cogl_framebuffer_orthographic (offscreen, 0, 0,
-                                              tex_width, 1,
-                                              -1, 100);
-    cogl_framebuffer_clear4f (offscreen,
-                              COGL_BUFFER_BIT_COLOR,
-                              0, 0, 0, 0);
-
-    n_quads = n_stops - 1 + !!left_padding + !!right_padding;
-    n_vertices = 6 * n_quads;
-    vertices = _cairo_malloc_ab (n_vertices, sizeof (CoglVertexP2C4));
-    if (unlikely (!vertices)) {
-        status = CAIRO_INT_STATUS_NO_MEMORY;
-        goto BAIL;
-    }
-
-    p = vertices;
-    if (left_padding)
-	emit_stop (&p, 0, left_padding, &left_padding_color, &left_padding_color);
-    prev = (float)left_padding;
-    for (n = 1; n < n_stops; n++) {
-	right = (float)left_padding + (float)un_padded_width * stops[n].offset;
-	emit_stop (&p, prev, right, &stops[n-1].color, &stops[n].color);
-	prev = right;
-    }
-    if (right_padding)
-	emit_stop (&p, prev, width, &right_padding_color, &right_padding_color);
-
-    prim = cogl_primitive_new_p2c4 (device->cogl_context,
-                                    COGL_VERTICES_MODE_TRIANGLES,
-                                    n_vertices,
-                                    vertices);
-    free (vertices);
-    pipeline = cogl_pipeline_new (device->cogl_context);
-    cogl_primitive_draw (prim, offscreen, pipeline);
-
-    if (need_mirrored_gradient) {
-        /* In order to use a reflected gradient on hardware that
-         * doesn't have a mirrored repeating texture wrap mode, we
-         * render two reflected images to a double-length linear
-         * texture and reflect that */
-        CoglMatrix transform;
-
-        cogl_matrix_init_identity (&transform);
-        cogl_matrix_translate (&transform, tex_width, 0.0f, 0.0f);
-        cogl_matrix_scale (&transform, -1.0f, 1.0f, 1.0f);
-
-        cogl_framebuffer_transform (offscreen, &transform);
-        cogl_primitive_draw (prim, offscreen, pipeline);
-    }
-
-    cogl_object_unref (prim);
-    cogl_object_unref (pipeline);
-
-    cogl_object_unref (offscreen);
-    offscreen = NULL;
-
-    gradient->textures = g_list_prepend (gradient->textures, entry);
-    gradient->cache_entry.size = _cairo_cogl_linear_gradient_size (gradient);
-
-#ifdef DUMP_GRADIENTS_TO_PNG
-    dump_gradient_to_png (tex);
-#endif
-
-#warning "FIXME:"
-    /* XXX: it seems the documentation of _cairo_cache_insert isn't true - it
-     * doesn't handle re-adding the same entry gracefully - the cache will
-     * just keep on growing and then it will start randomly evicting things
-     * pointlessly */
-    /* we ignore errors here and just return an uncached gradient */
-    if (likely (! _cairo_cache_insert (&device->linear_cache, &gradient->cache_entry)))
-        _cairo_cogl_linear_gradient_reference (gradient);
-
-    *gradient_out = gradient;
-    return CAIRO_INT_STATUS_SUCCESS;
-
-BAIL:
-    free (entry);
-    if (gradient)
-	_cairo_cogl_linear_gradient_destroy (gradient);
-    if (offscreen)
-        cogl_object_unref (offscreen);
-    return status;
-}
diff --git a/src/cairo-cogl-private.h b/src/cairo-cogl-private.h
deleted file mode 100644
index b0be2661e..000000000
--- a/src/cairo-cogl-private.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.og/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * Contributor(s):
- *      Robert Bragg <robert at linux.intel.com>
- */
-
-#ifndef CAIRO_COGL_PRIVATE_H
-#define CAIRO_COGL_PRIVATE_H
-
-#include "cairo-device-private.h"
-#include "cairo-cache-private.h"
-#include "cairo-backend-private.h"
-#include "cairo-default-context-private.h"
-#include "cairo-surface-private.h"
-#include "cairo-freelist-private.h"
-
-#include <cogl/cogl2-experimental.h>
-
-typedef enum _cairo_cogl_template_type {
-	/* solid source */
-    CAIRO_COGL_TEMPLATE_TYPE_SOLID,
-    /* solid source with solid mask */
-    CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_SOLID,
-    /* solid source with texture mask */
-    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_SOLID,
-    /* texture source */
-    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE,
-    /* texture source with solid mask */
-    CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_TEXTURE,
-    /* texture source with texture mask */
-    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_TEXTURE,
-    /* texture source with source alpha ignored */
-    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_IGNORE_ALPHA,
-    /* texture source with solid mask with source alpha ignored */
-    CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_TEXTURE_IGNORE_ALPHA,
-    /* texture source with texture mask with source alpha ignored */
-    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_TEXTURE_IGNORE_ALPHA,
-    CAIRO_COGL_TEMPLATE_TYPE_COUNT
-} cairo_cogl_template_type;
-
-typedef struct _cairo_cogl_device {
-    cairo_device_t base;
-
-    CoglContext *cogl_context;
-
-    cairo_bool_t has_npots;
-    cairo_bool_t has_mirrored_repeat;
-
-    CoglAttributeBuffer *buffer_stack;
-    size_t buffer_stack_size;
-    size_t buffer_stack_offset;
-    guint8 *buffer_stack_pointer;
-
-    /* This is a limited set of templates because we don't support the
-     * full range of operators that cairo has. The CAIRO_OPERATOR_ADD
-     * is the operator enum with the highest value that we support so
-     * we cap the size of the array by that.
-     *
-     * For each operator, we have a template for when we have a solid
-     * source and a non-solid source. For each of those, we also have
-     * additional templates for when we have a solid mask or a
-     * non-solid mask, for a total of six templates per operator.
-     *
-     * The templates are set to null at device creation time and only
-     * actually created on their first use.
-     */
-    CoglPipeline *template_pipelines[CAIRO_OPERATOR_ADD + 1][CAIRO_COGL_TEMPLATE_TYPE_COUNT];
-
-    /* Caches 1d linear gradient textures */
-    cairo_cache_t linear_cache;
-
-    cairo_cache_t path_fill_prim_cache;
-    cairo_cache_t path_stroke_prim_cache;
-
-    cairo_freelist_t path_fill_meta_freelist;
-    cairo_freelist_t path_stroke_meta_freelist;
-} cairo_cogl_device_t;
-
-typedef struct _cairo_cogl_clip_primitives {
-    cairo_t *clip;
-    CoglPrimitive **primitives;
-} cairo_cogl_clip_primitives_t;
-
-typedef struct _cairo_cogl_surface {
-    cairo_surface_t base;
-
-    /* We currently have 3 basic kinds of Cogl surfaces:
-     * 1) A light surface simply wrapping a CoglTexture
-     * 2) A CoglOffscreen framebuffer that implicitly also wraps a CoglTexture
-     * 3) A CoglOnscreen framebuffer which could potentially be mapped to
-     *    a CoglTexture (e.g. via tfp on X11) but we don't currently do
-     *    that.
-     */
-
-    CoglTexture *texture;
-    CoglFramebuffer *framebuffer;
-
-    int width;
-    int height;
-
-    /* Is this a snapshot used for mirrored repeating on hardware which
-     * doesn't have it, consisting of four reflected images? */
-    cairo_bool_t is_mirrored_snapshot;
-
-    GQueue *journal;
-
-    cairo_clip_t *last_clip;
-
-    /* A small fifo of recently used cairo_clip_ts paired with CoglPrimitives
-     * that can be used to mask the stencil buffer. */
-    GList *clips_fifo;
-
-    int n_clip_updates_per_frame;
-
-    /* Since the surface backend drawing operator functions don't get
-     * passed the current cairo_t context we don't have a good way
-     * to get our user-coordinates path into our surface_fill function.
-     *
-     * For now we use our _cairo_cogl_context_fill() wrapper to set this
-     * side band data on the surface...
-     */
-    cairo_path_fixed_t *user_path;
-    cairo_matrix_t ctm;
-    cairo_matrix_t ctm_inverse;
-    cairo_bool_t path_is_rectangle;
-    double path_rectangle_x;
-    double path_rectangle_y;
-    double path_rectangle_width;
-    double path_rectangle_height;
-} cairo_cogl_surface_t;
-
-cairo_status_t
-_cairo_cogl_path_fixed_rectangle (cairo_path_fixed_t *path,
-				  cairo_fixed_t x,
-				  cairo_fixed_t y,
-				  cairo_fixed_t width,
-				  cairo_fixed_t height);
-
-#endif /* CAIRO_COGL_PRIVATE_H */
diff --git a/src/cairo-cogl-surface.c b/src/cairo-cogl-surface.c
deleted file mode 100644
index f4eee091c..000000000
--- a/src/cairo-cogl-surface.c
+++ /dev/null
@@ -1,4106 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.og/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * Contributor(s):
- *      Robert Bragg <robert at linux.intel.com>
- */
-#include "cairoint.h"
-
-#include "cairo-cache-private.h"
-#include "cairo-error-private.h"
-#include "cairo-path-fixed-private.h"
-#include "cairo-recording-surface-private.h"
-#include "cairo-recording-surface-inline.h"
-#include "cairo-fixed-private.h"
-#include "cairo-device-private.h"
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-image-surface-inline.h"
-#include "cairo-cogl-private.h"
-#include "cairo-cogl-gradient-private.h"
-#include "cairo-arc-private.h"
-#include "cairo-traps-private.h"
-#include "cairo-surface-subsurface-inline.h"
-#include "cairo-surface-fallback-private.h"
-#include "cairo-surface-offset-private.h"
-
-#include "cairo-cogl.h"
-
-#include <cogl/cogl2-experimental.h>
-#include <glib.h>
-
-#define CAIRO_COGL_DEBUG 0
-//#define DISABLE_BATCHING
-#define MAX_JOURNAL_SIZE 100
-
-#if CAIRO_COGL_DEBUG && __GNUC__
-#define UNSUPPORTED(reason) ({ \
-    g_warning ("cairo-cogl: hit unsupported operation: %s", reason); \
-    CAIRO_INT_STATUS_UNSUPPORTED; \
-})
-#else
-#define UNSUPPORTED(reason) CAIRO_INT_STATUS_UNSUPPORTED
-#endif
-
-#define CAIRO_COGL_PATH_META_CACHE_SIZE (1024 * 1024)
-
-typedef struct _cairo_cogl_texture_attributes {
-    /* nabbed from cairo_surface_attributes_t... */
-    cairo_matrix_t	    matrix;
-    cairo_extend_t	    extend;
-    cairo_bool_t	    has_component_alpha;
-
-    CoglPipelineFilter      filter;
-    CoglPipelineWrapMode    s_wrap;
-    CoglPipelineWrapMode    t_wrap;
-} cairo_cogl_texture_attributes_t;
-
-typedef struct _cairo_cogl_pipeline {
-    int n_layers;
-    cairo_operator_t op;
-
-    /* These are not always the same as the operator's, as sometimes
-     * this is a pre-render for a different operator */
-    cairo_bool_t src_bounded;
-    cairo_bool_t mask_bounded;
-
-    cairo_bool_t has_src_tex_clip;
-    cairo_path_fixed_t src_tex_clip;
-    cairo_bool_t has_mask_tex_clip;
-    cairo_path_fixed_t mask_tex_clip;
-    cairo_rectangle_int_t unbounded_extents;
-
-    CoglPipeline *pipeline;
-} cairo_cogl_pipeline_t;
-
-typedef enum _cairo_cogl_journal_entry_type {
-    CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE,
-    CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE,
-    CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP
-} cairo_cogl_journal_entry_type_t;
-
-typedef struct _cairo_cogl_journal_entry {
-    cairo_cogl_journal_entry_type_t type;
-} cairo_cogl_journal_entry_t;
-
-typedef struct _cairo_cogl_journal_clip_entry {
-    cairo_cogl_journal_entry_t base;
-    cairo_clip_t *clip;
-} cairo_cogl_journal_clip_entry_t;
-
-typedef struct _cairo_cogl_journal_rect_entry {
-    cairo_cogl_journal_entry_t base;
-    cairo_cogl_pipeline_t *pipeline;
-
-    float x;
-    float y;
-    float width;
-    float height;
-    cairo_matrix_t ctm;
-} cairo_cogl_journal_rect_entry_t;
-
-typedef struct _cairo_cogl_journal_prim_entry {
-    cairo_cogl_journal_entry_t base;
-    cairo_cogl_pipeline_t *pipeline;
-
-    CoglPrimitive *primitive;
-    cairo_matrix_t transform;
-} cairo_cogl_journal_prim_entry_t;
-
-typedef struct _cairo_cogl_path_fill_meta {
-    cairo_cache_entry_t	base;
-    cairo_path_fixed_t path;
-    cairo_fill_rule_t fill_rule;
-    double tolerance;
-
-    CoglPrimitive *prim;
-
-    cairo_freelist_t *freelist;
-} cairo_cogl_path_fill_meta_t;
-
-typedef struct _cairo_cogl_path_stroke_meta {
-    cairo_cache_entry_t	base;
-    cairo_path_fixed_t path;
-    cairo_stroke_style_t style;
-    double tolerance;
-
-    CoglPrimitive *prim;
-
-    cairo_freelist_t *freelist;
-} cairo_cogl_path_stroke_meta_t;
-
-static cairo_surface_t *
-_cairo_cogl_surface_create_full (cairo_cogl_device_t *dev,
-				 cairo_content_t      content,
-				 CoglFramebuffer     *framebuffer,
-				 CoglTexture         *texture);
-
-static void
-_cairo_cogl_journal_flush (cairo_cogl_surface_t *surface);
-
-cairo_private extern const cairo_surface_backend_t _cairo_cogl_surface_backend;
-
-slim_hidden_proto (cairo_cogl_device_create);
-slim_hidden_proto (cairo_cogl_surface_create_for_fb);
-slim_hidden_proto (cairo_cogl_onscreen_surface_create);
-slim_hidden_proto (cairo_cogl_offscreen_surface_create);
-slim_hidden_proto (cairo_cogl_surface_get_framebuffer);
-slim_hidden_proto (cairo_cogl_surface_get_texture);
-slim_hidden_proto (cairo_cogl_surface_end_frame);
-slim_hidden_proto (cairo_cogl_surface_synchronize);
-
-static cairo_cogl_device_t *
-to_device (cairo_device_t *device)
-{
-    return (cairo_cogl_device_t *)device;
-}
-
-/* moves trap points such that they become the actual corners of the trapezoid */
-static void
-_sanitize_trap (cairo_trapezoid_t *t)
-{
-    cairo_trapezoid_t s = *t;
-
-#define FIX(lr, tb, p) \
-    if (t->lr.p.y != t->tb) { \
-        t->lr.p.x = s.lr.p2.x + _cairo_fixed_mul_div_floor (s.lr.p1.x - s.lr.p2.x, s.tb - s.lr.p2.y, s.lr.p1.y - s.lr.p2.y); \
-        t->lr.p.y = s.tb; \
-    }
-    FIX (left,  top,    p1);
-    FIX (left,  bottom, p2);
-    FIX (right, top,    p1);
-    FIX (right, bottom, p2);
-}
-
-static cairo_status_t
-_cairo_cogl_surface_ensure_framebuffer (cairo_cogl_surface_t *surface)
-{
-    CoglError *error = NULL;
-
-    if (surface->framebuffer)
-	return CAIRO_STATUS_SUCCESS;
-
-    surface->framebuffer =
-        cogl_offscreen_new_with_texture (surface->texture);
-    if (unlikely (!cogl_framebuffer_allocate (surface->framebuffer,
-                                              &error)))
-    {
-        g_warning ("Could not create framebuffer for surface: %s",
-                   error->message);
-        cogl_error_free (error);
-	cogl_object_unref (surface->framebuffer);
-	surface->framebuffer = NULL;
-	return CAIRO_STATUS_NO_MEMORY;
-    }
-
-    cogl_framebuffer_orthographic (surface->framebuffer, 0, 0,
-                                   cogl_texture_get_width (surface->texture),
-                                   cogl_texture_get_height (surface->texture),
-                                   -1, 100);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_bool_t
-_cairo_cogl_surface_get_extents (void                  *abstract_surface,
-                                 cairo_rectangle_int_t *extents)
-{
-    cairo_cogl_surface_t *surface = abstract_surface;
-
-    extents->x = 0;
-    extents->y = 0;
-    extents->width  = surface->width;
-    extents->height = surface->height;
-
-    return TRUE;
-}
-
-/* Taken from cairo-surface-clipper.c */
-static cairo_status_t
-_cairo_path_fixed_add_box (cairo_path_fixed_t *path,
-			   const cairo_box_t *box)
-{
-    cairo_status_t status;
-
-    status = _cairo_path_fixed_move_to (path, box->p1.x, box->p1.y);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_line_to (path, box->p2.x, box->p1.y);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_line_to (path, box->p2.x, box->p2.y);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_line_to (path, box->p1.x, box->p2.y);
-    if (unlikely (status))
-	return status;
-
-    return _cairo_path_fixed_close_path (path);
-}
-
-static void
-_cairo_cogl_journal_discard (cairo_cogl_surface_t *surface)
-{
-    GList *l;
-
-    if (!surface->journal) {
-	assert (surface->last_clip == NULL);
-	return;
-    }
-
-    for (l = surface->journal->head; l; l = l->next) {
-	cairo_cogl_journal_entry_t *entry = l->data;
-	gsize entry_size;
-
-	switch (entry->type)
-	{
-	case CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP: {
-	    cairo_cogl_journal_clip_entry_t *clip_entry =
-		(cairo_cogl_journal_clip_entry_t *)entry;
-	    _cairo_clip_destroy (clip_entry->clip);
-	    entry_size = sizeof (cairo_cogl_journal_clip_entry_t);
-	    break;
-	}
-	case CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE: {
-	    cairo_cogl_journal_rect_entry_t *rect_entry =
-		(cairo_cogl_journal_rect_entry_t *)entry;
-	    cogl_object_unref (rect_entry->pipeline->pipeline);
-            if (rect_entry->pipeline->has_src_tex_clip)
-                _cairo_path_fixed_fini (&rect_entry->pipeline->src_tex_clip);
-            if (rect_entry->pipeline->has_mask_tex_clip)
-                _cairo_path_fixed_fini (&rect_entry->pipeline->mask_tex_clip);
-            g_free (rect_entry->pipeline);
-	    entry_size = sizeof (cairo_cogl_journal_rect_entry_t);
-	    break;
-	}
-	case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE: {
-	    cairo_cogl_journal_prim_entry_t *prim_entry =
-		(cairo_cogl_journal_prim_entry_t *)entry;
-	    cogl_object_unref (prim_entry->pipeline->pipeline);
-            if (prim_entry->primitive)
-	        cogl_object_unref (prim_entry->primitive);
-            if (prim_entry->pipeline->has_src_tex_clip)
-                _cairo_path_fixed_fini (&prim_entry->pipeline->src_tex_clip);
-            if (prim_entry->pipeline->has_mask_tex_clip)
-                _cairo_path_fixed_fini (&prim_entry->pipeline->mask_tex_clip);
-            g_free (prim_entry->pipeline);
-	    entry_size = sizeof (cairo_cogl_journal_prim_entry_t);
-	    break;
-	}
-	default:
-	    assert (0); /* not reached! */
-	    entry_size = 0; /* avoid compiler warning */
-	}
-	g_slice_free1 (entry_size, entry);
-    }
-
-    g_queue_clear (surface->journal);
-
-    if (surface->last_clip) {
-	_cairo_clip_destroy (surface->last_clip);
-	surface->last_clip = NULL;
-    }
-}
-
-static void
-_cairo_cogl_journal_free (cairo_cogl_surface_t *surface)
-{
-    _cairo_cogl_journal_discard (surface);
-    g_queue_free (surface->journal);
-    surface->journal = NULL;
-}
-
-static void
-_cairo_cogl_journal_log_primitive (cairo_cogl_surface_t  *surface,
-				   cairo_cogl_pipeline_t *pipeline,
-				   CoglPrimitive         *primitive,
-				   cairo_matrix_t        *transform)
-{
-    cairo_cogl_journal_prim_entry_t *entry;
-
-    if (unlikely (surface->journal == NULL))
-	surface->journal = g_queue_new ();
-
-    /* FIXME: Instead of a GList here we should stack allocate the journal
-     * entries so it would be cheaper to allocate and they can all be freed in
-     * one go after flushing! */
-    entry = g_slice_new (cairo_cogl_journal_prim_entry_t);
-    entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE;
-
-    entry->pipeline = pipeline;
-
-    entry->primitive = primitive;
-    if (primitive)
-        cogl_object_ref (primitive);
-
-    entry->transform = *transform;
-
-    g_queue_push_tail (surface->journal, entry);
-
-#ifdef DISABLE_BATCHING
-    _cairo_cogl_journal_flush (surface);
-#else
-    /* To avoid consuming too much memory, flush the journal if it gets
-     * to a certain size */
-    if (g_queue_get_length (surface->journal) > MAX_JOURNAL_SIZE)
-        _cairo_cogl_journal_flush (surface);
-#endif
-}
-
-static void
-_cairo_cogl_journal_log_rectangle (cairo_cogl_surface_t  *surface,
-				   cairo_cogl_pipeline_t *pipeline,
-				   float                  x,
-				   float                  y,
-				   float                  width,
-				   float                  height,
-				   cairo_matrix_t        *ctm)
-{
-    cairo_cogl_journal_rect_entry_t *entry;
-
-    if (unlikely (surface->journal == NULL))
-	surface->journal = g_queue_new ();
-
-    /* FIXME: Instead of a GList here we should stack allocate the journal
-     * entries so it would be cheaper to allocate and they can all be freed in
-     * one go after flushing! */
-    entry = g_slice_new (cairo_cogl_journal_rect_entry_t);
-    entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE;
-
-    entry->pipeline = pipeline;
-
-    entry->x = x;
-    entry->y = y;
-    entry->width = width;
-    entry->height = height;
-    entry->ctm = *ctm;
-
-    g_queue_push_tail (surface->journal, entry);
-
-#ifdef DISABLE_BATCHING
-    _cairo_cogl_journal_flush (surface);
-#else
-    /* To avoid consuming too much memory, flush the journal if it gets
-     * to a certain size */
-    if (g_queue_get_length (surface->journal) > MAX_JOURNAL_SIZE)
-        _cairo_cogl_journal_flush (surface);
-#endif
-}
-
-static void
-_cairo_cogl_journal_log_clip (cairo_cogl_surface_t *surface,
-			      const cairo_clip_t   *clip)
-{
-    cairo_cogl_journal_clip_entry_t *entry;
-
-    if (unlikely (surface->journal == NULL))
-	surface->journal = g_queue_new ();
-
-    /* FIXME: Instead of a GList here we should stack allocate the journal
-     * entries so it would be cheaper to allocate and they can all be freed in
-     * one go after flushing! */
-    entry = g_slice_new (cairo_cogl_journal_clip_entry_t);
-    entry->base.type = CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP;
-    entry->clip = _cairo_clip_copy (clip);
-
-    g_queue_push_tail (surface->journal, entry);
-}
-
-static CoglAttributeBuffer *
-_cairo_cogl_device_allocate_buffer_space (cairo_cogl_device_t *dev,
-                                          size_t               size,
-                                          size_t              *offset,
-                                          void               **pointer)
-{
-    /* XXX: In the Cogl journal we found it more efficient to have a pool of
-     * buffers that we re-cycle but for now we simply throw away our stack
-     * buffer each time we flush. */
-    if (unlikely (dev->buffer_stack &&
-		  (dev->buffer_stack_size - dev->buffer_stack_offset) < size)) {
-	cogl_buffer_unmap (dev->buffer_stack);
-	cogl_object_unref (dev->buffer_stack);
-	dev->buffer_stack = NULL;
-	dev->buffer_stack_size *= 2;
-    }
-
-    if (unlikely (dev->buffer_stack_size < size))
-	dev->buffer_stack_size = size * 2;
-
-    if (unlikely (dev->buffer_stack == NULL)) {
-	dev->buffer_stack =
-            cogl_attribute_buffer_new (dev->cogl_context,
-                                       dev->buffer_stack_size,
-                                       NULL);
-	dev->buffer_stack_pointer =
-	    cogl_buffer_map (dev->buffer_stack,
-			     COGL_BUFFER_ACCESS_WRITE,
-			     COGL_BUFFER_MAP_HINT_DISCARD);
-	dev->buffer_stack_offset = 0;
-    }
-
-    *pointer = dev->buffer_stack_pointer + dev->buffer_stack_offset;
-    *offset = dev->buffer_stack_offset;
-
-    dev->buffer_stack_offset += size;
-    return cogl_object_ref (dev->buffer_stack);
-}
-
-
-static CoglAttributeBuffer *
-_cairo_cogl_traps_to_triangles_buffer (cairo_cogl_surface_t *surface,
-				       cairo_traps_t        *traps,
-				       size_t               *offset,
-				       cairo_bool_t          one_shot)
-{
-    CoglAttributeBuffer *buffer;
-    int n_traps = traps->num_traps;
-    int i;
-    CoglVertexP2 *triangles;
-    cairo_cogl_device_t *dev = to_device(surface->base.device);
-
-    if (one_shot) {
-	buffer =
-            _cairo_cogl_device_allocate_buffer_space (dev,
-                                                      n_traps * sizeof (CoglVertexP2) * 6,
-                                                      offset,
-                                                      (void **)&triangles);
-	if (!buffer)
-	    return NULL;
-    } else {
-	buffer =
-            cogl_attribute_buffer_new (dev->cogl_context,
-                                       n_traps * sizeof (CoglVertexP2) * 6,
-                                       NULL);
-	if (!buffer)
-	    return NULL;
-	triangles = cogl_buffer_map (buffer,
-				     COGL_BUFFER_ACCESS_WRITE,
-				     COGL_BUFFER_MAP_HINT_DISCARD);
-	if (!triangles)
-	    return NULL;
-	*offset = 0;
-    }
-
-    /* XXX: This is can be very expensive. I'm not sure a.t.m if it's
-     * predominantly the bandwidth required or the cost of the fixed_to_float
-     * conversions but either way we should try using an index buffer to
-     * reduce the amount we upload by 1/3 (offset by allocating and uploading
-     * indices though) sadly though my experience with the intel mesa drivers
-     * is that slow paths can easily be hit when starting to use indices.
-     */
-    for (i = 0; i < n_traps; i++)
-    {
-	CoglVertexP2 *p = &triangles[i * 6];
-	cairo_trapezoid_t *trap = &traps->traps[i];
-
-	p[0].x = _cairo_fixed_to_double (trap->left.p1.x);
-	p[0].y = _cairo_fixed_to_double (trap->left.p1.y);
-
-	p[1].x = _cairo_fixed_to_double (trap->left.p2.x);
-	p[1].y = _cairo_fixed_to_double (trap->left.p2.y);
-
-	p[2].x = _cairo_fixed_to_double (trap->right.p2.x);
-	p[2].y = _cairo_fixed_to_double (trap->right.p2.y);
-
-	p[3].x = p[0].x;
-	p[3].y = p[0].y;
-
-	p[4].x = p[2].x;
-	p[4].y = p[2].y;
-
-	p[5].x = _cairo_fixed_to_double (trap->right.p1.x);
-	p[5].y = _cairo_fixed_to_double (trap->right.p1.y);
-    }
-
-    if (!one_shot)
-	cogl_buffer_unmap (buffer);
-
-    return buffer;
-}
-
-static CoglPrimitive *
-_cairo_cogl_traps_to_composite_prim (cairo_cogl_surface_t *surface,
-				     cairo_traps_t        *traps,
-				     cairo_bool_t          one_shot)
-{
-    int n_traps = traps->num_traps;
-    size_t offset;
-    CoglAttributeBuffer *buffer;
-    CoglPrimitive *prim;
-    CoglAttribute *attributes[3];
-    const char *attrib_names[3] = {"cogl_position_in",
-                                   "cogl_tex_coord0_in",
-                                   "cogl_tex_coord1_in"};
-    int i;
-
-    /* XXX: Ideally we would skip tessellating to traps entirely since
-     * given their representation, conversion to triangles is quite expensive.
-     *
-     * This simplifies the conversion to triangles by making the end points of
-     * the two side lines actually just correspond to the corners of the
-     * traps.
-     */
-    for (i = 0; i < n_traps; i++)
-	_sanitize_trap (&traps->traps[i]);
-
-    buffer = _cairo_cogl_traps_to_triangles_buffer (surface,
-                                                    traps,
-                                                    &offset,
-                                                    one_shot);
-
-    /* We create the largest used number of texture coordinate
-     * attributes here to ensure that when cached, they can be reused
-     * with any pipeline that we may associate with a given path. If
-     * the corresponding layer for a texture coordinates attribute
-     * doesn't exist, cogl simply ignores it. Since all of the
-     * attributes are aliasing the same attribute buffer, the overhead
-     * of specifying them is minimal. */
-    for (i = 0; i < 3; i++) {
-        attributes[i] = cogl_attribute_new (buffer,
-                                            attrib_names[i],
-                                            sizeof (CoglVertexP2),
-                                            offset,
-                                            2,
-                                            COGL_ATTRIBUTE_TYPE_FLOAT);
-    }
-
-    /* The attributes will have taken references on the buffer */
-    cogl_object_unref (buffer);
-
-    prim =
-        cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
-			                    n_traps * 6, attributes, 3);
-
-    /* The primitive will now keep the attributes alive... */
-    for (i = 0; i < 3; i++)
-        cogl_object_unref (attributes[i]);
-
-    return prim;
-}
-
-/* In order to facilitate path caching, we transform the input path
- * into a form that will make all translations and rotations of a given
- * path identical, thereby allowing them to be identified with
- * conventional path hashing and equivalence functions. A
- * transformation matrix is also output so that the path can be
- * transformed back into its original form during rendering. */
-static cairo_int_status_t
-_cairo_cogl_get_untransformed_path (cairo_path_fixed_t       *copy,
-                                    const cairo_path_fixed_t *orig,
-                                    cairo_matrix_t           *transform_out)
-{
-    cairo_matrix_t transform;
-    cairo_int_status_t status;
-
-    if (orig->buf.base.num_points < 1)
-        return CAIRO_INT_STATUS_NOTHING_TO_DO;
-
-    status = _cairo_path_fixed_init_copy (copy, orig);
-    if (unlikely (status))
-        return status;
-
-    /* First the path is translated so that its first point lies on the
-     * origin. */
-    cairo_matrix_init_translate (&transform,
-                                 -_cairo_fixed_to_double(orig->buf.points[0].x),
-                                 -_cairo_fixed_to_double(orig->buf.points[0].y));
-
-    /* Then the path is rotated so that its second point lies on the
-     * x axis. */
-    if (orig->buf.base.num_points > 1) {
-        double x = _cairo_fixed_to_double(orig->buf.points[1].x) -
-                   _cairo_fixed_to_double(orig->buf.points[0].x);
-        double y = _cairo_fixed_to_double(orig->buf.points[1].y) -
-                   _cairo_fixed_to_double(orig->buf.points[0].y);
-        double hyp = sqrt (x * x + y * y);
-
-        transform.xx = x / hyp;
-        transform.yy = x / hyp;
-        transform.xy = -y / hyp;
-        transform.yx = y / hyp;
-    }
-
-    _cairo_path_fixed_transform (copy, &transform);
-
-    *transform_out = transform;
-    status = cairo_matrix_invert (transform_out);
-    if (unlikely (status)) {
-        _cairo_path_fixed_fini (copy);
-        return status;
-    }
-
-    return CAIRO_INT_STATUS_SUCCESS;
-}
-
-static void
-_cairo_cogl_path_fill_meta_destroy (cairo_cogl_path_fill_meta_t *meta)
-{
-    _cairo_path_fixed_fini (&meta->path);
-    cogl_object_unref (meta->prim);
-
-    _cairo_freelist_free (meta->freelist, meta);
-}
-
-static cairo_bool_t
-_cairo_cogl_path_fill_meta_equal (const void *key_a, const void *key_b)
-{
-    const cairo_cogl_path_fill_meta_t *meta0 = key_a;
-    const cairo_cogl_path_fill_meta_t *meta1 = key_b;
-
-    if (meta0->fill_rule != meta1->fill_rule)
-        return FALSE;
-
-    if (meta0->tolerance != meta1->tolerance)
-        return FALSE;
-
-    if (!_cairo_path_fixed_equal (&meta0->path, &meta1->path))
-        return FALSE;
-
-    return TRUE;
-}
-
-static cairo_int_status_t
-_cairo_cogl_fill_to_primitive (cairo_cogl_surface_t	*surface,
-			       const cairo_path_fixed_t	*path,
-			       cairo_fill_rule_t	 fill_rule,
-			       double			 tolerance,
-			       cairo_bool_t		 one_shot,
-			       CoglPrimitive	       **primitive,
-                               cairo_matrix_t           *transform)
-{
-    cairo_traps_t traps;
-    cairo_int_status_t status;
-    cairo_cogl_path_fill_meta_t meta;
-    cairo_cogl_path_fill_meta_t *acquired_meta;
-    cairo_cogl_path_fill_meta_t *insert_meta = NULL;
-    cairo_cogl_device_t *dev = to_device (surface->base.device);
-    uintptr_t hash;
-
-    *primitive = NULL;
-
-    status = _cairo_cogl_get_untransformed_path (&meta.path,
-                                                 path,
-                                                 transform);
-    if (unlikely (status))
-        return status;
-
-    hash = _cairo_path_fixed_hash (&meta.path);
-    hash = _cairo_hash_bytes (hash, &fill_rule, sizeof (fill_rule));
-    hash = _cairo_hash_bytes (hash, &tolerance, sizeof (tolerance));
-    meta.base.hash = hash;
-    meta.tolerance = tolerance;
-    meta.fill_rule = fill_rule;
-
-    acquired_meta = _cairo_cache_lookup (&dev->path_fill_prim_cache,
-                                         &meta.base);
-
-    if (acquired_meta) {
-        // g_print ("fill cache hit");
-        *primitive = cogl_object_ref (acquired_meta->prim);
-        _cairo_path_fixed_fini (&meta.path);
-        return CAIRO_STATUS_SUCCESS;
-    }
-
-    _cairo_traps_init (&traps);
-    status = _cairo_path_fixed_fill_to_traps (&meta.path,
-                                              fill_rule,
-                                              tolerance,
-                                              &traps);
-    if (unlikely (status))
-	goto BAIL;
-
-    if (traps.num_traps == 0) {
-	status = CAIRO_INT_STATUS_NOTHING_TO_DO;
-	goto BAIL;
-    }
-
-    *primitive = _cairo_cogl_traps_to_composite_prim (surface,
-                                                      &traps,
-                                                      one_shot);
-    if (unlikely (!*primitive)) {
-	status = CAIRO_INT_STATUS_NO_MEMORY;
-	goto BAIL;
-    }
-
-    insert_meta =
-        _cairo_freelist_alloc (&dev->path_fill_meta_freelist);
-    if (unlikely (!insert_meta)) {
-        status = CAIRO_INT_STATUS_NO_MEMORY;
-        goto BAIL;
-    }
-
-    insert_meta->base.hash = meta.base.hash;
-    insert_meta->base.size =
-        traps.num_traps * sizeof (CoglVertexP2) * 6;
-    insert_meta->tolerance = tolerance;
-    insert_meta->fill_rule = fill_rule;
-    insert_meta->prim = cogl_object_ref (*primitive);
-    insert_meta->freelist = &dev->path_fill_meta_freelist;
-
-    status = _cairo_path_fixed_init_copy (&insert_meta->path,
-                                          &meta.path);
-    if (unlikely (status))
-        goto BAIL;
-
-    if (unlikely (_cairo_cache_insert (&dev->path_fill_prim_cache,
-                                       &insert_meta->base)))
-    {
-        g_warning ("Fill primitive cache insertion unsuccessful");
-        goto BAIL;
-    }
-
-    _cairo_path_fixed_fini (&meta.path);
-    _cairo_traps_fini (&traps);
-
-    return status;
-
-BAIL:
-    if (*primitive) {
-        cogl_object_unref (*primitive);
-        *primitive = NULL;
-    }
-    if (insert_meta)
-        _cairo_cogl_path_fill_meta_destroy (insert_meta);
-    _cairo_path_fixed_fini (&meta.path);
-    _cairo_traps_fini (&traps);
-
-    return status;
-}
-
-static cairo_bool_t
-_cairo_cogl_stroke_style_equal (const cairo_stroke_style_t *a,
-			        const cairo_stroke_style_t *b)
-{
-    if (a->line_width == b->line_width &&
-	a->line_cap == b->line_cap &&
-	a->line_join == b->line_join &&
-	a->miter_limit == b->miter_limit &&
-	a->num_dashes == b->num_dashes &&
-	a->dash_offset == b->dash_offset)
-    {
-	unsigned int i;
-	for (i = 0; i < a->num_dashes; i++) {
-	    if (a->dash[i] != b->dash[i])
-		return FALSE;
-	}
-    }
-    return TRUE;
-}
-
-static cairo_bool_t
-_cairo_cogl_path_stroke_meta_equal (const void *key_a,
-                                    const void *key_b)
-{
-    const cairo_cogl_path_stroke_meta_t *meta0 = key_a;
-    const cairo_cogl_path_stroke_meta_t *meta1 = key_b;
-
-    if (meta0->tolerance != meta1->tolerance)
-        return FALSE;
-
-    if (!_cairo_cogl_stroke_style_equal (&meta0->style, &meta1->style))
-        return FALSE;
-
-    if (!_cairo_path_fixed_equal (&meta0->path, &meta1->path))
-        return FALSE;
-
-    return TRUE;
-}
-
-static void
-_cairo_cogl_path_stroke_meta_destroy (cairo_cogl_path_stroke_meta_t *meta)
-{
-    _cairo_stroke_style_fini (&meta->style);
-    _cairo_path_fixed_fini (&meta->path);
-    cogl_object_unref (meta->prim);
-
-    _cairo_freelist_free (meta->freelist, meta);
-}
-
-static uintptr_t
-_cairo_cogl_stroke_style_hash (uintptr_t                   hash,
-			       const cairo_stroke_style_t *style)
-{
-    unsigned int i;
-    hash = _cairo_hash_bytes (hash, &style->line_width, sizeof (style->line_width));
-    hash = _cairo_hash_bytes (hash, &style->line_cap, sizeof (style->line_cap));
-    hash = _cairo_hash_bytes (hash, &style->line_join, sizeof (style->line_join));
-    hash = _cairo_hash_bytes (hash, &style->miter_limit, sizeof (style->miter_limit));
-    hash = _cairo_hash_bytes (hash, &style->num_dashes, sizeof (style->num_dashes));
-    hash = _cairo_hash_bytes (hash, &style->dash_offset, sizeof (style->dash_offset));
-    for (i = 0; i < style->num_dashes; i++)
-	hash = _cairo_hash_bytes (hash, &style->dash[i], sizeof (double));
-    return hash;
-}
-
-static cairo_int_status_t
-_cairo_cogl_stroke_to_primitive (cairo_cogl_surface_t	    *surface,
-				 const cairo_path_fixed_t   *path,
-				 const cairo_stroke_style_t *style,
-				 double			     tolerance,
-				 cairo_bool_t		     one_shot,
-				 CoglPrimitive		   **primitive,
-                                 cairo_matrix_t             *transform)
-{
-    cairo_traps_t traps;
-    cairo_int_status_t status;
-    cairo_cogl_path_stroke_meta_t meta;
-    cairo_cogl_path_stroke_meta_t *acquired_meta;
-    cairo_cogl_path_stroke_meta_t *insert_meta = NULL;
-    cairo_matrix_t identity;
-    cairo_cogl_device_t *dev = to_device (surface->base.device);
-    uintptr_t hash;
-
-    *primitive = NULL;
-
-    status = _cairo_cogl_get_untransformed_path (&meta.path,
-                                                 path,
-                                                 transform);
-    if (unlikely (status))
-        return status;
-
-    hash = _cairo_path_fixed_hash (&meta.path);
-    hash = _cairo_cogl_stroke_style_hash (hash, style);
-    hash = _cairo_hash_bytes (hash, &tolerance, sizeof (tolerance));
-    meta.base.hash = hash;
-    meta.tolerance = tolerance;
-
-    status = _cairo_stroke_style_init_copy (&meta.style, style);
-    if (unlikely (status)) {
-        _cairo_path_fixed_fini (&meta.path);
-        return status;
-    }
-
-    acquired_meta = _cairo_cache_lookup (&dev->path_stroke_prim_cache,
-                                         &meta.base);
-
-    if (acquired_meta) {
-        // g_print ("stroke cache hit");
-        *primitive = cogl_object_ref (acquired_meta->prim);
-        _cairo_path_fixed_fini (&meta.path);
-        return CAIRO_STATUS_SUCCESS;
-    }
-
-    _cairo_traps_init (&traps);
-
-    cairo_matrix_init_identity (&identity);
-    status = _cairo_path_fixed_stroke_polygon_to_traps (&meta.path,
-                                                        style,
-                                                        &identity,
-                                                        &identity,
-                                                        tolerance,
-                                                        &traps);
-    if (unlikely (status))
-	goto BAIL;
-
-    if (traps.num_traps == 0) {
-	status = CAIRO_INT_STATUS_NOTHING_TO_DO;
-	goto BAIL;
-    }
-
-    *primitive = _cairo_cogl_traps_to_composite_prim (surface,
-                                                      &traps,
-                                                      one_shot);
-    if (unlikely (!*primitive)) {
-	status = CAIRO_INT_STATUS_NO_MEMORY;
-	goto BAIL;
-    }
-
-    insert_meta =
-        _cairo_freelist_alloc (&dev->path_stroke_meta_freelist);
-    if (unlikely (!insert_meta)) {
-        status = CAIRO_INT_STATUS_NO_MEMORY;
-        goto BAIL;
-    }
-
-    insert_meta->base.hash = meta.base.hash;
-    insert_meta->base.size =
-        traps.num_traps * sizeof (CoglVertexP2) * 6;
-    insert_meta->tolerance = tolerance;
-    insert_meta->prim = cogl_object_ref (*primitive);
-    insert_meta->freelist = &dev->path_stroke_meta_freelist;
-
-    status = _cairo_stroke_style_init_copy (&insert_meta->style,
-                                            style);
-    if (unlikely (status)) {
-        _cairo_stroke_style_fini (&insert_meta->style);
-        free (insert_meta);
-        insert_meta = NULL;
-        goto BAIL;
-    }
-
-    status = _cairo_path_fixed_init_copy (&insert_meta->path,
-                                          &meta.path);
-    if (unlikely (status))
-        goto BAIL;
-
-    if (unlikely (_cairo_cache_insert (&dev->path_stroke_prim_cache,
-                                       &insert_meta->base)))
-    {
-        g_warning ("Stroke primitive cache insertion unsuccessful");
-        goto BAIL;
-    }
-
-    _cairo_path_fixed_fini (&meta.path);
-    _cairo_stroke_style_fini (&meta.style);
-    _cairo_traps_fini (&traps);
-
-    return status;
-
-BAIL:
-    if (*primitive) {
-        cogl_object_unref (*primitive);
-        *primitive = NULL;
-    }
-    if (insert_meta)
-        _cairo_cogl_path_stroke_meta_destroy (insert_meta);
-    _cairo_path_fixed_fini (&meta.path);
-    _cairo_stroke_style_fini (&meta.style);
-    _cairo_traps_fini (&traps);
-
-    return status;
-}
-
-static void
-_cairo_cogl_set_path_prim_clip (cairo_cogl_surface_t *surface,
-                                cairo_path_fixed_t   *path,
-                                int                  *clip_stack_depth,
-                                cairo_fill_rule_t     fill_rule,
-                                double                tolerance)
-{
-    cairo_rectangle_int_t extents;
-    cairo_int_status_t status;
-    CoglPrimitive *prim;
-    cairo_matrix_t transform;
-    CoglMatrix matrix;
-    double x1, y1, x2, y2;
-
-    status = _cairo_cogl_fill_to_primitive (surface,
-                                            path,
-                                            fill_rule,
-                                            tolerance,
-                                            FALSE,
-                                            &prim,
-                                            &transform);
-    if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) {
-        /* If the clip is of zero fill area, set all clipped */
-        cogl_framebuffer_push_scissor_clip (surface->framebuffer,
-                                            0, 0, 0, 0);
-        (*clip_stack_depth)++;
-        return;
-    } else if (unlikely (status)) {
-        g_warning ("Failed to get primitive for clip path while "
-                   "flushing journal");
-        goto BAIL;
-    }
-
-    float transformfv[16] = {
-        transform.xx, transform.yx, 0, 0,
-        transform.xy, transform.yy, 0, 0,
-        0,            0,            1, 0,
-        transform.x0, transform.y0, 0, 1
-    };
-
-    cogl_matrix_init_from_array (&matrix, transformfv);
-
-    cogl_framebuffer_push_matrix (surface->framebuffer);
-    cogl_framebuffer_transform (surface->framebuffer, &matrix);
-
-    _cairo_path_fixed_approximate_clip_extents (path, &extents);
-
-    /* The extents need to be transformed by the inverse of the
-     * modelview matrix because they are in terms of un-transformed
-     * device coordinates and the bounds coordinates will be
-     * transformed by the modelview matrix */
-    status = cairo_matrix_invert (&transform);
-    if (unlikely (status)) {
-        g_warning ("Could not apply clip due to invalid matrix from "
-                   "path transformation");
-        goto BAIL;
-    }
-
-    x1 = extents.x;
-    y1 = extents.y;
-    x2 = extents.x + extents.width;
-    y2 = extents.y + extents.height;
-    _cairo_matrix_transform_bounding_box (&transform,
-                                          &x1, &y1, &x2, &y2,
-                                          NULL);
-
-    cogl_framebuffer_push_primitive_clip (surface->framebuffer, prim,
-                                          x1, y1, x2, y2);
-    (*clip_stack_depth)++;
-
-    cogl_framebuffer_pop_matrix (surface->framebuffer);
-
-BAIL:
-    if (prim)
-        cogl_object_unref (prim);
-}
-
-/* This is the way in which we handle CAIRO_EXTEND_NONE set on the
- * source or mask pattern surfaces, as well as unbounded operators.
- * First, we limit the rendering area to the region which will not be
- * sampled from beyond the source or mask textures with additional clip
- * paths, which were created when we obtained the original pipeline.
- * The region will also be limited by the drawing area due to the fact
- * we are drawing with the original primitive's vertices.
- *
- * In order to handle unbounded operators, we do a second rendering pass
- * for places outside of such region. We limit the rending to outside
- * this region by using a depth buffer to preserve all places where
- * rendering took place during the first pass. For this region, we also
- * have to remove the CAIRO_EXTEND_NONE clips if the operator is not
- * bound by their respective contents. Because OpenGL sets all vertex
- * z-values to 0.0 if none are supplied in the attributes data (we only
- * supply x and y values), it will update the region in the buffer to a
- * value over the default clearing value of 1.0. Given that the default
- * test function is GL_LESS, we don't have to set z attributes on the
- * vertices of the second rendering pass either, as 0.0 will never be
- * less than 0.0. If cogl ever adds a method to clip out a primitive
- * instead of just clipping it in, we may be able to use a more
- * efficient method using the stencil buffer. */
-static void
-_cairo_cogl_apply_tex_clips (cairo_cogl_surface_t  *surface,
-                             int                   *clip_stack_depth,
-                             cairo_cogl_pipeline_t *pipeline)
-{
-    CoglDepthState depth_state;
-    CoglBool cogl_status;
-
-    /* Enable the depth test if it will be needed */
-    if ((!pipeline->mask_bounded && pipeline->has_mask_tex_clip) ||
-        (!pipeline->src_bounded && pipeline->has_src_tex_clip))
-    {
-        cogl_depth_state_init (&depth_state);
-        cogl_depth_state_set_test_enabled (&depth_state, TRUE);
-        cogl_status = cogl_pipeline_set_depth_state (pipeline->pipeline,
-                                                     &depth_state,
-                                                     NULL);
-        if (unlikely (cogl_status != TRUE))
-            g_warning ("Error setting depth state for unbounded render");
-
-        /* Clear the depth buffer to 1.0. The color values are unused
-         * placeholders. */
-        cogl_framebuffer_clear4f (surface->framebuffer,
-                                  COGL_BUFFER_BIT_DEPTH,
-                                  0.0, 0.0, 0.0, 0.0);
-    }
-
-    if (pipeline->mask_bounded && !pipeline->src_bounded) {
-        /* Push mask clip first so later we can pop the source clip
-         * and still be bound by the mask clip */
-        if (pipeline->has_mask_tex_clip)
-            _cairo_cogl_set_path_prim_clip (surface,
-                                            &pipeline->mask_tex_clip,
-                                            clip_stack_depth,
-                                            CAIRO_FILL_RULE_WINDING,
-                                            0.0);
-        if (pipeline->has_src_tex_clip)
-            _cairo_cogl_set_path_prim_clip (surface,
-                                            &pipeline->src_tex_clip,
-                                            clip_stack_depth,
-                                            CAIRO_FILL_RULE_WINDING,
-                                            0.0);
-    } else {
-        if (pipeline->has_src_tex_clip)
-            _cairo_cogl_set_path_prim_clip (surface,
-                                            &pipeline->src_tex_clip,
-                                            clip_stack_depth,
-                                            CAIRO_FILL_RULE_WINDING,
-                                            0.0);
-        if (pipeline->has_mask_tex_clip)
-            _cairo_cogl_set_path_prim_clip (surface,
-                                            &pipeline->mask_tex_clip,
-                                            clip_stack_depth,
-                                            CAIRO_FILL_RULE_WINDING,
-                                            0.0);
-    }
-}
-
-/* Get the pipeline for the second pass */
-static CoglPipeline *
-_cairo_cogl_setup_unbounded_area_pipeline (cairo_cogl_surface_t *surface,
-                                           cairo_operator_t      op)
-{
-    CoglPipeline *unbounded_pipeline;
-    CoglDepthState depth_state;
-    CoglBool cogl_status;
-    cairo_cogl_device_t *dev = to_device(surface->base.device);
-
-    /* If a template pipeline exists for any given operator, the
-     * corresponding solid template pipeline always exists */
-    unbounded_pipeline =
-        cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-    cogl_pipeline_set_color4f (unbounded_pipeline, 0.0, 0.0, 0.0, 0.0);
-
-    /* Enable depth test on second-pass pipeline */
-    cogl_depth_state_init (&depth_state);
-    cogl_depth_state_set_test_enabled (&depth_state, TRUE);
-    cogl_status = cogl_pipeline_set_depth_state (unbounded_pipeline,
-                                                 &depth_state,
-                                                 NULL);
-    if (unlikely (cogl_status != TRUE))
-        g_warning ("Error setting depth state for unbounded render");
-
-    return unbounded_pipeline;
-}
-
-static void
-_cairo_cogl_unbounded_render (cairo_cogl_surface_t  *surface,
-                              int                   *clip_stack_depth,
-                              cairo_cogl_pipeline_t *pipeline,
-                              cairo_bool_t          *needs_vertex_render)
-{
-    /* We will need a second rendering of the original vertices if we
-     * still need to be bounded by the mask but had a source tex clip */
-    *needs_vertex_render = FALSE;
-
-    /* Pop all unbounded tex clips. Do not pop clips the operator is
-     * bounded by, so that we can still be bounded by them during the
-     * second pass (vertex render or extents render). */
-    if (pipeline->mask_bounded && pipeline->src_bounded) {
-        /* We don't need a second pass if it will just be in the same
-         * region as the first */
-    } else if (pipeline->src_bounded) {
-        if (pipeline->has_mask_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-    } else if (pipeline->mask_bounded) {
-        if (pipeline->has_src_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-            *needs_vertex_render = TRUE;
-        }
-    } else {
-        if (pipeline->has_src_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-        if (pipeline->has_mask_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-    }
-
-    /* If an operator is unbounded by the mask, we need to render the
-     * second transparent pass within the full unbounded extents */
-    if (!pipeline->mask_bounded) {
-        CoglPipeline *unbounded_pipeline;
-
-        /* Draw a transparent rectangle to cover the entire extents */
-        unbounded_pipeline =
-            _cairo_cogl_setup_unbounded_area_pipeline (surface,
-                                                       pipeline->op);
-        cogl_framebuffer_draw_rectangle (surface->framebuffer,
-                                         unbounded_pipeline,
-                                         pipeline->unbounded_extents.x,
-                                         pipeline->unbounded_extents.y,
-                                         pipeline->unbounded_extents.x + pipeline->unbounded_extents.width,
-                                         pipeline->unbounded_extents.y + pipeline->unbounded_extents.height);
-        cogl_object_unref (unbounded_pipeline);
-    }
-}
-
-static void
-_cairo_cogl_post_unbounded_render (cairo_cogl_surface_t  *surface,
-                                   int                   *clip_stack_depth,
-                                   cairo_cogl_pipeline_t *pipeline)
-{
-    CoglDepthState depth_state;
-    CoglBool cogl_status;
-
-    /* Disable the depth test */
-    if ((!pipeline->mask_bounded && pipeline->has_mask_tex_clip) ||
-        (!pipeline->src_bounded && pipeline->has_src_tex_clip))
-    {
-        cogl_depth_state_init (&depth_state);
-        cogl_depth_state_set_test_enabled (&depth_state, FALSE);
-        cogl_status = cogl_pipeline_set_depth_state (pipeline->pipeline,
-                                                     &depth_state,
-                                                     NULL);
-        if (unlikely (cogl_status != TRUE))
-            g_warning ("Error setting depth state after unbounded render");
-    }
-
-    /* Pop all bounded tex clips (those that were not popped before) */
-    if (pipeline->src_bounded && pipeline->mask_bounded) {
-        if (pipeline->has_src_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-        if (pipeline->has_mask_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-    } else if (pipeline->src_bounded) {
-        if (pipeline->has_src_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-    } else if (pipeline->mask_bounded) {
-        if (pipeline->has_mask_tex_clip) {
-            cogl_framebuffer_pop_clip (surface->framebuffer);
-            (*clip_stack_depth)--;
-        }
-    } else {
-        /* We have already popped all of the clips in the
-         * unbounded_render function */
-    }
-}
-
-static void
-_cairo_cogl_journal_flush (cairo_cogl_surface_t *surface)
-{
-    GList *l;
-    cairo_cogl_device_t *dev;
-    int clip_stack_depth = 0;
-    int i;
-
-    if (!surface->journal)
-	return;
-
-    dev = to_device(surface->base.device);
-    if (dev->buffer_stack && dev->buffer_stack_offset) {
-	cogl_buffer_unmap (dev->buffer_stack);
-	cogl_object_unref (dev->buffer_stack);
-	dev->buffer_stack = NULL;
-    }
-
-    if (unlikely (_cairo_cogl_surface_ensure_framebuffer (surface))) {
-        g_warning ("Could not get framebuffer for flushing journal");
-        assert (0);
-    }
-
-    cogl_framebuffer_push_matrix (surface->framebuffer);
-
-    for (l = surface->journal->head; l; l = l->next) {
-	cairo_cogl_journal_entry_t *entry = l->data;
-
-	switch (entry->type)
-	{
-	case CAIRO_COGL_JOURNAL_ENTRY_TYPE_CLIP: {
-	    cairo_cogl_journal_clip_entry_t *clip_entry =
-		(cairo_cogl_journal_clip_entry_t *)entry;
-	    cairo_clip_path_t *path;
-
-	    for (i = 0; i < clip_stack_depth; i++)
-		cogl_framebuffer_pop_clip (surface->framebuffer);
-	    clip_stack_depth = 0;
-
-            if (clip_entry->clip == NULL)
-                continue; // there is no clip
-
-	    for (path = clip_entry->clip->path, i = 0;
-                 path;
-                 path = path->prev, i++)
-            {
-                _cairo_cogl_set_path_prim_clip (surface,
-                                                &path->path,
-                                                &clip_stack_depth,
-                                                path->fill_rule,
-                                                path->tolerance);
-            }
-
-	    if (clip_entry->clip->num_boxes > 0) {
-                cairo_path_fixed_t boxes_path;
-
-                _cairo_path_fixed_init (&boxes_path);
-                for (int i = 0; i < clip_entry->clip->num_boxes; i++) {
-                    if (unlikely (_cairo_path_fixed_add_box (&boxes_path,
-                                                             &clip_entry->clip->boxes[i])))
-                    {
-                        g_warning ("Could not add all clip boxes while "
-                                   "flushing journal");
-                        break;
-                    }
-                }
-
-                _cairo_cogl_set_path_prim_clip (surface,
-                                                &boxes_path,
-                                                &clip_stack_depth,
-                                                CAIRO_FILL_RULE_WINDING,
-                                                0.0);
-
-                _cairo_path_fixed_fini (&boxes_path);
-	    }
-
-	    surface->n_clip_updates_per_frame++;
-	    break;
-	}
-	case CAIRO_COGL_JOURNAL_ENTRY_TYPE_RECTANGLE: {
-	    cairo_cogl_journal_rect_entry_t *rect_entry =
-		(cairo_cogl_journal_rect_entry_t *)entry;
-	    float tex_coords[8];
-	    float x1 = rect_entry->x;
-	    float y1 = rect_entry->y;
-	    float x2 = rect_entry->x + rect_entry->width;
-	    float y2 = rect_entry->y + rect_entry->height;
-	    cairo_matrix_t *ctm = &rect_entry->ctm;
-	    float ctmfv[16] = {
-		ctm->xx, ctm->yx, 0, 0,
-		ctm->xy, ctm->yy, 0, 0,
-		0,	     0,	      1, 0,
-		ctm->x0, ctm->y0, 0, 1
-	    };
-	    CoglMatrix transform;
-            cairo_bool_t needs_vertex_render;
-            CoglPipeline *unbounded_pipeline;
-
-	    cogl_matrix_init_from_array (&transform, ctmfv);
-
-            _cairo_cogl_apply_tex_clips (surface,
-                                         &clip_stack_depth,
-                                         rect_entry->pipeline);
-
-	    if (rect_entry->pipeline->n_layers) {
-		g_assert (rect_entry->pipeline->n_layers <= 2);
-		tex_coords[0] = x1;
-		tex_coords[1] = y1;
-		tex_coords[2] = x2;
-		tex_coords[3] = y2;
-		if (rect_entry->pipeline->n_layers > 1)
-		    memcpy (&tex_coords[4], tex_coords, sizeof (float) * 4);
-	    }
-
-	    cogl_framebuffer_push_matrix (surface->framebuffer);
-	    cogl_framebuffer_transform (surface->framebuffer, &transform);
-	    cogl_framebuffer_draw_multitextured_rectangle (surface->framebuffer,
-                                                           rect_entry->pipeline->pipeline,
-                                                           x1, y1,
-                                                           x2, y2,
-						           tex_coords,
-                                                           4 * rect_entry->pipeline->n_layers);
-
-            _cairo_cogl_unbounded_render (surface,
-                                          &clip_stack_depth,
-                                          rect_entry->pipeline,
-                                          &needs_vertex_render);
-            if (needs_vertex_render) {
-                unbounded_pipeline =
-                    _cairo_cogl_setup_unbounded_area_pipeline (surface,
-                                                               rect_entry->pipeline->op);
-                cogl_framebuffer_draw_multitextured_rectangle (surface->framebuffer,
-                                                               unbounded_pipeline,
-                                                               x1, y1,
-                                                               x2, y2,
-						               tex_coords,
-                                                               4 * rect_entry->pipeline->n_layers);
-                cogl_object_unref (unbounded_pipeline);
-            }
-            _cairo_cogl_post_unbounded_render (surface,
-                                               &clip_stack_depth,
-                                               rect_entry->pipeline);
-
-	    cogl_framebuffer_pop_matrix (surface->framebuffer);
-	    break;
-	}
-	case CAIRO_COGL_JOURNAL_ENTRY_TYPE_PRIMITIVE: {
-	    cairo_cogl_journal_prim_entry_t *prim_entry =
-		(cairo_cogl_journal_prim_entry_t *)entry;
-	    CoglMatrix transform;
-            cairo_bool_t needs_vertex_render;
-            CoglPipeline *unbounded_pipeline;
-
-            _cairo_cogl_apply_tex_clips (surface,
-                                         &clip_stack_depth,
-                                         prim_entry->pipeline);
-
-	    cogl_framebuffer_push_matrix (surface->framebuffer);
-            cairo_matrix_t *ctm = &prim_entry->transform;
-            float ctmfv[16] = {
-                ctm->xx, ctm->yx, 0, 0,
-                ctm->xy, ctm->yy, 0, 0,
-                0,       0,       1, 0,
-                ctm->x0, ctm->y0, 0, 1
-            };
-            cogl_matrix_init_from_array (&transform, ctmfv);
-            cogl_framebuffer_transform (surface->framebuffer, &transform);
-
-            /* If the primitive is NULL, it means we just draw the
-             * unbounded rectangle */
-            if (prim_entry->primitive)
-	        cogl_primitive_draw (prim_entry->primitive,
-                                     surface->framebuffer,
-                                     prim_entry->pipeline->pipeline);
-
-            _cairo_cogl_unbounded_render (surface,
-                                          &clip_stack_depth,
-                                          prim_entry->pipeline,
-                                          &needs_vertex_render);
-            if (needs_vertex_render && prim_entry->primitive) {
-                unbounded_pipeline =
-                    _cairo_cogl_setup_unbounded_area_pipeline (surface,
-                                                               prim_entry->pipeline->op);
-                cogl_primitive_draw (prim_entry->primitive,
-                                     surface->framebuffer,
-                                     unbounded_pipeline);
-                cogl_object_unref (unbounded_pipeline);
-            }
-            _cairo_cogl_post_unbounded_render (surface,
-                                               &clip_stack_depth,
-                                               prim_entry->pipeline);
-
-	    cogl_framebuffer_pop_matrix (surface->framebuffer);
-	    break;
-	}
-	default:
-	    assert (0); /* not reached! */
-	}
-    }
-
-    cogl_framebuffer_pop_matrix (surface->framebuffer);
-
-    for (i = 0; i < clip_stack_depth; i++)
-	cogl_framebuffer_pop_clip (surface->framebuffer);
-
-    _cairo_cogl_journal_discard (surface);
-}
-
-static cairo_status_t
-_cairo_cogl_surface_flush (void    *abstract_surface,
-			   unsigned flags)
-{
-    cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface;
-
-    if (flags)
-	return CAIRO_STATUS_SUCCESS;
-
-    _cairo_cogl_journal_flush (surface);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_cairo_cogl_surface_finish (void *abstract_surface)
-{
-    cairo_cogl_surface_t *surface = abstract_surface;
-
-    if (surface->texture)
-	cogl_object_unref (surface->texture);
-
-    if (surface->framebuffer)
-	cogl_object_unref (surface->framebuffer);
-
-    if (surface->journal)
-	_cairo_cogl_journal_free (surface);
-
-    /*XXX wtf */
-    cairo_device_release (surface->base.device);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static CoglTextureComponents
-get_components_from_cairo_content (cairo_content_t content)
-{
-    /* We use RGBA for color-only surfaces due to the fact that cogl
-     * does not provide a padded XRGB format, thereby making us use
-     * RGBA formats to represent e.g. CAIRO_FORMAT_RGB24 and doing very
-     * expensive format conversions on the cpu when images are read
-     * back */
-    return (content & CAIRO_CONTENT_COLOR) ?
-           COGL_TEXTURE_COMPONENTS_RGBA :
-           COGL_TEXTURE_COMPONENTS_A;
-}
-
-static CoglPixelFormat
-get_default_cogl_format_from_components (CoglTextureComponents components)
-{
-    switch (components)
-    {
-    case COGL_TEXTURE_COMPONENTS_A:
-        return COGL_PIXEL_FORMAT_A_8;
-    case COGL_TEXTURE_COMPONENTS_RG:
-        return COGL_PIXEL_FORMAT_RG_88;
-    case COGL_TEXTURE_COMPONENTS_RGB:
-    case COGL_TEXTURE_COMPONENTS_RGBA:
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-	return COGL_PIXEL_FORMAT_BGRA_8888_PRE;
-#else
-	return COGL_PIXEL_FORMAT_ARGB_8888_PRE;
-#endif
-    case COGL_TEXTURE_COMPONENTS_DEPTH:
-        return COGL_PIXEL_FORMAT_DEPTH_32;
-    default:
-        return 0;
-    }
-}
-
-static CoglTextureComponents
-get_components_from_cairo_format (cairo_format_t format)
-{
-    switch (format)
-    {
-    case CAIRO_FORMAT_A1:
-    case CAIRO_FORMAT_A8:
-        return COGL_TEXTURE_COMPONENTS_A;
-
-    case CAIRO_FORMAT_RGB16_565:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_RGB30:
-    case CAIRO_FORMAT_RGB96F:
-        return COGL_TEXTURE_COMPONENTS_RGB;
-
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGBA128F:
-        return COGL_TEXTURE_COMPONENTS_RGBA;
-
-    case CAIRO_FORMAT_INVALID:
-    default:
-        g_warning("Cairo format unrepresentable by cogl");
-        return 0;
-    }
-}
-
-static CoglPixelFormat
-get_cogl_format_from_cairo_format (cairo_format_t cairo_format);
-
-/* XXX: We often use RGBA format for onscreen framebuffers so make sure
- * to handle CAIRO_FORMAT_INVALID sensibly */
-static cairo_format_t
-get_cairo_format_from_cogl_format (CoglPixelFormat format)
-{
-    switch ((int)format)
-    {
-    case COGL_PIXEL_FORMAT_A_8:
-	return CAIRO_FORMAT_A8;
-    case COGL_PIXEL_FORMAT_RGB_565:
-	return CAIRO_FORMAT_RGB16_565;
-    case COGL_PIXEL_FORMAT_RG_88:
-        g_warning ("cairo cannot handle red-green textures");
-        return CAIRO_FORMAT_INVALID;
-    case COGL_PIXEL_FORMAT_DEPTH_32:
-        g_warning ("cairo cannot handle depth textures");
-        return CAIRO_FORMAT_INVALID;
-    
-    case COGL_PIXEL_FORMAT_BGRA_8888_PRE:
-    case COGL_PIXEL_FORMAT_ARGB_8888_PRE:
-    case COGL_PIXEL_FORMAT_RGBA_8888_PRE:
-	/* Note: this is ambiguous since CAIRO_FORMAT_RGB24
-	 * would also map to the same CoglPixelFormat */
-	return CAIRO_FORMAT_ARGB32;
-
-    default:
-	g_warning("bad format: %x a? %d, bgr? %d, pre %d, format: %d",
-		  format,
-		  format & COGL_A_BIT,
-		  format & COGL_BGR_BIT,
-		  format & COGL_PREMULT_BIT,
-		  format & ~(COGL_A_BIT | COGL_BGR_BIT | COGL_PREMULT_BIT));
-	return CAIRO_FORMAT_INVALID;
-    }
-}
-
-static CoglPixelFormat
-get_cogl_format_from_cairo_format (cairo_format_t cairo_format)
-{
-    switch (cairo_format)
-    {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB24:
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-	return COGL_PIXEL_FORMAT_BGRA_8888_PRE;
-#else
-	return COGL_PIXEL_FORMAT_ARGB_8888_PRE;
-#endif
-    case CAIRO_FORMAT_A8:
-	return COGL_PIXEL_FORMAT_A_8;
-    case CAIRO_FORMAT_RGB16_565:
-	return COGL_PIXEL_FORMAT_RGB_565;
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-    case CAIRO_FORMAT_RGB30:
-    case CAIRO_FORMAT_RGB96F:
-    case CAIRO_FORMAT_RGBA128F:
-	return 0;
-    }
-
-    g_warn_if_reached ();
-    return 0;
-}
-
-static cairo_surface_t *
-_cairo_cogl_surface_create_similar (void            *abstract_surface,
-				    cairo_content_t  content,
-				    int              width,
-				    int              height)
-{
-    cairo_cogl_surface_t *reference_surface = abstract_surface;
-    cairo_cogl_surface_t *surface;
-    CoglTexture *texture;
-    cairo_status_t status;
-    cairo_cogl_device_t *dev =
-        to_device(reference_surface->base.device);
-    int tex_width = width;
-    int tex_height = height;
-
-    /* In the case of lack of NPOT texture support, we allocate texture
-     * with dimensions of the next power of two */
-    if (!dev->has_npots) {
-        tex_width = pow (2, ceil (log2 (tex_width)));
-        tex_height = pow (2, ceil (log2 (tex_height)));
-    }
-
-    texture = cogl_texture_2d_new_with_size (dev->cogl_context,
-                                             tex_width, tex_height);
-    if (!texture)
-        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    cogl_texture_set_components (texture,
-        get_components_from_cairo_content (content));
-
-    surface = (cairo_cogl_surface_t *)
-	_cairo_cogl_surface_create_full (dev, content, NULL, texture);
-    if (unlikely (surface->base.status))
-	return &surface->base;
-
-    /* The surface will take a reference on the texture */
-    cogl_object_unref (texture);
-
-    /* If we passed a texture with larger dimensions, we need to set
-     * the surface dimensions */
-    surface->width = width;
-    surface->height = height;
-
-    status = _cairo_cogl_surface_ensure_framebuffer (surface);
-    if (unlikely (status)) {
-	cairo_surface_destroy (&surface->base);
-	return _cairo_surface_create_in_error (status);
-    }
-
-    return &surface->base;
-}
-
-static cairo_status_t
-_cairo_cogl_surface_read_rect_to_image_surface (cairo_cogl_surface_t   *surface,
-						cairo_rectangle_int_t  *interest,
-						cairo_image_surface_t **image_out)
-{
-    cairo_image_surface_t *image;
-    cairo_status_t status;
-    cairo_format_t cairo_format;
-    CoglPixelFormat cogl_format;
-
-    status = _cairo_cogl_surface_ensure_framebuffer (surface);
-    if (unlikely (status))
-	return status;
-
-    if (surface->texture)
-    {
-        cogl_format =
-            get_default_cogl_format_from_components (
-                cogl_texture_get_components (surface->texture) );
-        cairo_format = get_cairo_format_from_cogl_format (cogl_format);
-    } else {
-        cairo_format =
-            _cairo_format_from_content (surface->base.content);
-        cogl_format = get_cogl_format_from_cairo_format (cairo_format);
-    }
-
-    image = (cairo_image_surface_t *)
-        cairo_image_surface_create (cairo_format,
-                                    surface->width,
-                                    surface->height);
-    if (image->base.status)
-        return image->base.status;
-
-    cogl_framebuffer_read_pixels (surface->framebuffer, 0, 0,
-                                  surface->width, surface->height,
-                                  cogl_format, image->data);
-
-    *image_out = image;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_cairo_cogl_surface_acquire_source_image (void		         *abstract_surface,
-					  cairo_image_surface_t **image_out,
-					  void		        **image_extra)
-{
-    cairo_cogl_surface_t *surface = abstract_surface;
-    cairo_status_t status;
-
-    if (unlikely (_cairo_surface_flush (abstract_surface, 0)))
-        g_warning ("Error flushing journal while acquiring image");
-
-    if (surface->texture) {
-        CoglTextureComponents components =
-            cogl_texture_get_components(surface->texture);
-        CoglPixelFormat cogl_format =
-            get_default_cogl_format_from_components (components);
-        cairo_format_t cairo_format =
-            get_cairo_format_from_cogl_format (cogl_format);
-        if (cairo_format == CAIRO_FORMAT_INVALID) {
-            cairo_format = CAIRO_FORMAT_ARGB32;
-            cogl_format =
-                get_cogl_format_from_cairo_format (cairo_format);
-        }
-
-        /* We use the actual texture dimensions here instead, because
-         * if we have a larger texture than the surface dimensions for
-         * devices not supporting NPOT textures, the surface dimensions
-         * will not be able to fit the data */
-        cairo_image_surface_t *image = (cairo_image_surface_t *)
-	        cairo_image_surface_create (cairo_format,
-	                                    cogl_texture_get_width (surface->texture),
-	                                    cogl_texture_get_height (surface->texture));
-        if (image->base.status)
-            return image->base.status;
-
-        cogl_texture_get_data (surface->texture,
-                               cogl_format,
-                               0,
-                               image->data);
-
-        /* If the texture dimensions were different than the surface
-         * dimensions, this will set them to the correct values.
-         * Because the stride stays the same, it will still function
-         * correctly */
-        image->width = surface->width;
-        image->height = surface->height;
-
-	image->base.is_clear = FALSE;
-	*image_out = image;
-    } else {
-	cairo_rectangle_int_t extents = {
-	    0, 0, surface->width, surface->height
-	};
-	status = _cairo_cogl_surface_read_rect_to_image_surface (surface, &extents,
-								 image_out);
-	if (unlikely (status))
-	    return status;
-    }
-
-    *image_extra = NULL;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-_cairo_cogl_surface_release_source_image (void			*abstract_surface,
-					  cairo_image_surface_t *image,
-					  void			*image_extra)
-{
-    cairo_surface_destroy (&image->base);
-}
-
-static cairo_status_t
-_cairo_cogl_surface_clear (cairo_cogl_surface_t *surface,
-			   const cairo_color_t  *color)
-{
-    /* Anything batched in the journal up until now is redundant... */
-    _cairo_cogl_journal_discard (surface);
-
-    /* XXX: we currently implicitly clear the depth and stencil buffer here
-     * but since we use the framebuffer_discard extension when available I
-     * suppose this doesn't matter too much.
-     *
-     * The main concern is that we want to avoid re-loading an external z
-     * buffer at the start of each frame, but also many gpu architectures have
-     * optimizations for how they handle the depth/stencil buffers and can get
-     * upset if they aren't cleared together at the start of the frame.
-     *
-     * FIXME: we need a way to assert that the clip stack currently isn't
-     * using the stencil buffer before clearing it here!
-     */
-    cogl_framebuffer_clear4f (surface->framebuffer,
-			      COGL_BUFFER_BIT_COLOR |
-			      COGL_BUFFER_BIT_DEPTH |
-			      COGL_BUFFER_BIT_STENCIL,
-			      color->red * color->alpha,
-			      color->green * color->alpha,
-			      color->blue * color->alpha,
-			      color->alpha);
-    return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
-_cairo_cogl_path_fixed_rectangle (cairo_path_fixed_t *path,
-				  cairo_fixed_t x,
-				  cairo_fixed_t y,
-				  cairo_fixed_t width,
-				  cairo_fixed_t height)
-{
-    cairo_status_t status;
-
-    status = _cairo_path_fixed_move_to (path, x, y);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_rel_line_to (path, width, 0);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_rel_line_to (path, 0, height);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_rel_line_to (path, -width, 0);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_path_fixed_close_path (path);
-    if (unlikely (status))
-	return status;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-
-static CoglPipelineWrapMode
-get_cogl_wrap_mode_for_extend (cairo_extend_t       extend_mode,
-                               cairo_cogl_device_t *dev)
-{
-    switch (extend_mode)
-    {
-    case CAIRO_EXTEND_NONE:
-	return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
-    case CAIRO_EXTEND_PAD:
-	return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
-    case CAIRO_EXTEND_REPEAT:
-	return COGL_PIPELINE_WRAP_MODE_REPEAT;
-    case CAIRO_EXTEND_REFLECT:
-        if (!dev->has_mirrored_repeat)
-            /* If the hardware cannot support mirrored repeating, we
-             * emulate it elsewhere */
-            return COGL_PIPELINE_WRAP_MODE_REPEAT;
-        else
-	    return COGL_PIPELINE_WRAP_MODE_MIRRORED_REPEAT;
-    }
-    assert (0); /* not reached */
-    return COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
-}
-
-static CoglPipelineFilter
-get_cogl_filter_for_filter (cairo_filter_t filter)
-{
-    switch (filter)
-    {
-    case CAIRO_FILTER_FAST:
-    case CAIRO_FILTER_NEAREST:
-        return COGL_PIPELINE_FILTER_NEAREST;
-
-    case CAIRO_FILTER_GOOD:
-    case CAIRO_FILTER_BEST:
-    case CAIRO_FILTER_BILINEAR:
-        return COGL_PIPELINE_FILTER_LINEAR;
-
-    case CAIRO_FILTER_GAUSSIAN:
-    default:
-        g_warning("Invalid pattern filter");
-        return COGL_PIPELINE_FILTER_NEAREST;
-    }
-}
-
-static void
-_cairo_cogl_matrix_all_scale (cairo_matrix_t *matrix,
-                              double          xscale,
-                              double          yscale)
-{
-    /* Since cairo_matrix_scale does not scale the x0 and y0 components,
-     * which is required for scaling translations to normalized
-     * coordinates, use a custom solution here. */
-    matrix->xx *= xscale;
-    matrix->yx *= yscale;
-    matrix->xy *= xscale;
-    matrix->yy *= yscale;
-    matrix->x0 *= xscale;
-    matrix->y0 *= yscale;
-}
-
-static CoglTexture *
-_cairo_cogl_scale_texture (CoglContext           *context,
-                           CoglTexture           *texture_in,
-                           unsigned int           new_width,
-                           unsigned int           new_height,
-                           cairo_bool_t           do_mirror_texture,
-                           cairo_bool_t           always_new_texture)
-{
-    CoglTexture *texture_out = NULL;
-    CoglPipeline *copying_pipeline = NULL;
-    CoglFramebuffer *fb = NULL;
-    CoglError *error = NULL;
-    unsigned int tex_width = new_width;
-    unsigned int tex_height = new_height;
-
-    /* If the texture is already in the desired dimensions and we are
-     * not mirroring it, copying it, or reading from different extents,
-     * return it unmodified */
-    if (!do_mirror_texture && !always_new_texture &&
-        new_width == cogl_texture_get_width (texture_in) &&
-        new_height == cogl_texture_get_height (texture_in))
-        return texture_in;
-
-    if (do_mirror_texture) {
-        tex_width *= 2;
-        tex_height *= 2;
-    }
-
-    texture_out =
-        cogl_texture_2d_new_with_size (context, tex_width, tex_height);
-    if (unlikely (!texture_out)) {
-        g_warning ("Failed to get texture for scaling");
-        goto BAIL;
-    }
-
-    cogl_texture_set_components (texture_out,
-        cogl_texture_get_components (texture_in));
-
-    fb = cogl_offscreen_new_with_texture (texture_out);
-    if (unlikely (!cogl_framebuffer_allocate (fb, &error))) {
-        g_warning ("Could not get framebuffer for texture scaling: %s",
-                   error->message);
-        cogl_error_free (error);
-        goto BAIL;
-    }
-
-    cogl_framebuffer_orthographic (fb, 0, 0,
-                                       tex_width, tex_height,
-                                       -1, 100);
-
-    copying_pipeline = cogl_pipeline_new (context);
-    cogl_pipeline_set_layer_texture (copying_pipeline, 0, texture_in);
-    cogl_pipeline_set_layer_filters (copying_pipeline, 0,
-                                     COGL_PIPELINE_FILTER_NEAREST,
-                                     COGL_PIPELINE_FILTER_NEAREST);
-
-    if (do_mirror_texture) {
-        /* Draw four rectangles to the new texture with the appropriate
-         * reflection on each one */
-
-        const float rect_coordinates[32] = {
-            /* Rectangle 1 */
-            0, 0, 0.5 * tex_width, 0.5 * tex_height,
-            0, 0, 1, 1,
-
-            /* Rectangle 2 */
-            tex_width, 0, 0.5 * tex_width, 0.5 * tex_height,
-            0, 0, 1, 1,
-
-            /* Rectangle 3 */
-            0, tex_height, 0.5 * tex_width, 0.5 * tex_height,
-            0, 0, 1, 1,
-
-            /* Rectangle 4 */
-            tex_width, tex_height, 0.5 * tex_width, 0.5 * tex_height,
-            0, 0, 1, 1
-        };
-
-        cogl_framebuffer_draw_textured_rectangles (fb,
-                                                   copying_pipeline,
-                                                   rect_coordinates,
-                                                   4);
-    } else {
-        cogl_framebuffer_draw_textured_rectangle (fb,
-                                                  copying_pipeline,
-                                                  0, 0,
-                                                  tex_width,
-                                                  tex_height,
-                                                  0, 0, 1, 1);
-    }
-
-    cogl_object_unref (fb);
-    cogl_object_unref (copying_pipeline);
-    cogl_object_unref (texture_in);
-
-    return texture_out;
-
-BAIL:
-    if (texture_out)
-        cogl_object_unref (texture_out);
-    if (fb)
-        cogl_object_unref (fb);
-    if (copying_pipeline)
-        cogl_object_unref (copying_pipeline);
-
-    return NULL;
-}
-
-/* NB: a reference for the texture is transferred to the caller which
- * should be unrefed */
-static CoglTexture *
-_cairo_cogl_acquire_cogl_surface_texture (cairo_cogl_surface_t        *reference_surface,
-                                          cairo_surface_t             *surface,
-                                          const cairo_rectangle_int_t *surface_extents,
-                                          const cairo_matrix_t        *pattern_matrix,
-                                          cairo_matrix_t              *out_matrix,
-                                          const cairo_bool_t           need_mirrored_texture,
-                                          cairo_bool_t                *is_mirrored_texture)
-{
-    CoglTexture *texture;
-    cairo_surface_t *clone = NULL;
-    cairo_cogl_surface_t *cogl_surface =
-        (cairo_cogl_surface_t *)surface;
-    cairo_bool_t do_mirror_texture;
-    cairo_cogl_device_t *dev =
-        to_device (reference_surface->base.device);
-    double xscale, yscale;
-    int new_width = surface_extents->width;
-    int new_height = surface_extents->height;
-
-    if (surface_extents->x < 0 || surface_extents->y < 0 ||
-        (surface_extents->x + surface_extents->width) >
-            cogl_surface->width ||
-        (surface_extents->y + surface_extents->height) >
-            cogl_surface->height)
-        return NULL;
-
-    *out_matrix = *pattern_matrix;
-    *is_mirrored_texture = FALSE;
-
-    if (unlikely (_cairo_surface_flush (surface, 0))) {
-        g_warning ("Error flushing source surface while getting "
-                   "pattern texture");
-        goto BAIL;
-    }
-
-    *is_mirrored_texture =
-        need_mirrored_texture || cogl_surface->is_mirrored_snapshot;
-    do_mirror_texture =
-        need_mirrored_texture && !cogl_surface->is_mirrored_snapshot;
-
-    /* There seems to be a bug in which cogl isn't flushing its own
-     * internal journal when reading from dependent sub-textures.
-     * If this is ever fixed, the following block of code can be
-     * removed. */
-    {
-        _cairo_cogl_surface_ensure_framebuffer (cogl_surface);
-        cogl_framebuffer_finish (cogl_surface->framebuffer);
-    }
-    /* We copy the surface to a new texture, thereby making a
-     * snapshot of it, as its contents may change between the time
-     * we log the pipeline and when we flush the journal. The sub
-     * texture itself cannot be used while drawing primitives, so we do
-     * a copy to a 2d texture. */
-    texture = cogl_sub_texture_new (dev->cogl_context,
-                                    cogl_surface->texture,
-                                    surface_extents->x,
-                                    surface_extents->y,
-                                    surface_extents->width,
-                                    surface_extents->height);
-    if (unlikely (!texture))
-        goto BAIL;
-
-    /* If we do not support NPOT dimensions, scale the new texture to
-     * the next power of two while copying */
-    if (!dev->has_npots) {
-        new_width = (int)pow (2, ceil (log2 (new_width)));
-        new_height = (int)pow (2, ceil (log2 (new_height)));
-    }
-    texture = _cairo_cogl_scale_texture (dev->cogl_context,
-                                         texture,
-                                         new_width,
-                                         new_height,
-                                         do_mirror_texture,
-                                         TRUE);
-    if (unlikely (!texture))
-        goto BAIL;
-
-    clone =
-        _cairo_cogl_surface_create_full (dev,
-                                         reference_surface->base.content,
-                                         NULL,
-                                         texture);
-    if (unlikely (clone->status)) {
-        g_warning ("Could not get clone surface for texture");
-        goto BAIL;
-    }
-    _cairo_surface_attach_snapshot (surface, clone, NULL);
-
-    /* Attaching the snapshot will take a reference on the clone surface... */
-    cairo_surface_destroy (clone);
-    clone = NULL;
-
-    /* Convert from un-normalized source coordinates in backend
-     * coordinates to normalized texture coordinates. */
-    if (*is_mirrored_texture) {
-        xscale = 0.5 / surface_extents->width;
-        yscale = 0.5 / surface_extents->height;
-    } else {
-        xscale = 1.0 / surface_extents->width;
-        yscale = 1.0 / surface_extents->height;
-    }
-    _cairo_cogl_matrix_all_scale (out_matrix, xscale, yscale);
-
-    return texture;
-
-BAIL:
-    if (texture)
-        cogl_object_unref (texture);
-    if (clone)
-        cairo_surface_destroy (clone);
-
-    return NULL;
-}
-
-/* NB: a reference for the texture is transferred to the caller which
- * should be unrefed */
-static CoglTexture *
-_cairo_cogl_acquire_recording_surface_texture (cairo_cogl_surface_t        *reference_surface,
-                                               cairo_surface_t             *surface,
-                                               const cairo_rectangle_int_t *extents,
-                                               const cairo_matrix_t        *pattern_matrix,
-                                               cairo_matrix_t              *out_matrix,
-                                               const cairo_bool_t           need_mirrored_texture,
-                                               cairo_bool_t                *is_mirrored_texture)
-{
-    CoglTexture *texture = NULL;
-    cairo_surface_t *clone = NULL;
-    cairo_cogl_device_t *dev =
-        to_device (reference_surface->base.device);
-    cairo_matrix_t transform;
-    int tex_height, tex_width;
-    double xscale, yscale;
-
-    *is_mirrored_texture = FALSE;
-
-    /* We will pre-transform all of the drawing by the pattern matrix
-     * and confine it to the required extents, so no later transform
-     * will be required */
-    cairo_matrix_init_translate (out_matrix, -extents->x, -extents->y);
-
-    cairo_matrix_init_translate (&transform, extents->x, extents->y);
-    cairo_matrix_multiply (&transform, &transform, pattern_matrix);
-
-    if (!dev->has_npots) {
-        /* Record to a texture sized to the next power of two */
-        tex_width = (int)pow (2, ceil (log2 (extents->width)));
-        tex_height = (int)pow (2, ceil (log2 (extents->height)));
-
-        /* And scale accordingly */
-        cairo_matrix_scale (&transform,
-                            (double)extents->width / (double)tex_width,
-                            (double)extents->height / (double)tex_height);
-    } else {
-        tex_width = extents->width;
-        tex_height = extents->height;
-    }
-
-    texture = cogl_texture_2d_new_with_size (dev->cogl_context,
-                                             tex_width,
-                                             tex_height);
-    if (unlikely (!texture)) {
-        g_warning ("Failed to create texture for replaying recording "
-                   "surface");
-        goto BAIL;
-    }
-
-    cogl_texture_set_components (texture,
-        get_components_from_cairo_content (surface->content));
-
-    /* Do not attach this as a snapshot, as it only represents part of
-     * the surface */
-    clone =
-        _cairo_cogl_surface_create_full (dev,
-                                         reference_surface->base.content,
-                                         NULL,
-                                         texture);
-    if (unlikely (_cairo_cogl_surface_ensure_framebuffer ((cairo_cogl_surface_t *)clone)))
-    {
-        g_warning ("Could not get framebuffer for replaying recording "
-                   "surface");
-        goto BAIL;
-    }
-
-    if (unlikely (_cairo_recording_surface_replay_with_clip (surface,
-                                                             &transform,
-                                                             clone,
-                                                             NULL)))
-    {
-        g_warning ("Could not replay recording surface");
-        goto BAIL;
-    }
-    _cairo_cogl_journal_flush ((cairo_cogl_surface_t *)clone);
-    cairo_surface_destroy (clone);
-
-    if (need_mirrored_texture) {
-        /* Scale to the same image extents, but mirror the texture,
-         * thereby making it larger */
-        texture = _cairo_cogl_scale_texture (dev->cogl_context,
-                                             texture,
-                                             tex_width,
-                                             tex_height,
-                                             TRUE,
-                                             FALSE);
-        if (unlikely (!texture))
-            goto BAIL;
-
-        *is_mirrored_texture = TRUE;
-    }
-
-    /* Convert from un-normalized source coordinates in backend
-     * coordinates to normalized texture coordinates. */
-    if (*is_mirrored_texture) {
-        xscale = 0.5 / extents->width;
-        yscale = 0.5 / extents->height;
-    } else {
-        xscale = 1.0 / extents->width;
-        yscale = 1.0 / extents->height;
-    }
-    _cairo_cogl_matrix_all_scale (out_matrix, xscale, yscale);
-
-    return texture;
-
-BAIL:
-    if (clone)
-        cairo_surface_destroy (clone);
-    if (texture)
-        cogl_object_unref (texture);
-
-    return NULL;
-}
-
-/* NB: a reference for the texture is transferred to the caller which
- * should be unrefed */
-static CoglTexture *
-_cairo_cogl_acquire_generic_surface_texture (cairo_cogl_surface_t *reference_surface,
-                                             cairo_surface_t      *surface,
-                                             const cairo_matrix_t *pattern_matrix,
-                                             cairo_matrix_t       *out_matrix,
-                                             const cairo_bool_t    need_mirrored_texture,
-                                             cairo_bool_t         *is_mirrored_texture)
-{
-    CoglTexture *texture = NULL;
-    cairo_image_surface_t *image;
-    cairo_image_surface_t *acquired_image = NULL;
-    void *image_extra;
-    cairo_image_surface_t *image_clone = NULL;
-    CoglBitmap *bitmap;
-    CoglError *error = NULL;
-    cairo_surface_t *clone = NULL;
-    CoglPixelFormat format;
-    cairo_cogl_device_t *dev =
-        to_device (reference_surface->base.device);
-    ptrdiff_t stride;
-    unsigned char *data;
-    double xscale, yscale;
-
-    *out_matrix = *pattern_matrix;
-    *is_mirrored_texture = FALSE;
-
-    if (_cairo_surface_is_image (surface)) {
-        image = (cairo_image_surface_t *)surface;
-    } else {
-        cairo_status_t status =
-            _cairo_surface_acquire_source_image (surface,
-                                                 &acquired_image,
-                                                 &image_extra);
-        if (unlikely (status)) {
-            g_warning ("acquire_source_image failed: %s [%d]",
-                        cairo_status_to_string (status), status);
-            return NULL;
-        }
-        image = acquired_image;
-    }
-
-    format = get_cogl_format_from_cairo_format (image->format);
-    if (!format) {
-        image_clone = _cairo_image_surface_coerce (image);
-        if (unlikely (image_clone->base.status)) {
-            g_warning ("image_surface_coerce failed");
-            texture = NULL;
-            goto BAIL;
-        }
-
-        format =
-            get_cogl_format_from_cairo_format (image_clone->format);
-        assert (format);
-
-        image = image_clone;
-    }
-
-    if (image->stride < 0) {
-        /* If the stride is negative, this modifies the data pointer so
-         * that all of the pixels are read into the texture, but
-         * upside-down. We then invert the matrix so the texture is
-         * read from the bottom up instead of from the top down. */
-        stride = -image->stride;
-        data = image->data - stride * (image->height - 1);
-
-        out_matrix->yx *= -1.0;
-        out_matrix->yy *= -1.0;
-        out_matrix->y0 += image->height;
-    } else {
-        stride = image->stride;
-        data = image->data;
-    }
-
-    bitmap = cogl_bitmap_new_for_data (dev->cogl_context,
-                                       image->width,
-                                       image->height,
-                                       format, /* incoming */
-                                       stride,
-                                       data);
-
-    if (!dev->has_npots)
-        texture =
-            cogl_texture_2d_sliced_new_from_bitmap (bitmap,
-                                                    COGL_TEXTURE_MAX_WASTE);
-    else
-        texture = cogl_texture_2d_new_from_bitmap (bitmap);
-
-    /* The texture will have taken a reference on the bitmap */
-    cogl_object_unref (bitmap);
-
-    cogl_texture_set_components (texture,
-        get_components_from_cairo_format (image->format));
-
-    if (unlikely (!cogl_texture_allocate (texture, &error))) {
-        g_warning ("Failed to allocate texture: %s", error->message);
-        cogl_error_free (error);
-        goto BAIL;
-    }
-
-    if (need_mirrored_texture) {
-        int new_width = image->width;
-        int new_height = image->height;
-
-        /* If the device does not support npot textures, scale to the
-         * next power of two as well */
-        if (!dev->has_npots) {
-            new_width = (int)pow (2, ceil (log2 (new_width)));
-            new_height = (int)pow (2, ceil (log2 (new_height)));
-        }
-
-        texture = _cairo_cogl_scale_texture (dev->cogl_context,
-                                             texture,
-                                             new_width,
-                                             new_height,
-                                             TRUE,
-                                             FALSE);
-        if (unlikely (!texture))
-            goto BAIL;
-
-        *is_mirrored_texture = TRUE;
-    } else if (!dev->has_npots) {
-        /* We need to scale the texture up if the hardware does not
-         * support npots */
-
-        /* Get dimensions for the next power of two */
-        int new_width = (int)pow (2, ceil (log2 (image->width)));
-        int new_height = (int)pow (2, ceil (log2 (image->height)));
-
-        texture = _cairo_cogl_scale_texture (dev->cogl_context,
-                                             texture,
-                                             new_width,
-                                             new_height,
-                                             FALSE,
-                                             FALSE);
-        if (unlikely (!texture))
-            goto BAIL;
-    }
-
-    clone =
-        _cairo_cogl_surface_create_full (dev,
-                                         reference_surface->base.content,
-                                         NULL,
-                                         texture);
-    if (unlikely (clone->status)) {
-        g_warning ("Unable to create clone surface for texture");
-        goto BAIL;
-    }
-
-    if (*is_mirrored_texture)
-        ((cairo_cogl_surface_t *)clone)->is_mirrored_snapshot = TRUE;
-
-    if (_cairo_surface_is_subsurface (surface))
-        _cairo_surface_subsurface_set_snapshot (surface, clone);
-    else
-        _cairo_surface_attach_snapshot (surface, clone, NULL);
-
-    /* Attaching the snapshot will take a reference on the clone surface... */
-    cairo_surface_destroy (clone);
-    clone = NULL;
-
-    /* Convert from un-normalized source coordinates in backend
-     * coordinates to normalized texture coordinates. */
-    if (*is_mirrored_texture) {
-        xscale = 0.5 / image->width;
-        yscale = 0.5 / image->height;
-    } else {
-        xscale = 1.0 / image->width;
-        yscale = 1.0 / image->height;
-    }
-    _cairo_cogl_matrix_all_scale (out_matrix, xscale, yscale);
-
-    /* Release intermediate surface representations */
-    if (image_clone) {
-	cairo_surface_destroy (&image_clone->base);
-        image_clone = NULL;
-    }
-    if (acquired_image) {
-	_cairo_surface_release_source_image (surface,
-                                             acquired_image,
-                                             image_extra);
-        acquired_image = NULL;
-    }
-
-    return texture;
-
-BAIL:
-    if (clone)
-        cairo_surface_destroy (clone);
-    if (image_clone)
-	cairo_surface_destroy (&image_clone->base);
-    if (acquired_image)
-	_cairo_surface_release_source_image (surface,
-                                             acquired_image,
-                                             image_extra);
-    if (texture)
-        cogl_object_unref (texture);
-
-    return NULL;
-}
-
-static cairo_status_t
-_cairo_cogl_create_tex_clip (cairo_path_fixed_t *tex_clip,
-                             cairo_matrix_t      inverse,
-                             cairo_bool_t        is_mirrored_texture)
-{
-    cairo_status_t status;
-
-    status = cairo_matrix_invert (&inverse);
-    if (unlikely (status))
-        return status;
-
-    if (is_mirrored_texture)
-        status =
-            _cairo_cogl_path_fixed_rectangle (tex_clip, 0, 0,
-                                              _cairo_fixed_from_double (0.5),
-                                              _cairo_fixed_from_double (0.5));
-    else
-        status = _cairo_cogl_path_fixed_rectangle (tex_clip, 0, 0,
-                                                   CAIRO_FIXED_ONE,
-                                                   CAIRO_FIXED_ONE);
-    if (unlikely (status))
-	return status;
-
-    _cairo_path_fixed_transform (tex_clip, &inverse);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-/* NB: a reference for the texture is transferred to the caller which should
- * be unrefed */
-static CoglTexture *
-_cairo_cogl_acquire_pattern_texture (const cairo_pattern_t           *pattern,
-				     cairo_cogl_surface_t            *destination,
-				     const cairo_rectangle_int_t     *extents,
-				     cairo_cogl_texture_attributes_t *attributes,
-                                     cairo_path_fixed_t              *tex_clip)
-{
-    CoglTexture *texture = NULL;
-    cairo_cogl_device_t *dev = to_device (destination->base.device);
-    cairo_bool_t is_mirrored_texture;
-    cairo_bool_t need_mirrored_texture =
-        (pattern->extend == CAIRO_EXTEND_REFLECT &&
-         !dev->has_mirrored_repeat);
-
-    switch ((int)pattern->type)
-    {
-    case CAIRO_PATTERN_TYPE_SURFACE: {
-        cairo_cogl_surface_t *clone;
-        cairo_surface_t *surface = ((cairo_surface_pattern_t *)pattern)->surface;
-
-        clone = (cairo_cogl_surface_t *)
-            _cairo_surface_has_snapshot (surface,
-                                         &_cairo_cogl_surface_backend);
-        if (clone && clone->texture)
-            if ((!need_mirrored_texture) || clone->is_mirrored_snapshot)
-            {
-                texture = cogl_object_ref (clone->texture);
-                attributes->matrix = pattern->matrix;
-                is_mirrored_texture = clone->is_mirrored_snapshot;
-
-                /* Convert from un-normalized source coordinates in
-                 * backend coordinates to normalized texture
-                 * coordinates. */
-                _cairo_cogl_matrix_all_scale (&attributes->matrix,
-                                              1.0 / clone->width,
-                                              1.0 / clone->height);
-            };
-
-        if (!texture) {
-            cairo_rectangle_int_t surface_extents;
-            cairo_surface_t *unwrapped =
-                _cairo_surface_get_source (surface, &surface_extents);
-
-            if (_cairo_surface_is_recording (surface)) {
-                texture =
-                    _cairo_cogl_acquire_recording_surface_texture (destination,
-                                                                   surface,
-                                                                   extents,
-                                                                   &pattern->matrix,
-                                                                   &attributes->matrix,
-                                                                   need_mirrored_texture,
-                                                                   &is_mirrored_texture);
-            } else if (surface->type == CAIRO_SURFACE_TYPE_COGL &&
-                       ((cairo_cogl_surface_t *)unwrapped)->texture) {
-                texture =
-                    _cairo_cogl_acquire_cogl_surface_texture (destination,
-                                                              unwrapped,
-                                                              &surface_extents,
-                                                              &pattern->matrix,
-                                                              &attributes->matrix,
-                                                              need_mirrored_texture,
-                                                              &is_mirrored_texture);
-            }
-        }
-
-        if (!texture)
-            texture =
-                _cairo_cogl_acquire_generic_surface_texture (destination,
-                                                             surface,
-                                                             &pattern->matrix,
-                                                             &attributes->matrix,
-                                                             need_mirrored_texture,
-                                                             &is_mirrored_texture);
-
-        if (unlikely (!texture))
-            return NULL;
-
-	attributes->extend = pattern->extend;
-	attributes->filter =
-            get_cogl_filter_for_filter (pattern->filter);
-	attributes->has_component_alpha = pattern->has_component_alpha;
-
-	attributes->s_wrap =
-            get_cogl_wrap_mode_for_extend (pattern->extend, dev);
-	attributes->t_wrap = attributes->s_wrap;
-
-        /* In order to support CAIRO_EXTEND_NONE, we use the same wrap
-         * mode as CAIRO_EXTEND_PAD, but pass a clip to the drawing
-         * function to make sure that we never sample anything beyond
-         * the texture boundaries. */
-        if (pattern->extend == CAIRO_EXTEND_NONE && tex_clip)
-            if (_cairo_cogl_create_tex_clip (tex_clip,
-                                             attributes->matrix,
-                                             is_mirrored_texture))
-            {
-                cogl_object_unref (texture);
-                return NULL;
-            }
-
-	return texture;
-    }
-    case CAIRO_PATTERN_TYPE_RADIAL:
-    case CAIRO_PATTERN_TYPE_MESH:
-    case CAIRO_PATTERN_TYPE_RASTER_SOURCE: {
-	cairo_surface_t *surface;
-        cairo_matrix_t new_pattern_matrix;
-
-	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-					      extents->width, extents->height);
-	if (_cairo_surface_offset_paint (surface,
-					 extents->x, extents->y,
-					 CAIRO_OPERATOR_SOURCE,
-					 pattern, NULL)) {
-	    cairo_surface_destroy (surface);
-	    return NULL;
-	}
-
-        cairo_matrix_init_translate (&new_pattern_matrix,
-                                     -extents->x, -extents->y);
-
-	texture =
-            _cairo_cogl_acquire_generic_surface_texture (destination,
-                                                         surface,
-                                                         &new_pattern_matrix,
-                                                         &attributes->matrix,
-                                                         need_mirrored_texture,
-                                                         &is_mirrored_texture);
-	if (unlikely (!texture))
-	    goto BAIL;
-
-	attributes->extend = pattern->extend;
-	attributes->filter = COGL_PIPELINE_FILTER_NEAREST;
-	attributes->has_component_alpha = pattern->has_component_alpha;
-
-	/* any pattern extend modes have already been dealt with... */
-	attributes->s_wrap = COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE;
-	attributes->t_wrap = attributes->s_wrap;
-
-        /* In order to support CAIRO_EXTEND_NONE, we use the same wrap
-         * mode as CAIRO_EXTEND_PAD, but pass a clip to the drawing
-         * function to make sure that we never sample anything beyond
-         * the texture boundaries. */
-        if (pattern->extend == CAIRO_EXTEND_NONE && tex_clip)
-            if (_cairo_cogl_create_tex_clip (tex_clip,
-                                             attributes->matrix,
-                                             is_mirrored_texture))
-            {
-                cogl_object_unref (texture);
-                cairo_surface_destroy (surface);
-                return NULL;
-            }
-
-BAIL:
-	cairo_surface_destroy (surface);
-
-	return texture;
-    }
-    case CAIRO_PATTERN_TYPE_LINEAR: {
-	cairo_linear_pattern_t *linear_pattern = (cairo_linear_pattern_t *)pattern;
-	cairo_cogl_linear_gradient_t *gradient;
-	cairo_cogl_linear_texture_entry_t *linear_texture;
-	cairo_int_status_t status;
-        double dist, scale;
-
-	status = _cairo_cogl_get_linear_gradient (to_device(destination->base.device),
-						  pattern->extend,
-						  linear_pattern->base.n_stops,
-						  linear_pattern->base.stops,
-                                                  need_mirrored_texture,
-						  &gradient);
-	if (unlikely (status))
-	    return NULL;
-
-	linear_texture = _cairo_cogl_linear_gradient_texture_for_extend (gradient, pattern->extend);
-
-	attributes->extend = pattern->extend;
-	attributes->filter =
-            get_cogl_filter_for_filter (pattern->filter);
-	attributes->has_component_alpha = pattern->has_component_alpha;
-	attributes->s_wrap =
-            get_cogl_wrap_mode_for_extend (pattern->extend, dev);
-	attributes->t_wrap = attributes->s_wrap;
-
-        attributes->matrix = pattern->matrix;
-
-	double a = linear_pattern->pd2.x - linear_pattern->pd1.x;
-	double b = linear_pattern->pd2.y - linear_pattern->pd1.y;
-	double angle = - atan2f (b, a);
-
-	cairo_matrix_rotate (&attributes->matrix, angle);
-
-	cairo_matrix_translate (&attributes->matrix,
-				-linear_pattern->pd1.x,
-				-linear_pattern->pd1.y);
-
-	/* Convert from un-normalized source coordinates in backend
-	 * coordinates to normalized texture coordinates. */
-	dist = sqrtf (a*a + b*b);
-        if (need_mirrored_texture)
-            scale = 0.5 / dist;
-        else
-	    scale = 1.0 / dist;
-        _cairo_cogl_matrix_all_scale (&attributes->matrix,
-                                      scale, scale);
-
-	return cogl_object_ref (linear_texture->texture);
-    }
-    default:
-	g_warning ("Unsupported source type");
-	return NULL;
-    }
-}
-
-static cairo_bool_t
-set_blend (CoglPipeline *pipeline, const char *blend_string)
-{
-    CoglError *error = NULL;
-    if (unlikely (!cogl_pipeline_set_blend (pipeline,
-                                            blend_string,
-                                            &error)))
-    {
-	g_warning ("Unsupported blend string with current gpu/driver: %s", blend_string);
-	cogl_error_free (error);
-	return FALSE;
-    }
-    return TRUE;
-}
-
-static cairo_bool_t
-_cairo_cogl_setup_op_state (CoglPipeline    *pipeline,
-                            cairo_operator_t op)
-{
-    cairo_bool_t status = FALSE;
-
-    switch ((int)op)
-    {
-    case CAIRO_OPERATOR_OVER:
-	status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR * (1 - SRC_COLOR[A]))");
-	break;
-    case CAIRO_OPERATOR_IN:
-	status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * DST_COLOR[A], 0)");
-	break;
-    case CAIRO_OPERATOR_OUT:
-        status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), 0)");
-        break;
-    case CAIRO_OPERATOR_ATOP:
-        status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * DST_COLOR[A], DST_COLOR * (1 - SRC_COLOR[A]))");
-        break;
-    case CAIRO_OPERATOR_DEST:
-        status = set_blend (pipeline, "RGBA = ADD (0, DST_COLOR)");
-        break;
-    case CAIRO_OPERATOR_DEST_OVER:
-	status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), DST_COLOR)");
-	break;
-    case CAIRO_OPERATOR_DEST_IN:
-	status = set_blend (pipeline, "RGBA = ADD (0, DST_COLOR * SRC_COLOR[A])");
-	break;
-    case CAIRO_OPERATOR_DEST_OUT:
-        status = set_blend (pipeline, "RGBA = ADD (0, DST_COLOR * (1 - SRC_COLOR[A]))");
-        break;
-    case CAIRO_OPERATOR_DEST_ATOP:
-        status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), DST_COLOR * SRC_COLOR[A])");
-        break;
-    case CAIRO_OPERATOR_XOR:
-        status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR * (1 - DST_COLOR[A]), DST_COLOR * (1 - SRC_COLOR[A]))");
-        break;
-    /* In order to handle SOURCE with a mask, we use two passes. The
-     * first consists of a CAIRO_OPERATOR_DEST_OUT with the source alpha
-     * replaced by the mask alpha in order to multiply all the
-     * destination values by one minus the mask alpha. The second pass
-     * (this one) then adds the source values, which have already been
-     * premultiplied by the mask alpha. */
-    case CAIRO_OPERATOR_SOURCE:
-    case CAIRO_OPERATOR_ADD:
-	status = set_blend (pipeline, "RGBA = ADD (SRC_COLOR, DST_COLOR)");
-	break;
-    case CAIRO_OPERATOR_CLEAR:
-        /* Runtime check */
-        /* CAIRO_OPERATOR_CLEAR is not supposed to use its own pipeline
-         * type. Use CAIRO_OPERATOR_DEST_OUT with the mask alpha as
-         * source alpha instead. */
-        assert (0);
-    default:
-        g_warning ("Unsupported blend operator");
-        assert (0);
-    }
-
-    return status;
-}
-
-static void
-create_template_for_op_type (cairo_cogl_device_t      *dev,
-                              cairo_operator_t         op,
-                              cairo_cogl_template_type type)
-{
-    CoglPipeline *pipeline;
-    CoglColor color;
-
-    if (dev->template_pipelines[op][type])
-        return;
-
-    cogl_color_init_from_4f (&color, 1.0f, 1.0f, 1.0f, 1.0f);
-
-    if (!dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]) {
-        CoglPipeline *base = cogl_pipeline_new (dev->cogl_context);
-
-        if (!_cairo_cogl_setup_op_state (base, op)) {
-            cogl_object_unref (base);
-            return;
-        }
-
-        dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID] = base;
-    }
-
-    switch ((int)type)
-    {
-    case CAIRO_COGL_TEMPLATE_TYPE_SOLID:
-        return;
-    case CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_SOLID:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
-        cogl_pipeline_set_layer_combine (pipeline, 0,
-                                         "RGBA = MODULATE (PRIMARY, CONSTANT[A])",
-                                         NULL);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_SOLID:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        cogl_pipeline_set_layer_combine (pipeline, 0,
-                                         "RGBA = MODULATE (PRIMARY, TEXTURE[A])",
-                                         NULL);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_TEXTURE:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_TEXTURE:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color);
-        cogl_pipeline_set_layer_combine (pipeline, 1,
-                                         "RGBA = MODULATE (PREVIOUS, CONSTANT[A])",
-                                         NULL);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_TEXTURE:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        cogl_pipeline_set_layer_null_texture (pipeline, 1,
-                                              COGL_TEXTURE_TYPE_2D);
-        cogl_pipeline_set_layer_combine (pipeline, 1,
-                                         "RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
-                                         NULL);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_IGNORE_ALPHA:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        /* We do not set the combine color when we use this template
-         * pipeline, so the source texture alpha will be replaces by
-         * ones */
-        cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
-        cogl_pipeline_set_layer_combine (pipeline, 0,
-                                         "RGB = REPLACE (TEXTURE)"
-                                         "A = REPLACE (CONSTANT)",
-                                         NULL);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_TEXTURE_IGNORE_ALPHA:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        /* We do not set the combine color when we use this template
-         * pipeline, so the source texture alpha will be replaces by
-         * ones */
-        cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
-        cogl_pipeline_set_layer_combine (pipeline, 0,
-                                         "RGB = REPLACE (TEXTURE)"
-                                         "A = REPLACE (CONSTANT)",
-                                         NULL);
-        cogl_pipeline_set_layer_combine_constant (pipeline, 1, &color);
-        cogl_pipeline_set_layer_combine (pipeline, 1,
-                                         "RGBA = MODULATE (PREVIOUS, CONSTANT[A])",
-                                         NULL);
-        break;
-    case CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_TEXTURE_IGNORE_ALPHA:
-        pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][CAIRO_COGL_TEMPLATE_TYPE_SOLID]);
-        cogl_pipeline_set_layer_null_texture (pipeline, 0,
-                                              COGL_TEXTURE_TYPE_2D);
-        /* We do not set the combine color when we use this template
-         * pipeline, so the source texture alpha will be replaces by
-         * ones */
-        cogl_pipeline_set_layer_combine_constant (pipeline, 0, &color);
-        cogl_pipeline_set_layer_combine (pipeline, 0,
-                                         "RGB = REPLACE (TEXTURE)"
-                                         "A = REPLACE (CONSTANT)",
-                                         NULL);
-        cogl_pipeline_set_layer_null_texture (pipeline, 1,
-                                              COGL_TEXTURE_TYPE_2D);
-        cogl_pipeline_set_layer_combine (pipeline, 1,
-                                         "RGBA = MODULATE (PREVIOUS, TEXTURE[A])",
-                                         NULL);
-        break;
-    default:
-        g_warning ("Invalid cogl pipeline template type");
-        return;
-    }
-
-    dev->template_pipelines[op][type] = pipeline;
-}
-
-static void
-set_layer_texture_with_attributes (CoglPipeline                    *pipeline,
-				   int                              layer_index,
-				   CoglTexture                     *texture,
-				   cairo_cogl_texture_attributes_t *attributes,
-                                   cairo_matrix_t                  *path_transform)
-{
-    cairo_matrix_t m;
-
-    cogl_pipeline_set_layer_texture (pipeline, layer_index, texture);
-
-    cogl_pipeline_set_layer_filters (pipeline,
-                                     layer_index,
-                                     attributes->filter,
-                                     attributes->filter);
-
-    /* We multiply in the path transform here so that we read texture
-     * values from coordinates that are consistent with the coordinates
-     * of the path after it is transformed by the modelview matrix */
-    if (path_transform)
-        cairo_matrix_multiply (&m, path_transform, &attributes->matrix);
-    else
-        m = attributes->matrix;
-
-    if (!_cairo_matrix_is_identity (&m)) {
-	float texture_matrixfv[16] = {
-	    m.xx, m.yx, 0, 0,
-	    m.xy, m.yy, 0, 0,
-	    0,    0,    1, 0,
-	    m.x0, m.y0, 0, 1
-	};
-	CoglMatrix texture_matrix;
-	cogl_matrix_init_from_array (&texture_matrix, texture_matrixfv);
-	cogl_pipeline_set_layer_matrix (pipeline, layer_index, &texture_matrix);
-    }
-
-    if (attributes->s_wrap != attributes->t_wrap) {
-	cogl_pipeline_set_layer_wrap_mode_s (pipeline, layer_index, attributes->s_wrap);
-	cogl_pipeline_set_layer_wrap_mode_t (pipeline, layer_index, attributes->t_wrap);
-    } else {
-	cogl_pipeline_set_layer_wrap_mode (pipeline, layer_index, attributes->s_wrap);
-    }
-}
-
-/* This takes an argument of a pointer to an array of two pointers to
- * #cairo_cogl_pipeline_t. On failure, both pointers will be set to
- * NULL */
-static void
-get_source_mask_operator_destination_pipelines (cairo_cogl_pipeline_t       **pipelines,
-                                                const cairo_pattern_t        *mask,
-					        const cairo_pattern_t        *source,
-					        cairo_operator_t              op,
-					        cairo_cogl_surface_t         *destination,
-					        cairo_composite_rectangles_t *extents,
-                                                cairo_matrix_t               *path_transform)
-{
-    cairo_cogl_template_type template_type;
-    cairo_cogl_device_t *dev = to_device(destination->base.device);
-
-    pipelines[0] = NULL;
-    pipelines[1] = NULL;
-
-    switch ((int)source->type)
-    {
-    case CAIRO_PATTERN_TYPE_SOLID:
-        if (mask) {
-            /* If the mask surface has no alpha content, we use a mask
-             * of solid ones */
-            if ((mask->type == CAIRO_PATTERN_TYPE_SOLID) ||
-                (mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
-                 ((cairo_surface_pattern_t *)mask)->surface->content == CAIRO_CONTENT_COLOR))
-                template_type =
-                    CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_SOLID;
-            else
-                template_type =
-                    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_SOLID;
-        } else {
-            template_type = CAIRO_COGL_TEMPLATE_TYPE_SOLID;
-        }
-        break;
-    case CAIRO_PATTERN_TYPE_SURFACE:
-        /* If the source does not have alpha content, we have to use
-         * a specialized set of texture combining functions in order to
-         * ensure that if we have a CAIRO_FORMAT_RGB24 source, we are
-         * ignoring the alpha and replacing it with ones. Otherwise, we
-         * use the template types for any other type of non-solid
-         * source. */
-        if (((cairo_surface_pattern_t *)source)->surface->content ==
-             CAIRO_CONTENT_COLOR)
-        {
-            if (mask) {
-                /* If the mask surface has no alpha content, we use a
-                 * mask of solid ones */
-                if ((mask->type == CAIRO_PATTERN_TYPE_SOLID) ||
-                    (mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
-                     ((cairo_surface_pattern_t *)mask)->surface->content == CAIRO_CONTENT_COLOR))
-                    template_type =
-                        CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_TEXTURE_IGNORE_ALPHA;
-                else
-                    template_type =
-                        CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_TEXTURE_IGNORE_ALPHA;
-            } else {
-                template_type =
-                    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_IGNORE_ALPHA;
-            }
-            break;
-        }
-        // else fall through
-    case CAIRO_PATTERN_TYPE_LINEAR:
-    case CAIRO_PATTERN_TYPE_RADIAL:
-    case CAIRO_PATTERN_TYPE_MESH:
-    case CAIRO_PATTERN_TYPE_RASTER_SOURCE:
-        if (mask) {
-            /* If the mask surface has no alpha content, we use a mask
-             * of solid ones */
-            if ((mask->type == CAIRO_PATTERN_TYPE_SOLID) ||
-                (mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
-                 ((cairo_surface_pattern_t *)mask)->surface->content == CAIRO_CONTENT_COLOR))
-                template_type =
-                    CAIRO_COGL_TEMPLATE_TYPE_SOLID_MASK_TEXTURE;
-            else
-                template_type =
-                    CAIRO_COGL_TEMPLATE_TYPE_TEXTURE_MASK_TEXTURE;
-        } else {
-            template_type = CAIRO_COGL_TEMPLATE_TYPE_TEXTURE;
-        }
-        break;
-    default:
-	g_warning ("Unsupported source type");
-	return;
-    }
-
-    /* pipelines[0] is for pre-rendering the mask alpha in the case
-     * that it cannot be represented through the source color alpha
-     * value. For more details, go to the description in
-     * _cairo_cogl_setup_op_state */
-    if (op == CAIRO_OPERATOR_CLEAR || op == CAIRO_OPERATOR_SOURCE) {
-        cairo_cogl_template_type prerender_type;
-
-        pipelines[0] = g_new (cairo_cogl_pipeline_t, 1);
-
-        if (mask && mask->type != CAIRO_PATTERN_TYPE_SOLID)
-            prerender_type = CAIRO_COGL_TEMPLATE_TYPE_SOLID;
-        else
-            prerender_type = CAIRO_COGL_TEMPLATE_TYPE_TEXTURE;
-
-        /* Lazily create pipeline templates */
-        if (unlikely (dev->template_pipelines[CAIRO_OPERATOR_DEST_OUT][prerender_type] == NULL))
-            create_template_for_op_type (dev,
-                                         CAIRO_OPERATOR_DEST_OUT,
-                                         prerender_type);
-
-        pipelines[0]->pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[CAIRO_OPERATOR_DEST_OUT][prerender_type]);
-
-        pipelines[0]->mask_bounded =
-            _cairo_operator_bounded_by_mask (op);
-        pipelines[0]->src_bounded =
-            _cairo_operator_bounded_by_source (op);
-        pipelines[0]->op = CAIRO_OPERATOR_DEST_OUT;
-        pipelines[0]->n_layers = 0;
-        pipelines[0]->has_src_tex_clip = FALSE;
-        pipelines[0]->has_mask_tex_clip = FALSE;
-        pipelines[0]->unbounded_extents = extents->unbounded;
-    }
-
-    /* pipelines[1] is for normal rendering, modulating the mask with
-     * the source. Most operators will only need this pipeline. */
-    if (op != CAIRO_OPERATOR_CLEAR) {
-        pipelines[1] = g_new (cairo_cogl_pipeline_t, 1);
-
-        /* Lazily create pipeline templates */
-        if (unlikely (dev->template_pipelines[op][template_type] == NULL))
-            create_template_for_op_type (dev, op, template_type);
-
-        pipelines[1]->pipeline =
-            cogl_pipeline_copy (dev->template_pipelines[op][template_type]);
-
-        pipelines[1]->mask_bounded =
-            _cairo_operator_bounded_by_mask (op);
-        pipelines[1]->src_bounded =
-            _cairo_operator_bounded_by_source (op);
-        pipelines[1]->op = op;
-        pipelines[1]->n_layers = 0;
-        pipelines[1]->has_src_tex_clip = FALSE;
-        pipelines[1]->has_mask_tex_clip = FALSE;
-        pipelines[1]->unbounded_extents = extents->unbounded;
-    }
-
-    if (pipelines[1]) {
-        if (source->type == CAIRO_PATTERN_TYPE_SOLID) {
-            cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)source;
-            cogl_pipeline_set_color4f (pipelines[1]->pipeline,
-                                       solid_pattern->color.red * solid_pattern->color.alpha,
-                                       solid_pattern->color.green * solid_pattern->color.alpha,
-                                       solid_pattern->color.blue * solid_pattern->color.alpha,
-                                       solid_pattern->color.alpha);
-        } else {
-	    cairo_cogl_texture_attributes_t attributes;
-
-            _cairo_path_fixed_init (&pipelines[1]->src_tex_clip);
-
-	    CoglTexture *texture =
-	        _cairo_cogl_acquire_pattern_texture (source, destination,
-                                                     &extents->bounded,
-                                                     &attributes,
-                                                     &pipelines[1]->src_tex_clip);
-            if (unlikely (!texture))
-                goto BAIL;
-            set_layer_texture_with_attributes (pipelines[1]->pipeline,
-                                               pipelines[1]->n_layers++,
-                                               texture,
-                                               &attributes,
-                                               path_transform);
-            cogl_object_unref (texture);
-
-            if (pipelines[1]->src_tex_clip.buf.base.num_ops > 0)
-                pipelines[1]->has_src_tex_clip = TRUE;
-            else
-                _cairo_path_fixed_fini (&pipelines[1]->src_tex_clip);
-        }
-    }
-
-    if (mask) {
-	if (mask->type == CAIRO_PATTERN_TYPE_SOLID) {
-	    cairo_solid_pattern_t *solid_pattern = (cairo_solid_pattern_t *)mask;
-	    CoglColor color;
-	    cogl_color_init_from_4f (&color,
-				     solid_pattern->color.red * solid_pattern->color.alpha,
-				     solid_pattern->color.green * solid_pattern->color.alpha,
-				     solid_pattern->color.blue * solid_pattern->color.alpha,
-				     solid_pattern->color.alpha);
-            if (pipelines[1])
-	        cogl_pipeline_set_layer_combine_constant (pipelines[1]->pipeline,
-                                                          pipelines[1]->n_layers++,
-                                                          &color);
-            if (pipelines[0])
-                cogl_pipeline_set_color (pipelines[0]->pipeline,
-                                         &color);
-        /* If the only component present in our mask is a color
-         * component, skip setting the layer texture, as we already
-         * set a solid of uniform ones on it during the template
-         * creation process */
-	} else if (!(mask->type == CAIRO_PATTERN_TYPE_SURFACE &&
-                    ((cairo_surface_pattern_t *)mask)->surface->content == CAIRO_CONTENT_COLOR)) {
-	    cairo_cogl_texture_attributes_t attributes;
-            cairo_path_fixed_t mask_tex_clip;
-
-            _cairo_path_fixed_init (&mask_tex_clip);
-
-	    CoglTexture *texture =
-		_cairo_cogl_acquire_pattern_texture (mask, destination,
-						     &extents->bounded,
-						     &attributes,
-                                                     &mask_tex_clip);
-	    if (unlikely (!texture))
-		goto BAIL;
-            if (pipelines[1]) {
-                if (mask_tex_clip.buf.base.num_ops > 0) {
-                    pipelines[1]->has_mask_tex_clip = TRUE;
-                    if (unlikely (_cairo_path_fixed_init_copy (&pipelines[1]->mask_tex_clip,
-                                                               &mask_tex_clip)))
-                        goto BAIL;
-                }
-	        set_layer_texture_with_attributes (pipelines[1]->pipeline,
-                                                   pipelines[1]->n_layers++,
-                                                   texture,
-                                                   &attributes,
-                                                   path_transform);
-            }
-            if (pipelines[0]) {
-                if (mask_tex_clip.buf.base.num_ops > 0) {
-                    pipelines[0]->has_mask_tex_clip = TRUE;
-                    if (unlikely (_cairo_path_fixed_init_copy (&pipelines[0]->mask_tex_clip,
-                                                               &mask_tex_clip)))
-                        goto BAIL;
-                }
-                set_layer_texture_with_attributes (pipelines[0]->pipeline,
-                                                   pipelines[0]->n_layers++,
-                                                   texture,
-                                                   &attributes,
-                                                   path_transform);
-            }
-
-            _cairo_path_fixed_fini (&mask_tex_clip);
-	    cogl_object_unref (texture);
-	}
-    }
-
-    return;
-
-BAIL:
-    if (pipelines[0]) {
-        cogl_object_unref (pipelines[0]->pipeline);
-        if (pipelines[0]->has_src_tex_clip)
-            _cairo_path_fixed_fini (&pipelines[0]->src_tex_clip);
-        if (pipelines[0]->has_mask_tex_clip)
-            _cairo_path_fixed_fini (&pipelines[0]->mask_tex_clip);
-        g_free (pipelines[0]);
-        pipelines[0] = NULL;
-    }
-    if (pipelines[1]) {
-        cogl_object_unref (pipelines[1]->pipeline);
-        if (pipelines[1]->has_src_tex_clip)
-            _cairo_path_fixed_fini (&pipelines[1]->src_tex_clip);
-        if (pipelines[1]->has_mask_tex_clip)
-            _cairo_path_fixed_fini (&pipelines[1]->mask_tex_clip);
-        g_free (pipelines[1]);
-        pipelines[1] = NULL;
-    }
-}
-
-#if 0
-CoglPrimitive *
-_cairo_cogl_rectangle_new_p2t2t2 (CoglContext *cogl_context,
-                                  float        x,
-                                  float        y,
-                                  float        width,
-                                  float        height)
-{
-    CoglVertexP2 vertices[] = {
-	{x, y}, {x, y + height}, {x + width, y + height},
-	{x, y}, {x + width, y + height}, {x + width, y}
-    };
-    CoglAttributeBuffer *buffer = cogl_attribute_buffer_new (cogl_context,
-                                                             sizeof (vertices));
-    CoglAttribute *pos = cogl_attribute_new (buffer,
-					     "cogl_position_in",
-					     sizeof (CoglVertexP2),
-					     0,
-					     2,
-					     COGL_ATTRIBUTE_TYPE_FLOAT);
-    CoglAttribute *tex_coords0 = cogl_attribute_new (buffer,
-						     "cogl_tex_coord0_in",
-						     sizeof (CoglVertexP2),
-						     0,
-						     2,
-						     COGL_ATTRIBUTE_TYPE_FLOAT);
-    CoglAttribute *tex_coords0 = cogl_attribute_new (buffer,
-						     "cogl_tex_coord0_in",
-						     sizeof (CoglVertexP2),
-						     0,
-						     2,
-						     COGL_ATTRIBUTE_TYPE_FLOAT);
-    CoglPrimitive *prim;
-
-    cogl_buffer_set_data (buffer, 0, vertices, sizeof (vertices));
-
-    /* The attributes will now keep the buffer alive... */
-    cogl_object_unref (buffer);
-
-    prim = cogl_primitive_new (COGL_VERTICES_MODE_TRIANGLES,
-			       6, pos, tex_coords, NULL);
-
-    /* The primitive will now keep the attribute alive... */
-    cogl_object_unref (pos);
-
-    return prim;
-}
-#endif
-
-static void
-_cairo_cogl_log_clip (cairo_cogl_surface_t *surface,
-		      const cairo_clip_t   *clip)
-{
-    if (!_cairo_clip_equal (clip, surface->last_clip)) {
-	_cairo_cogl_journal_log_clip (surface, clip);
-	_cairo_clip_destroy (surface->last_clip);
-	surface->last_clip = _cairo_clip_copy (clip);
-    }
-}
-
-static void
-_cairo_cogl_maybe_log_clip (cairo_cogl_surface_t         *surface,
-			    cairo_composite_rectangles_t *composite)
-{
-    cairo_clip_t *clip = composite->clip;
-
-    if (_cairo_composite_rectangles_can_reduce_clip (composite, clip))
-	clip = NULL;
-
-    if (clip == NULL) {
-	if (_cairo_composite_rectangles_can_reduce_clip (composite,
-							 surface->last_clip))
-	    return;
-    }
-
-    _cairo_cogl_log_clip (surface, clip);
-}
-
-static cairo_bool_t
-is_operator_supported (cairo_operator_t op)
-{
-    switch ((int)op) {
-    case CAIRO_OPERATOR_CLEAR:
-    case CAIRO_OPERATOR_SOURCE:
-    case CAIRO_OPERATOR_OVER:
-    case CAIRO_OPERATOR_IN:
-    case CAIRO_OPERATOR_OUT:
-    case CAIRO_OPERATOR_ATOP:
-    case CAIRO_OPERATOR_DEST:
-    case CAIRO_OPERATOR_DEST_OVER:
-    case CAIRO_OPERATOR_DEST_IN:
-    case CAIRO_OPERATOR_DEST_OUT:
-    case CAIRO_OPERATOR_DEST_ATOP:
-    case CAIRO_OPERATOR_XOR:
-    case CAIRO_OPERATOR_ADD:
-	return TRUE;
-
-    default:
-        g_warning("cairo-cogl: Blend operator not supported");
-	return FALSE;
-    }
-}
-
-static cairo_int_status_t
-_cairo_cogl_surface_paint (void                  *abstract_surface,
-                           cairo_operator_t       op,
-                           const cairo_pattern_t *source,
-                           const cairo_clip_t    *clip)
-{
-    cairo_cogl_surface_t *surface;
-    cairo_int_status_t status;
-    cairo_matrix_t identity;
-    cairo_cogl_pipeline_t *pipelines[2];
-    cairo_composite_rectangles_t extents;
-
-    if (clip == NULL) {
-        status = _cairo_cogl_surface_ensure_framebuffer (abstract_surface);
-        if (unlikely (status))
-            return status;
-
-	if (op == CAIRO_OPERATOR_CLEAR)
-            return _cairo_cogl_surface_clear (abstract_surface, CAIRO_COLOR_TRANSPARENT);
-	else if (source->type == CAIRO_PATTERN_TYPE_SOLID &&
-                (op == CAIRO_OPERATOR_SOURCE ||
-                 (op == CAIRO_OPERATOR_OVER && (((cairo_surface_t *)abstract_surface)->is_clear || _cairo_pattern_is_opaque_solid (source))))) {
-            return _cairo_cogl_surface_clear (abstract_surface,
-					      &((cairo_solid_pattern_t *) source)->color);
-        }
-    }
-
-    /* fall back to handling the paint in terms of a rectangle... */
-
-    surface = (cairo_cogl_surface_t *)abstract_surface;
-
-    if (!is_operator_supported (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    status =
-        _cairo_composite_rectangles_init_for_paint (&extents,
-                                                    &surface->base,
-                                                    op,
-                                                    source,
-                                                    clip);
-    if (unlikely (status))
-	return status;
-
-    get_source_mask_operator_destination_pipelines (pipelines,
-                                                    NULL,
-                                                    source,
-                                                    op,
-                                                    surface,
-                                                    &extents,
-                                                    NULL);
-    if (unlikely (pipelines[0] == NULL && pipelines[1] == NULL)) {
-        status = CAIRO_INT_STATUS_UNSUPPORTED;
-        goto BAIL;
-    }
-
-    _cairo_cogl_maybe_log_clip (surface, &extents);
-
-    cairo_matrix_init_identity (&identity);
-    if (pipelines[0])
-        _cairo_cogl_journal_log_rectangle (surface,
-                                           pipelines[0],
-                                           extents.bounded.x,
-                                           extents.bounded.y,
-                                           extents.bounded.width,
-                                           extents.bounded.height,
-                                           &identity);
-    if (pipelines[1])
-        _cairo_cogl_journal_log_rectangle (surface,
-                                           pipelines[1],
-                                           extents.bounded.x,
-                                           extents.bounded.y,
-                                           extents.bounded.width,
-                                           extents.bounded.height,
-                                           &identity);
-
-BAIL:
-    _cairo_composite_rectangles_fini (&extents);
-
-    return status;
-}
-
-static cairo_int_status_t
-_cairo_cogl_surface_mask (void                  *abstract_surface,
-                          cairo_operator_t       op,
-                          const cairo_pattern_t *source,
-                          const cairo_pattern_t *mask,
-                          const cairo_clip_t    *clip)
-{
-    cairo_cogl_surface_t *surface = abstract_surface;
-    cairo_composite_rectangles_t extents;
-    cairo_int_status_t status;
-    cairo_cogl_pipeline_t *pipelines[2];
-    cairo_matrix_t identity;
-
-    /* XXX: Use this to smoke test the acquire_source/dest_image fallback
-     * paths... */
-    //return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    if (!is_operator_supported (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    status = _cairo_composite_rectangles_init_for_mask (&extents,
-							&surface->base,
-							op, source, mask, clip);
-    if (unlikely (status))
-	return status;
-
-    get_source_mask_operator_destination_pipelines (pipelines,
-                                                    mask,
-                                                    source,
-                                                    op,
-                                                    surface,
-                                                    &extents,
-                                                    NULL);
-    if (unlikely (pipelines[0] == NULL && pipelines[1] == NULL)) {
-	status = CAIRO_INT_STATUS_UNSUPPORTED;
-        goto BAIL;
-    }
-
-    _cairo_cogl_maybe_log_clip (surface, &extents);
-
-    cairo_matrix_init_identity (&identity);
-    if (pipelines[0])
-        _cairo_cogl_journal_log_rectangle (surface,
-                                           pipelines[0],
-                                           extents.bounded.x,
-                                           extents.bounded.y,
-                                           extents.bounded.width,
-                                           extents.bounded.height,
-                                           &identity);
-    if (pipelines[1])
-        _cairo_cogl_journal_log_rectangle (surface,
-                                           pipelines[1],
-                                           extents.bounded.x,
-                                           extents.bounded.y,
-                                           extents.bounded.width,
-                                           extents.bounded.height,
-                                           &identity);
-
-BAIL:
-    _cairo_composite_rectangles_fini (&extents);
-
-    return status;
-}
-
-static cairo_int_status_t
-_cairo_cogl_surface_stroke (void                       *abstract_surface,
-			    cairo_operator_t            op,
-			    const cairo_pattern_t      *source,
-			    const cairo_path_fixed_t   *path,
-			    const cairo_stroke_style_t *style,
-			    const cairo_matrix_t       *ctm,
-			    const cairo_matrix_t       *ctm_inverse,
-			    double                      tolerance,
-			    cairo_antialias_t           antialias,
-			    const cairo_clip_t         *clip)
-{
-    cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface;
-    cairo_composite_rectangles_t extents;
-    cairo_cogl_pipeline_t *pipelines[2];
-    cairo_int_status_t status;
-    cairo_matrix_t transform;
-    CoglPrimitive *prim = NULL;
-
-    if (! is_operator_supported (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    status = _cairo_composite_rectangles_init_for_stroke (&extents,
-							  &surface->base,
-							  op, source, path,
-							  style,
-							  ctm,
-							  clip);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_cogl_stroke_to_primitive (surface, path, style,
-                                              tolerance, TRUE, &prim,
-                                              &transform);
-    if (status == CAIRO_INT_STATUS_NOTHING_TO_DO
-        && _cairo_operator_bounded_by_mask (op) == FALSE) {
-        /* Just render the unbounded rectangle */
-        prim = NULL;
-    } else if (unlikely (status)) {
-        goto BAIL;
-    }
-
-    get_source_mask_operator_destination_pipelines (pipelines,
-                                                    NULL,
-                                                    source,
-                                                    op,
-                                                    surface,
-                                                    &extents,
-                                                    &transform);
-    if (unlikely (pipelines[0] == NULL && pipelines[1] == NULL)) {
-        status = CAIRO_INT_STATUS_UNSUPPORTED;
-        goto BAIL;
-    }
-
-    _cairo_cogl_maybe_log_clip (surface, &extents);
-
-    if (pipelines[0])
-        _cairo_cogl_journal_log_primitive (surface,
-                                           pipelines[0],
-                                           prim,
-                                           &transform);
-    if (pipelines[1])
-        _cairo_cogl_journal_log_primitive (surface,
-                                           pipelines[1],
-                                           prim,
-                                           &transform);
-
-BAIL:
-    /* The journal will take a reference on the primitive... */
-    if (prim)
-	cogl_object_unref (prim);
-
-    _cairo_composite_rectangles_fini (&extents);
-
-    return status;
-}
-
-static cairo_int_status_t
-_cairo_cogl_surface_fill (void			    *abstract_surface,
-                          cairo_operator_t	     op,
-                          const cairo_pattern_t	    *source,
-                          const cairo_path_fixed_t  *path,
-                          cairo_fill_rule_t	     fill_rule,
-                          double		     tolerance,
-                          cairo_antialias_t	     antialias,
-                          const cairo_clip_t	    *clip)
-{
-    cairo_cogl_surface_t *surface = abstract_surface;
-    cairo_composite_rectangles_t extents;
-    cairo_int_status_t status;
-    cairo_matrix_t transform;
-    CoglPrimitive *prim = NULL;
-    cairo_cogl_pipeline_t *pipelines[2];
-
-    if (! is_operator_supported (op))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    status = _cairo_composite_rectangles_init_for_fill (&extents,
-							&surface->base,
-							op, source, path,
-							clip);
-    if (unlikely (status))
-	return status;
-
-    status = _cairo_cogl_fill_to_primitive (surface, path, fill_rule,
-                                            tolerance, TRUE, &prim,
-                                            &transform);
-    if (status == CAIRO_INT_STATUS_NOTHING_TO_DO
-        && _cairo_operator_bounded_by_mask (op) == FALSE) {
-        /* Just render the unbounded rectangle */
-        prim = NULL;
-    } else if (unlikely (status)) {
-        goto BAIL;
-    }
-
-    get_source_mask_operator_destination_pipelines (pipelines,
-                                                    NULL,
-                                                    source,
-                                                    op,
-                                                    surface,
-                                                    &extents,
-                                                    &transform);
-    if (unlikely (pipelines[0] == NULL && pipelines[1] == NULL)) {
-        status = CAIRO_INT_STATUS_UNSUPPORTED;
-        goto BAIL;
-    }
-
-    _cairo_cogl_maybe_log_clip (surface, &extents);
-
-    if (pipelines[0])
-        _cairo_cogl_journal_log_primitive (surface,
-                                           pipelines[0],
-                                           prim,
-                                           &transform);
-    if (pipelines[1])
-        _cairo_cogl_journal_log_primitive (surface,
-                                           pipelines[1],
-                                           prim,
-                                           &transform);
-
-BAIL:
-    /* The journal will take a reference on the prim */
-    if (prim)
-	cogl_object_unref (prim);
-    _cairo_composite_rectangles_fini (&extents);
-
-    return status;
-}
-
-/* Mostly taken from #cairo_vg_surface.c */
-/* TODO: implement actual font support, with either cogl-pango's glyph
- * cache or our own */
-static cairo_int_status_t
-_cairo_cogl_surface_show_glyphs (void                  *abstract_surface,
-                                 cairo_operator_t       op,
-                                 const cairo_pattern_t *source,
-                                 cairo_glyph_t         *glyphs,
-                                 int                    num_glyphs,
-                                 cairo_scaled_font_t   *scaled_font,
-                                 const cairo_clip_t    *clip)
-{
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
-    cairo_path_fixed_t path;
-    int num_chunk_glyphs;
-    int i;
-
-    if (num_glyphs <= 0)
-        return CAIRO_STATUS_SUCCESS;
-
-#define GLYPH_CHUNK_SIZE 100
-
-    /* Chunk glyphs in order to avoid large computation overheads
-     * during tessellation of long strings */
-    for (i = 0; i < num_glyphs; i += GLYPH_CHUNK_SIZE) {
-        num_chunk_glyphs = (num_glyphs - i) < GLYPH_CHUNK_SIZE ?
-                           (num_glyphs - i) : GLYPH_CHUNK_SIZE;
-
-        _cairo_path_fixed_init (&path);
-        status = _cairo_scaled_font_glyph_path (scaled_font,
-                                                &glyphs[i],
-                                                num_chunk_glyphs,
-                                                &path);
-        if (unlikely (status))
-            goto BAIL;
-
-        status = _cairo_cogl_surface_fill (abstract_surface,
-                                           op, source, &path,
-                                           CAIRO_FILL_RULE_WINDING,
-                                           CAIRO_GSTATE_TOLERANCE_DEFAULT,
-                                           CAIRO_ANTIALIAS_DEFAULT,
-                                           clip);
-
-        _cairo_path_fixed_fini (&path);
-    }
-
-#undef GLYPH_CHUNK_SIZE
-
-    return CAIRO_STATUS_SUCCESS;
-
-BAIL:
-    _cairo_path_fixed_fini (&path);
-
-    return status;
-}
-
-const cairo_surface_backend_t _cairo_cogl_surface_backend = {
-    CAIRO_SURFACE_TYPE_COGL,
-    _cairo_cogl_surface_finish,
-    _cairo_default_context_create,
-
-    _cairo_cogl_surface_create_similar,
-    NULL, /* create similar image */
-    NULL, /* map to image */
-    NULL, /* unmap image */
-
-    _cairo_surface_default_source,
-    _cairo_cogl_surface_acquire_source_image,
-    _cairo_cogl_surface_release_source_image,
-    NULL, /* snapshot */
-
-    NULL, /* copy_page */
-    NULL, /* show_page */
-
-    _cairo_cogl_surface_get_extents,
-    NULL, /* get_font_options */
-
-    _cairo_cogl_surface_flush, /* flush */
-    NULL, /* mark_dirty_rectangle */
-
-    _cairo_cogl_surface_paint,
-    _cairo_cogl_surface_mask,
-    _cairo_cogl_surface_stroke,
-    _cairo_cogl_surface_fill,
-    NULL, /* fill_stroke */
-    _cairo_cogl_surface_show_glyphs,
-};
-
-static cairo_surface_t *
-_cairo_cogl_surface_create_full (cairo_cogl_device_t *dev,
-				 cairo_content_t      content,
-				 CoglFramebuffer     *framebuffer,
-				 CoglTexture         *texture)
-{
-    cairo_cogl_surface_t *surface;
-    cairo_status_t status;
-
-    status = cairo_device_acquire (&dev->base);
-    if (unlikely (status))
-	return _cairo_surface_create_in_error (status);
-
-    surface = _cairo_malloc (sizeof (cairo_cogl_surface_t));
-    if (unlikely (surface == NULL))
-        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    surface->is_mirrored_snapshot = FALSE;
-
-    surface->framebuffer = framebuffer;
-    if (framebuffer) {
-        surface->width = cogl_framebuffer_get_width (framebuffer);
-        surface->height = cogl_framebuffer_get_height (framebuffer);
-	cogl_object_ref (framebuffer);
-    }
-
-    /* FIXME: If texture == NULL and we are given an offscreen framebuffer
-     * then we want a way to poke inside the framebuffer to get a texture */
-    surface->texture = texture;
-    if (texture) {
-	if (!framebuffer) {
-            surface->width = cogl_texture_get_width (texture);
-            surface->height = cogl_texture_get_height (texture);
-        }
-	cogl_object_ref (texture);
-    }
-
-    surface->journal = NULL;
-
-    surface->last_clip = NULL;
-
-    surface->n_clip_updates_per_frame = 0;
-
-    surface->path_is_rectangle = FALSE;
-    surface->user_path = NULL;
-
-    _cairo_surface_init (&surface->base,
-                         &_cairo_cogl_surface_backend,
-                         &dev->base,
-                         content,
-			 FALSE); /* is_vector */
-
-    return &surface->base;
-}
-
-cairo_surface_t *
-cairo_cogl_surface_create_for_fb (cairo_device_t  *abstract_device,
-                                  CoglFramebuffer *framebuffer,
-                                  cairo_content_t  content)
-{
-    cairo_cogl_device_t *dev = (cairo_cogl_device_t *)abstract_device;
-
-    if (abstract_device == NULL)
-	return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_ERROR);
-
-    if (abstract_device->status)
-	return _cairo_surface_create_in_error (abstract_device->status);
-
-    if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_COGL)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
-
-    return _cairo_cogl_surface_create_full (dev,
-                                            content,
-                                            framebuffer,
-                                            NULL);
-}
-slim_hidden_def (cairo_cogl_surface_create_for_fb);
-
-cairo_surface_t *
-cairo_cogl_onscreen_surface_create (cairo_device_t *abstract_device,
-                                    cairo_content_t content,
-                                    int width, int height)
-{
-    CoglFramebuffer *fb;
-    CoglTextureComponents components;
-    CoglError *error = NULL;
-    cairo_surface_t *surface;
-    cairo_cogl_device_t *dev = (cairo_cogl_device_t *)abstract_device;
-
-    if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_COGL)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
-
-    /* We don't yet have a way to set the components of a framebuffer */
-    components = get_components_from_cairo_content (content);
-
-    fb = cogl_onscreen_new (dev->cogl_context, width, height);
-
-    if (unlikely (!cogl_framebuffer_allocate (fb, &error))) {
-        g_warning ("Could not allocate framebuffer for onscreen "
-                   "surface: %s", error->message);
-        cogl_error_free (error);
-        return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_ERROR);
-    }
-    cogl_framebuffer_orthographic (fb, 0, 0, width, height, -1, 100);
-
-    surface = cairo_cogl_surface_create_for_fb (abstract_device,
-                                                fb,
-                                                content);
-
-    /* The surface will take a reference on the framebuffer */
-    cogl_object_unref (fb);
-
-    return surface;
-}
-slim_hidden_def (cairo_cogl_onscreen_surface_create);
-
-cairo_surface_t *
-cairo_cogl_offscreen_surface_create (cairo_device_t *abstract_device,
-                                     cairo_content_t content,
-                                     int width, int height)
-{
-    CoglFramebuffer *fb;
-    CoglTexture *tex;
-    CoglError *error = NULL;
-    cairo_surface_t *surface;
-    cairo_cogl_device_t *dev = (cairo_cogl_device_t *)abstract_device;
-    int tex_width = width;
-    int tex_height = height;
-
-    if (abstract_device->backend->type != CAIRO_DEVICE_TYPE_COGL)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
-
-    /* If we cannot use an NPOT texture, allocate the texture in power
-     * of two dimensions instead */
-    if (!dev->has_npots) {
-        tex_width = (int)pow (2, ceil (log2 (tex_width)));
-        tex_height = (int)pow (2, ceil (log2 (tex_height)));
-    }
-
-    tex = cogl_texture_2d_new_with_size (dev->cogl_context,
-                                         tex_width, tex_height);
-    cogl_texture_set_components (tex,
-        get_components_from_cairo_content (content));
-    fb = cogl_offscreen_new_with_texture (tex);
-
-    if (unlikely (!cogl_framebuffer_allocate (fb, &error))) {
-        g_warning ("Could not allocate framebuffer for offscreen "
-                   "surface: %s", error->message);
-        cogl_error_free (error);
-        return _cairo_surface_create_in_error (CAIRO_STATUS_DEVICE_ERROR);
-    }
-    cogl_framebuffer_orthographic (fb, 0, 0,
-                                   tex_width, tex_height,
-                                   -1, 100);
-
-    /* The framebuffer will take a reference on the texture */
-    cogl_object_unref (tex);
-
-    surface = cairo_cogl_surface_create_for_fb (abstract_device,
-                                                fb,
-                                                content);
-
-    /* The surface will take a reference on the framebuffer */
-    cogl_object_unref (fb);
-
-    ((cairo_cogl_surface_t *)surface)->width = width;
-    ((cairo_cogl_surface_t *)surface)->height = height;
-
-    return surface;
-}
-slim_hidden_def (cairo_cogl_offscreen_surface_create);
-
-CoglFramebuffer *
-cairo_cogl_surface_get_framebuffer (cairo_surface_t *abstract_surface)
-{
-    cairo_cogl_surface_t *surface;
-
-    if (abstract_surface->backend != &_cairo_cogl_surface_backend) {
-        _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-        return NULL;
-    }
-
-    surface = (cairo_cogl_surface_t *) abstract_surface;
-
-    return surface->framebuffer;
-}
-slim_hidden_def (cairo_cogl_surface_get_framebuffer);
-
-CoglTexture *
-cairo_cogl_surface_get_texture (cairo_surface_t *abstract_surface)
-{
-    cairo_cogl_surface_t *surface;
-
-    if (abstract_surface->backend != &_cairo_cogl_surface_backend) {
-        _cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
-        return NULL;
-    }
-
-    surface = (cairo_cogl_surface_t *) abstract_surface;
-
-    return surface->texture;
-}
-slim_hidden_def (cairo_cogl_surface_get_texture);
-
-static cairo_status_t
-_cairo_cogl_device_flush (void *device)
-{
-    cairo_status_t status;
-    cairo_cogl_device_t *dev = device;
-
-    status = cairo_device_acquire (device);
-    if (unlikely (status))
-	return status;
-
-    /* XXX: we don't need to flush Cogl here, we just need to flush
-     * any batching we do of compositing primitives. */
-
-    if (dev->buffer_stack && dev->buffer_stack_offset) {
-        cogl_buffer_unmap (dev->buffer_stack);
-        cogl_object_unref (dev->buffer_stack);
-        dev->buffer_stack = NULL;
-    }
-
-    cairo_device_release (device);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-_cairo_cogl_device_finish (void *device)
-{
-    cairo_status_t status;
-    cairo_cogl_device_t *dev = device;
-    int i, j;
-
-    status = cairo_device_acquire (device);
-    if (unlikely (status))
-	return;
-
-    /* XXX: Drop references to external resources */
-
-    _cairo_cache_fini (&dev->linear_cache);
-    _cairo_cache_fini (&dev->path_fill_prim_cache);
-    _cairo_cache_fini (&dev->path_stroke_prim_cache);
-
-    _cairo_freelist_fini (&dev->path_fill_meta_freelist);
-    _cairo_freelist_fini (&dev->path_stroke_meta_freelist);
-
-    if (dev->buffer_stack && dev->buffer_stack_offset) {
-        cogl_buffer_unmap (dev->buffer_stack);
-        cogl_object_unref (dev->buffer_stack);
-        dev->buffer_stack = NULL;
-    }
-
-    for (i = 0; i < CAIRO_OPERATOR_SATURATE; i++)
-        for (j = 0; j < CAIRO_COGL_TEMPLATE_TYPE_COUNT; j++)
-            if (dev->template_pipelines[i][j] != NULL) {
-                cogl_object_unref (dev->template_pipelines[i][j]);
-                dev->template_pipelines[i][j] = NULL;
-            }
-
-    cogl_object_unref (dev->cogl_context);
-
-    cairo_device_release (device);
-}
-
-static void
-_cairo_cogl_device_destroy (void *device)
-{
-    cairo_cogl_device_t *dev = device;
-
-    g_free (dev);
-}
-
-static const cairo_device_backend_t _cairo_cogl_device_backend = {
-    CAIRO_DEVICE_TYPE_COGL,
-
-    NULL, /* lock */
-    NULL, /* unlock */
-
-    _cairo_cogl_device_flush,
-    _cairo_cogl_device_finish,
-    _cairo_cogl_device_destroy,
-};
-
-cairo_device_t *
-cairo_cogl_device_create (CoglContext *cogl_context)
-{
-    cairo_cogl_device_t *dev = g_new (cairo_cogl_device_t, 1);
-    cairo_status_t status;
-
-    dev->cogl_context = cogl_object_ref (cogl_context);
-
-    dev->has_npots =
-        cogl_has_features (cogl_context,
-                           COGL_FEATURE_ID_TEXTURE_NPOT_BASIC,
-                           COGL_FEATURE_ID_TEXTURE_NPOT_REPEAT,
-                           0);
-
-    dev->has_mirrored_repeat =
-        cogl_has_feature (cogl_context,
-                          COGL_FEATURE_ID_MIRRORED_REPEAT);
-
-    dev->buffer_stack = NULL;
-    dev->buffer_stack_size = 4096;
-
-    /* Set all template pipelines to NULL */
-    memset (dev->template_pipelines, 0, sizeof (dev->template_pipelines));
-
-    status = _cairo_cache_init (&dev->linear_cache,
-                                _cairo_cogl_linear_gradient_equal,
-                                NULL,
-                                (cairo_destroy_func_t) _cairo_cogl_linear_gradient_destroy,
-                                CAIRO_COGL_LINEAR_GRADIENT_CACHE_SIZE);
-    if (unlikely (status)) {
-        g_free (dev);
-        return _cairo_device_create_in_error (status);
-    }
-
-    status = _cairo_cache_init (&dev->path_fill_prim_cache,
-                                _cairo_cogl_path_fill_meta_equal,
-                                NULL,
-                                (cairo_destroy_func_t) _cairo_cogl_path_fill_meta_destroy,
-                                CAIRO_COGL_PATH_META_CACHE_SIZE);
-
-    status = _cairo_cache_init (&dev->path_stroke_prim_cache,
-                                _cairo_cogl_path_stroke_meta_equal,
-                                NULL,
-                                (cairo_destroy_func_t) _cairo_cogl_path_stroke_meta_destroy,
-                                CAIRO_COGL_PATH_META_CACHE_SIZE);
-
-    _cairo_freelist_init (&dev->path_fill_meta_freelist,
-                          sizeof(cairo_cogl_path_fill_meta_t));
-    _cairo_freelist_init (&dev->path_stroke_meta_freelist,
-                          sizeof(cairo_cogl_path_stroke_meta_t));
-
-    _cairo_device_init (&dev->base, &_cairo_cogl_device_backend);
-    return &dev->base;
-}
-slim_hidden_def (cairo_cogl_device_create);
-
-cairo_status_t
-cairo_cogl_surface_end_frame (cairo_surface_t *abstract_surface)
-{
-    cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface;
-
-    if (abstract_surface->backend != &_cairo_cogl_surface_backend)
-        return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
-
-    cairo_surface_flush (abstract_surface);
-
-    if (surface->framebuffer)
-        if (cogl_is_onscreen (surface->framebuffer))
-            cogl_onscreen_swap_buffers (surface->framebuffer);
-
-    //g_print ("n_clip_updates_per_frame = %d\n", surface->n_clip_updates_per_frame);
-    surface->n_clip_updates_per_frame = 0;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-slim_hidden_def (cairo_cogl_surface_end_frame);
-
-cairo_status_t
-cairo_cogl_surface_synchronize (cairo_surface_t *abstract_surface)
-{
-    cairo_cogl_surface_t *surface = (cairo_cogl_surface_t *)abstract_surface;
-
-    if (abstract_surface->backend != &_cairo_cogl_surface_backend)
-        return CAIRO_STATUS_SURFACE_TYPE_MISMATCH;
-
-    if (surface->framebuffer)
-        cogl_framebuffer_finish (surface->framebuffer);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-slim_hidden_def (cairo_cogl_surface_synchronize);
diff --git a/src/cairo-cogl.h b/src/cairo-cogl.h
deleted file mode 100644
index b7a5b8e5c..000000000
--- a/src/cairo-cogl.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2011 Intel Corporation.
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Mozilla Corporation.
- *
- * Contributor(s):
- *      Robert Bragg <robert at linux.intel.com>
- */
-
-#ifndef CAIRO_COGL_H
-#define CAIRO_COGL_H
-
-#include "cairo.h"
-
-#if CAIRO_HAS_COGL_SURFACE
-
-#include <cogl/cogl2-experimental.h>
-
-CAIRO_BEGIN_DECLS
-
-cairo_public cairo_device_t *
-cairo_cogl_device_create (CoglContext *context);
-
-cairo_public cairo_surface_t *
-cairo_cogl_onscreen_surface_create (cairo_device_t *device,
-                                    cairo_content_t content,
-                                    int width, int height);
-
-cairo_public cairo_surface_t *
-cairo_cogl_offscreen_surface_create (cairo_device_t *device,
-                                     cairo_content_t content,
-                                     int width, int height);
-
-cairo_public cairo_surface_t *
-cairo_cogl_surface_create_for_fb (cairo_device_t  *device,
-                                  CoglFramebuffer *framebuffer,
-                                  cairo_content_t  content);
-
-cairo_public CoglFramebuffer *
-cairo_cogl_surface_get_framebuffer (cairo_surface_t *surface);
-
-/* If NPOT textures are not supported, the contents of interests may
- * only be in the lowest-coordinate corner of the texture obtained from
- * this function */
-cairo_public CoglTexture *
-cairo_cogl_surface_get_texture (cairo_surface_t *surface);
-
-cairo_public cairo_status_t
-cairo_cogl_surface_end_frame (cairo_surface_t *surface);
-
-cairo_public cairo_status_t
-cairo_cogl_surface_synchronize (cairo_surface_t *surface);
-
-CAIRO_END_DECLS
-
-#else  /* CAIRO_HAS_COGL_SURFACE*/
-# error Cairo was not compiled with support for the Cogl backend
-#endif /* CAIRO_HAS_COGL_SURFACE*/
-
-#endif /* CAIRO_COGL_H */
diff --git a/src/cairoint.h b/src/cairoint.h
index 5190c206b..80b695feb 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -461,11 +461,6 @@ _cairo_ft_font_reset_static_data (void);
 cairo_private void
 _cairo_win32_font_reset_static_data (void);
 
-#if CAIRO_HAS_COGL_SURFACE
-void
-_cairo_cogl_context_reset_static_data (void);
-#endif
-
 /* the font backend interface */
 
 struct _cairo_unscaled_font_backend {
diff --git a/src/meson.build b/src/meson.build
index 2db921104..0e2c5e80a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -192,10 +192,6 @@ cairo_feature_sources = {
     'cairo-gl-surface.c',
     'cairo-gl-traps-compositor.c',
   ],
-  'cairo-cogl': [
-    'cairo-cogl-surface.c',
-    'cairo-cogl-gradient.c',
-  ],
   'cairo-directfb': [
     'cairo-directfb-surface.c',
   ],
@@ -249,7 +245,6 @@ cairo_feature_headers = {
   'cairo-tee': ['cairo-tee.h'],
   'cairo-xml': ['cairo-xml.h'],
   'cairo-vg': ['cairo-vg.h'],
-  'cairo-cogl': ['cairo-cogl.h'],
 }
 
 cairo_no_warn_c_args = cc.get_supported_arguments([
commit 1409079eefc04dcb0cab49e02f3cf3cf5e622974
Author: Emmanuele Bassi <ebassi at gnome.org>
Date:   Sat Apr 17 23:53:52 2021 +0100

    Remove cairo-drm
    
    The DRM backend has always been a science experiment, but now it hasn't
    been built in more than 10 years, and it's completely broken.

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 58bb56889..d169b397b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -72,7 +72,6 @@ fedora image:
       glib2-devel
       librsvg2-devel
       gtk2-devel
-      libdrm-devel
       poppler-glib-devel
       pixman-devel
       cogl-devel
diff --git a/boilerplate/Makefile.sources b/boilerplate/Makefile.sources
index 4711cf6ca..e219f04f7 100644
--- a/boilerplate/Makefile.sources
+++ b/boilerplate/Makefile.sources
@@ -20,7 +20,6 @@ cairo_boilerplate_private = \
 	$(NULL)
 
 cairo_boilerplate_directfb_sources = cairo-boilerplate-directfb.c
-cairo_boilerplate_drm_sources = cairo-boilerplate-drm.c
 cairo_boilerplate_glx_sources = cairo-boilerplate-glx.c
 cairo_boilerplate_wgl_sources = cairo-boilerplate-wgl.c
 cairo_boilerplate_egl_sources = cairo-boilerplate-egl.c
diff --git a/boilerplate/Makefile.win32.features b/boilerplate/Makefile.win32.features
index 5cef41220..2325ccf5b 100644
--- a/boilerplate/Makefile.win32.features
+++ b/boilerplate/Makefile.win32.features
@@ -117,26 +117,6 @@ enabled_cairo_boilerplate_private += $(cairo_boilerplate_win32_font_private)
 enabled_cairo_boilerplate_sources += $(cairo_boilerplate_win32_font_sources)
 endif
 
-unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_drm_headers)
-all_cairo_boilerplate_headers += $(cairo_boilerplate_drm_headers)
-all_cairo_boilerplate_private += $(cairo_boilerplate_drm_private)
-all_cairo_boilerplate_sources += $(cairo_boilerplate_drm_sources)
-ifeq ($(CAIRO_HAS_DRM_SURFACE),1)
-enabled_cairo_boilerplate_headers += $(cairo_boilerplate_drm_headers)
-enabled_cairo_boilerplate_private += $(cairo_boilerplate_drm_private)
-enabled_cairo_boilerplate_sources += $(cairo_boilerplate_drm_sources)
-endif
-
-unsupported_cairo_boilerplate_headers += $(cairo_boilerplate_gallium_headers)
-all_cairo_boilerplate_headers += $(cairo_boilerplate_gallium_headers)
-all_cairo_boilerplate_private += $(cairo_boilerplate_gallium_private)
-all_cairo_boilerplate_sources += $(cairo_boilerplate_gallium_sources)
-ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1)
-enabled_cairo_boilerplate_headers += $(cairo_boilerplate_gallium_headers)
-enabled_cairo_boilerplate_private += $(cairo_boilerplate_gallium_private)
-enabled_cairo_boilerplate_sources += $(cairo_boilerplate_gallium_sources)
-endif
-
 supported_cairo_boilerplate_headers += $(cairo_boilerplate_png_headers)
 all_cairo_boilerplate_headers += $(cairo_boilerplate_png_headers)
 all_cairo_boilerplate_private += $(cairo_boilerplate_png_private)
diff --git a/boilerplate/cairo-boilerplate-drm.c b/boilerplate/cairo-boilerplate-drm.c
deleted file mode 100644
index 79d9229f6..000000000
--- a/boilerplate/cairo-boilerplate-drm.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Chris Wilson.
- */
-
-#include "cairo-boilerplate-private.h"
-
-#include <cairo-drm.h>
-
-static cairo_surface_t *
-_cairo_boilerplate_drm_create_surface (const char		 *name,
-				       cairo_content_t		  content,
-				       double			  width,
-				       double			  height,
-				       double			  max_width,
-				       double			  max_height,
-				       cairo_boilerplate_mode_t   mode,
-				       void			**closure)
-{
-    cairo_device_t *device;
-    cairo_format_t format;
-
-    device = cairo_drm_device_default ();
-    if (device == NULL)
-	return NULL; /* skip tests if no supported h/w found */
-
-    switch (content) {
-    case CAIRO_CONTENT_ALPHA:
-        format = CAIRO_FORMAT_A8;
-        break;
-    case CAIRO_CONTENT_COLOR:
-        format = CAIRO_FORMAT_RGB24;
-        break;
-    case CAIRO_CONTENT_COLOR_ALPHA:
-    default:
-        format = CAIRO_FORMAT_ARGB32;
-        break;
-    }
-
-    return *closure = cairo_drm_surface_create (device, format, width, height);
-}
-
-static void
-_cairo_boilerplate_drm_synchronize (void *closure)
-{
-    cairo_surface_t *image;
-
-    image = cairo_drm_surface_map_to_image (closure);
-    if (cairo_surface_status (image) == CAIRO_STATUS_SUCCESS)
-	cairo_drm_surface_unmap (closure, image);
-}
-
-static const cairo_boilerplate_target_t targets[] = {
-    /* Acceleration architectures may make the results differ by a
-     * bit, so we set the error tolerance to 1. */
-    {
-	"drm", "drm", NULL, NULL,
-	CAIRO_SURFACE_TYPE_DRM, CAIRO_CONTENT_COLOR_ALPHA, 1,
-	"cairo_drm_surface_create",
-	_cairo_boilerplate_drm_create_surface,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	NULL,
-	_cairo_boilerplate_drm_synchronize,
-        NULL,
-	TRUE, FALSE, FALSE
-    },
-    {
-	"drm", "drm", NULL, NULL,
-	CAIRO_SURFACE_TYPE_DRM, CAIRO_CONTENT_COLOR, 1,
-	"cairo_drm_surface_create",
-	_cairo_boilerplate_drm_create_surface,
-	cairo_surface_create_similar,
-	NULL, NULL,
-	_cairo_boilerplate_get_image_surface,
-	cairo_surface_write_to_png,
-	NULL,
-	_cairo_boilerplate_drm_synchronize,
-        NULL,
-	FALSE, FALSE, FALSE
-    },
-};
-CAIRO_BOILERPLATE (drm, targets)
diff --git a/boilerplate/meson.build b/boilerplate/meson.build
index 780f9bc30..f26d3fa0b 100644
--- a/boilerplate/meson.build
+++ b/boilerplate/meson.build
@@ -9,7 +9,6 @@ cairo_boilerplate_feature_sources = {
   'cairo-quartz': ['cairo-boilerplate-quartz.c'],
   'cairo-xcb': ['cairo-boilerplate-xcb.c'],
   'cairo-win32': ['cairo-boilerplate-win32.c', 'cairo-boilerplate-win32-printing.c'],
-  'cairo-drm': ['cairo-boilerplate-drm.c'],
   'cairo-cogl': ['cairo-boilerplate-cogl.c'],
   'cairo-directfb': ['cairo-boilerplate-directfb.c'],
   'cairo-pdf': ['cairo-boilerplate-pdf.c'],
diff --git a/build/Makefile.win32.features b/build/Makefile.win32.features
index bd03d5ce9..4770571a1 100644
--- a/build/Makefile.win32.features
+++ b/build/Makefile.win32.features
@@ -10,8 +10,6 @@ CAIRO_HAS_QUARTZ_FONT=0
 CAIRO_HAS_QUARTZ_IMAGE_SURFACE=0
 CAIRO_HAS_WIN32_SURFACE=1
 CAIRO_HAS_WIN32_FONT=1
-CAIRO_HAS_DRM_SURFACE=0
-CAIRO_HAS_GALLIUM_SURFACE=0
 CAIRO_HAS_PNG_FUNCTIONS=1
 CAIRO_HAS_GL_SURFACE=0
 CAIRO_HAS_GLESV2_SURFACE=0
diff --git a/build/Makefile.win32.features-h b/build/Makefile.win32.features-h
index 3c3d97733..6b28b6faa 100644
--- a/build/Makefile.win32.features-h
+++ b/build/Makefile.win32.features-h
@@ -35,12 +35,6 @@ endif
 ifeq ($(CAIRO_HAS_WIN32_FONT),1)
 	@echo "#define CAIRO_HAS_WIN32_FONT 1" >> $(top_srcdir)/src/cairo-features.h
 endif
-ifeq ($(CAIRO_HAS_DRM_SURFACE),1)
-	@echo "#define CAIRO_HAS_DRM_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
-endif
-ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1)
-	@echo "#define CAIRO_HAS_GALLIUM_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h
-endif
 ifeq ($(CAIRO_HAS_PNG_FUNCTIONS),1)
 	@echo "#define CAIRO_HAS_PNG_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h
 endif
diff --git a/build/configure.ac.features b/build/configure.ac.features
index a1a3ff830..d1fae3306 100644
--- a/build/configure.ac.features
+++ b/build/configure.ac.features
@@ -380,7 +380,6 @@ AC_DEFUN([CAIRO_REPORT],
 	echo "  OpenGL ES 3.0: $use_glesv3"
 	echo "  DirectFB:      $use_directfb"
 	echo "  OpenVG:        $use_vg"
-	echo "  DRM:           $use_drm"
 	echo "  Cogl:          $use_cogl"
 	echo ""
 	echo "The following font backends:"
diff --git a/configure.ac b/configure.ac
index dcbb3bdf5..06e421536 100644
--- a/configure.ac
+++ b/configure.ac
@@ -239,32 +239,6 @@ AM_CONDITIONAL(CAIRO_CAN_TEST_WIN32_PRINTING_SURFACE, test "x$test_win32_printin
 
 dnl ===========================================================================
 
-CAIRO_ENABLE_SURFACE_BACKEND(drm, DRM, no, [
-  dnl Keep in sync with meson.build!
-  drm_REQUIRES="libudev >= 136, libdrm >= 2.4"
-  PKG_CHECK_MODULES(drm, $drm_REQUIRES, ,
-   [use_drm="no (requires $drm_REQUIRES, udev is available from git://git.kernel.org/pub/scm/linux/hotplug/udev.git)"])
-])
-
-CAIRO_ENABLE_SURFACE_BACKEND(gallium, Gallium3D, no, [
-  if test "x$use_drm" = "xyes"; then
-      AC_ARG_WITH([gallium],
-		  [AS_HELP_STRING([--with-gallium=/path/to/mesa],
-				  [directory to find gallium enabled mesa])],
-		  [mesa_DIR="$withval"],
-		  [mesa_DIR="`pwd`/../mesa"])
-      gallium_DIR="$mesa_DIR/src/gallium"
-      gallium_NONPKGCONFIG_CFLAGS="-I$mesa_DIR/include -I$mesa_DIR/src/mesa -I$gallium_DIR/include -I$gallium_DIR/auxiliary"
-      gallium_NONPKGCONFIG_LIBS="-lGL"
-      AC_SUBST(mesa_DIR)
-      AC_SUBST(gallium_DIR)
-  else
-    use_gallium="no (requires --enable-drm)"
-  fi
-])
-
-dnl ===========================================================================
-
 CAIRO_ENABLE_FUNCTIONS(png, PNG, yes, [
   use_png=no
   AC_ARG_VAR([png_REQUIRES], [module name for libpng to search for using pkg-config])
diff --git a/doc/public/Makefile.am b/doc/public/Makefile.am
index bf2a0e759..b9e31ded0 100644
--- a/doc/public/Makefile.am
+++ b/doc/public/Makefile.am
@@ -20,7 +20,6 @@ EXTRA_HFILES=$(top_builddir)/src/cairo-supported-features.h
 
 # Headers to ignore
 IGNORE_HFILES= \
-	drm \
 	cairo-features.h \
 	cairo-features-win32.h \
 	$(all_cairo_private) \
diff --git a/doc/public/meson.build b/doc/public/meson.build
index 2c27105b4..31168f268 100644
--- a/doc/public/meson.build
+++ b/doc/public/meson.build
@@ -2,7 +2,6 @@ gnome = import('gnome')
 
 ignore_headers = [
   # Sub-directories
-  'drm',
   'win32',
 
   # Internal headers
diff --git a/meson.build b/meson.build
index d73e636a6..ad8fb19c3 100644
--- a/meson.build
+++ b/meson.build
@@ -11,7 +11,6 @@ xrender_required_version = '>= 0.6'
 xcb_required_version = '>= 1.6'
 xcb_render_required_version = '>= 1.6'
 libudev_required_version = '>= 136'
-libdrm_required_version = '>= 2.4'
 glib_required_version = '>= 2.14'
 
 # library versioning
@@ -504,24 +503,6 @@ if host_machine.system() == 'windows'
   ]
 endif
 
-# FIXME: Doesn't build since at least 2011
-libudev_dep = dependency('libudev', required: get_option('drm'),
-                         version: libudev_required_version)
-libdrm_dep = dependency('libdrm', required: get_option('drm'),
-                        version: libdrm_required_version)
-if libudev_dep.found() and libdrm_dep.found() and false
-  deps += [libudev_dep, libdrm_dep]
-
-  feature_conf.set('CAIRO_HAS_DRM_SURFACE', 1)
-  built_features += [{
-    'name': 'cairo-drm',
-    'description': 'DRM surface backend',
-    'deps': [libudev_dep, libdrm_dep],
-  }]
-endif
-
-# Not even trying to port gallium as it depends on drm
-
 # GL / GLESV2 / GLESV3 are mutually exclusive
 gl_backend = get_option('gl-backend')
 need_egl_functions = false
@@ -999,7 +980,6 @@ summary({
         'OpenGL ES 3.0': feature_conf.get('CAIRO_HAS_GLESV3_SURFACE', 0) == 1,
         'DirectFB': feature_conf.get('CAIRO_HAS_DIRECTFB_SURFACE', 0) == 1,
         'OpenVG': feature_conf.get('CAIRO_HAS_VG_SURFACE', 0) == 1,
-        'DRM': feature_conf.get('CAIRO_HAS_DRM_SURFACE', 0) == 1,
         'Cogl': feature_conf.get('CAIRO_HAS_COGL_SURFACE', 0) == 1,
         }, section: 'Surface Backends', bool_yn: true)
 
diff --git a/meson_options.txt b/meson_options.txt
index e9eeb1189..891fb99a3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -10,7 +10,6 @@ option('gl-backend', type : 'combo', value : 'disabled',
        choices : ['auto', 'gl', 'glesv2', 'glesv3', 'disabled'])
 option('glesv2', type : 'feature', value : 'disabled')
 option('glesv3', type : 'feature', value : 'disabled')
-option('drm', type : 'feature', value : 'disabled')
 option('openvg', type : 'feature', value : 'disabled')
 option('png', type : 'feature', value : 'auto') # png and svg surfaces
 option('quartz', type : 'feature', value : 'auto')
diff --git a/src/Makefile.sources b/src/Makefile.sources
index 329b8bdd8..938abe82d 100644
--- a/src/Makefile.sources
+++ b/src/Makefile.sources
@@ -396,38 +396,6 @@ cairo_wgl_sources += cairo-wgl-context.c
 cairo_directfb_headers = cairo-directfb.h
 cairo_directfb_sources = cairo-directfb-surface.c
 
-cairo_drm_headers = cairo-drm.h
-cairo_drm_private = drm/cairo-drm-private.h \
-		    drm/cairo-drm-intel-private.h \
-		    drm/cairo-drm-intel-brw-defines.h \
-		    drm/cairo-drm-intel-brw-structs.h \
-		    drm/cairo-drm-intel-brw-eu.h \
-		    drm/cairo-drm-intel-command-private.h \
-		    drm/cairo-drm-intel-ioctl-private.h \
-		    drm/cairo-drm-i915-private.h \
-		    drm/cairo-drm-i965-private.h \
-		    drm/cairo-drm-radeon-private.h
-cairo_drm_sources = drm/cairo-drm.c \
-		    drm/cairo-drm-bo.c \
-		    drm/cairo-drm-surface.c \
-		    drm/cairo-drm-intel.c \
-		    drm/cairo-drm-intel-debug.c \
-		    drm/cairo-drm-intel-surface.c \
-		    drm/cairo-drm-i915-surface.c \
-		    drm/cairo-drm-i915-glyphs.c \
-		    drm/cairo-drm-i915-shader.c \
-		    drm/cairo-drm-i915-spans.c \
-		    drm/cairo-drm-i965-surface.c \
-		    drm/cairo-drm-i965-glyphs.c \
-		    drm/cairo-drm-i965-shader.c \
-		    drm/cairo-drm-i965-spans.c \
-		    drm/cairo-drm-intel-brw-eu.c \
-		    drm/cairo-drm-intel-brw-eu-emit.c \
-		    drm/cairo-drm-intel-brw-eu-util.c \
-		    drm/cairo-drm-radeon.c \
-		    drm/cairo-drm-radeon-surface.c
-cairo_gallium_sources = drm/cairo-drm-gallium-surface.c
-
 cairo_script_headers = cairo-script.h
 cairo_script_private = cairo-script-private.h
 cairo_script_sources = cairo-script-surface.c
diff --git a/src/Makefile.win32.features b/src/Makefile.win32.features
index 7ddc6a8b7..9641ee9c6 100644
--- a/src/Makefile.win32.features
+++ b/src/Makefile.win32.features
@@ -159,34 +159,6 @@ ifeq ($(CAIRO_HAS_WIN32_FONT),1)
 enabled_cairo_pkgconf += cairo-win32-font.pc
 endif
 
-unsupported_cairo_headers += $(cairo_drm_headers)
-all_cairo_headers += $(cairo_drm_headers)
-all_cairo_private += $(cairo_drm_private)
-all_cairo_sources += $(cairo_drm_sources)
-ifeq ($(CAIRO_HAS_DRM_SURFACE),1)
-enabled_cairo_headers += $(cairo_drm_headers)
-enabled_cairo_private += $(cairo_drm_private)
-enabled_cairo_sources += $(cairo_drm_sources)
-endif
-all_cairo_pkgconf += cairo-drm.pc
-ifeq ($(CAIRO_HAS_DRM_SURFACE),1)
-enabled_cairo_pkgconf += cairo-drm.pc
-endif
-
-unsupported_cairo_headers += $(cairo_gallium_headers)
-all_cairo_headers += $(cairo_gallium_headers)
-all_cairo_private += $(cairo_gallium_private)
-all_cairo_sources += $(cairo_gallium_sources)
-ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1)
-enabled_cairo_headers += $(cairo_gallium_headers)
-enabled_cairo_private += $(cairo_gallium_private)
-enabled_cairo_sources += $(cairo_gallium_sources)
-endif
-all_cairo_pkgconf += cairo-gallium.pc
-ifeq ($(CAIRO_HAS_GALLIUM_SURFACE),1)
-enabled_cairo_pkgconf += cairo-gallium.pc
-endif
-
 supported_cairo_headers += $(cairo_png_headers)
 all_cairo_headers += $(cairo_png_headers)
 all_cairo_private += $(cairo_png_private)
diff --git a/src/cairo-debug.c b/src/cairo-debug.c
index 6acdea9dd..a314eefbf 100644
--- a/src/cairo-debug.c
+++ b/src/cairo-debug.c
@@ -88,10 +88,6 @@ cairo_debug_reset_static_data (void)
 
     _cairo_image_compositor_reset_static_data ();
 
-#if CAIRO_HAS_DRM_SURFACE
-    _cairo_drm_device_reset_static_data ();
-#endif
-
     _cairo_default_context_reset_static_data ();
 
     CAIRO_MUTEX_FINALIZE ();
diff --git a/src/cairo-drm.h b/src/cairo-drm.h
deleted file mode 100644
index 907610dcd..000000000
--- a/src/cairo-drm.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Chris Wilson.
- */
-
-#ifndef CAIRO_DRM_H
-#define CAIRO_DRM_H
-
-#include "cairo.h"
-
-#if CAIRO_HAS_DRM_SURFACE
-
-CAIRO_BEGIN_DECLS
-
-struct udev_device;
-
-cairo_public cairo_device_t *
-cairo_drm_device_get (struct udev_device *device);
-
-cairo_public cairo_device_t *
-cairo_drm_device_get_for_fd (int fd);
-
-cairo_public cairo_device_t *
-cairo_drm_device_default (void);
-
-cairo_public int
-cairo_drm_device_get_fd (cairo_device_t *device);
-
-cairo_public void
-cairo_drm_device_throttle (cairo_device_t *device);
-
-cairo_public cairo_surface_t *
-cairo_drm_surface_create (cairo_device_t *device,
-			  cairo_format_t format,
-			  int width, int height);
-
-cairo_public cairo_surface_t *
-cairo_drm_surface_create_for_name (cairo_device_t *device,
-				   unsigned int name,
-	                           cairo_format_t format,
-				   int width, int height, int stride);
-
-cairo_public cairo_surface_t *
-cairo_drm_surface_create_from_cacheable_image (cairo_device_t *device,
-	                                       cairo_surface_t *surface);
-
-cairo_public cairo_status_t
-cairo_drm_surface_enable_scan_out (cairo_surface_t *surface);
-
-cairo_public unsigned int
-cairo_drm_surface_get_handle (cairo_surface_t *surface);
-
-cairo_public unsigned int
-cairo_drm_surface_get_name (cairo_surface_t *surface);
-
-cairo_public cairo_format_t
-cairo_drm_surface_get_format (cairo_surface_t *surface);
-
-cairo_public int
-cairo_drm_surface_get_width (cairo_surface_t *surface);
-
-cairo_public int
-cairo_drm_surface_get_height (cairo_surface_t *surface);
-
-cairo_public int
-cairo_drm_surface_get_stride (cairo_surface_t *surface);
-
-/* XXX map/unmap, general surface layer? */
-
-/* Rough outline, culled from a conversation on IRC:
- *   map() returns an image-surface representation of the drm-surface,
- *   which you unmap() when you are finished, i.e. map() pulls the buffer back
- *   from the GPU, maps it into the CPU domain and gives you direct access to
- *   the pixels.  With the unmap(), the buffer is ready to be used again by the
- *   GPU and *until* the unmap(), all operations will be done in software.
- *
- *  (Technically calling cairo_surface_flush() on the underlying drm-surface
- *  will also disassociate the mapping.)
-*/
-cairo_public cairo_surface_t *
-cairo_drm_surface_map_to_image (cairo_surface_t *surface);
-
-cairo_public void
-cairo_drm_surface_unmap (cairo_surface_t *drm_surface,
-	                 cairo_surface_t *image_surface);
-
-CAIRO_END_DECLS
-
-#else  /* CAIRO_HAS_DRM_SURFACE */
-# error Cairo was not compiled with support for the DRM backend
-#endif /* CAIRO_HAS_DRM_SURFACE */
-
-#endif /* CAIRO_DRM_H */
diff --git a/src/cairo-mutex-list-private.h b/src/cairo-mutex-list-private.h
index ca7403006..70d566ebb 100644
--- a/src/cairo-mutex-list-private.h
+++ b/src/cairo-mutex-list-private.h
@@ -72,8 +72,5 @@ CAIRO_MUTEX_DECLARE (_cairo_gl_context_mutex)
 CAIRO_MUTEX_DECLARE (_cairo_atomic_mutex)
 #endif
 
-#if CAIRO_HAS_DRM_SURFACE
-CAIRO_MUTEX_DECLARE (_cairo_drm_device_mutex)
-#endif
 /* Undefine, to err on unintended inclusion */
 #undef   CAIRO_MUTEX_DECLARE
diff --git a/src/cairoint.h b/src/cairoint.h
index 4ffcba033..5190c206b 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1895,13 +1895,6 @@ _cairo_trapezoid_array_translate_and_scale (cairo_trapezoid_t *offset_traps,
 					    double tx, double ty,
 					    double sx, double sy);
 
-#if CAIRO_HAS_DRM_SURFACE
-
-cairo_private void
-_cairo_drm_device_reset_static_data (void);
-
-#endif
-
 cairo_private void
 _cairo_clip_reset_static_data (void);
 
diff --git a/src/check-headers.sh b/src/check-headers.sh
index f6c7bd59f..b4f14571d 100755
--- a/src/check-headers.sh
+++ b/src/check-headers.sh
@@ -11,7 +11,7 @@ echo Checking public headers for missing cairo_public decorators
 cd "$srcdir"
 FILES=$all_cairo_headers
 if test "x$FILES" = x; then
-	FILES=`find . -name 'cairo*.h' ! -name '*-private.h' ! -name 'cairoint.h' ! -name '*-inline.h' ! -name cairo-drm-intel-brw-eu.h`
+	FILES=`find . -name 'cairo*.h' ! -name '*-private.h' ! -name 'cairoint.h' ! -name '*-inline.h'`
 fi
 
 grep -B 1 '^cairo_.*[ 	]\+(' /dev/null $FILES |
diff --git a/src/drm/cairo-drm-bo.c b/src/drm/cairo-drm-bo.c
deleted file mode 100644
index c82f9331d..000000000
--- a/src/drm/cairo-drm-bo.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- */
-
-#include "cairoint.h"
-#include "cairo-drm-private.h"
-#include "cairo-error-private.h"
-
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <libdrm/drm.h>
-
-#define ERR_DEBUG(x) x
-
-cairo_status_t
-_cairo_drm_bo_open_for_name (const cairo_drm_device_t *dev,
-			     cairo_drm_bo_t *bo,
-			     uint32_t name)
-{
-    struct drm_gem_open open;
-    int ret;
-
-    open.name = name;
-    open.handle = 0;
-    open.size = 0;
-    do {
-	ret = ioctl (dev->fd, DRM_IOCTL_GEM_OPEN, &open);
-    } while (ret == -1 && errno == EINTR);
-    if (ret == -1) {
-	ERR_DEBUG((fprintf (stderr, "Failed to open bo for name %d: %s\n",
-			    name, strerror (errno))));
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
-
-    bo->name = name;
-    bo->size = open.size;
-    bo->handle = open.handle;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
-_cairo_drm_bo_flink (const cairo_drm_device_t *dev,
-		     cairo_drm_bo_t *bo)
-{
-    struct drm_gem_flink flink;
-    int ret;
-
-    memset (&flink, 0, sizeof (flink));
-    flink.handle = bo->handle;
-    ret = ioctl (dev->fd, DRM_IOCTL_GEM_FLINK, &flink);
-    if (ret == -1) {
-	ERR_DEBUG((fprintf (stderr, "Failed to flink bo: %s\n",
-			    strerror (errno))));
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
-
-    bo->name = flink.name;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-void
-_cairo_drm_bo_close (const cairo_drm_device_t *dev,
-		     cairo_drm_bo_t *bo)
-{
-    struct drm_gem_close close;
-    int ret;
-
-    close.handle = bo->handle;
-    do {
-	ret = ioctl (dev->fd, DRM_IOCTL_GEM_CLOSE, &close);
-    } while (ret == -1 && errno == EINTR);
-}
diff --git a/src/drm/cairo-drm-gallium-surface.c b/src/drm/cairo-drm-gallium-surface.c
deleted file mode 100644
index ca18f7336..000000000
--- a/src/drm/cairo-drm-gallium-surface.c
+++ /dev/null
@@ -1,826 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- * Copyright © 2009 Eric Anholt
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Chris Wilson.
- */
-
-#include "cairoint.h"
-
-#include "cairo-drm-private.h"
-#include "cairo-default-context-private.h"
-#include "cairo-error-private.h"
-
-#include <dlfcn.h>
-
-#include <state_tracker/drm_api.h>
-#include <pipe/p_format.h>
-#include <pipe/p_screen.h>
-#include <pipe/p_context.h>
-#include <pipe/p_state.h>
-
-#include <util/u_inlines.h>
-
-typedef struct _gallium_surface gallium_surface_t;
-typedef struct _gallium_device gallium_device_t;
-
-struct _gallium_device {
-    cairo_drm_device_t drm;
-
-    void *dlhandle;
-    struct drm_api *api;
-
-    struct pipe_screen *screen;
-    struct pipe_context *pipe;
-
-    int max_size;
-};
-
-struct _gallium_surface {
-    cairo_drm_surface_t drm;
-
-    enum pipe_format pipe_format;
-
-    struct pipe_resource *texture;
-    struct pipe_transfer *map_transfer;
-
-    cairo_surface_t *fallback;
-};
-
-static cairo_surface_t *
-gallium_surface_create_internal (gallium_device_t *device,
-				 enum pipe_format format,
-				 int width, int height);
-
-static inline gallium_device_t *
-gallium_device (gallium_surface_t *surface)
-{
-    return (gallium_device_t *) surface->drm.base.device;
-}
-
-static cairo_format_t
-_cairo_format_from_pipe_format (enum pipe_format format)
-{
-    switch ((int) format) {
-    case PIPE_FORMAT_A8_UNORM:
-	return CAIRO_FORMAT_A8;
-    case PIPE_FORMAT_A8R8G8B8_UNORM:
-	return CAIRO_FORMAT_ARGB32;
-    default:
-	return CAIRO_FORMAT_INVALID;
-    }
-}
-
-static enum pipe_format
-pipe_format_from_format (cairo_format_t format)
-{
-    switch ((int) format) {
-    case CAIRO_FORMAT_A8:
-	return PIPE_FORMAT_A8_UNORM;
-    case CAIRO_FORMAT_ARGB32:
-	return PIPE_FORMAT_A8R8G8B8_UNORM;
-    default:
-	return (enum pipe_format) -1;
-    }
-}
-
-static enum pipe_format
-pipe_format_from_content (cairo_content_t content)
-{
-    if (content == CAIRO_CONTENT_ALPHA)
-	return PIPE_FORMAT_A8_UNORM;
-    else
-	return PIPE_FORMAT_A8R8G8B8_UNORM;
-}
-
-static cairo_bool_t
-format_is_supported_destination (gallium_device_t *device,
-	                         enum pipe_format format)
-{
-    if (format == (enum pipe_format) -1)
-	return FALSE;
-
-    return device->screen->is_format_supported (device->screen,
-					        format,
-						0,
-						PIPE_BIND_RENDER_TARGET,
-						0);
-}
-
-#if 0
-static cairo_bool_t
-format_is_supported_source (gallium_device_t *device,
-	                    enum pipe_format format)
-{
-    return device->screen->is_format_supported (device->screen,
-					        format,
-						0,
-						PIPE_BIND_SAMPLER_VIEW,
-						0);
-}
-#endif
-
-static cairo_surface_t *
-gallium_surface_create_similar (void			*abstract_src,
-				cairo_content_t		 content,
-				int			 width,
-				int			 height)
-{
-    gallium_surface_t *other = abstract_src;
-    gallium_device_t *device = gallium_device (other);
-    enum pipe_format pipe_format;
-    cairo_surface_t *surface = NULL;
-    cairo_status_t status;
-
-    status = cairo_device_acquire (&device->drm.base);
-    if (unlikely (status))
-	return _cairo_surface_create_in_error (status);
-
-    if (MAX (width, height) > device->max_size)
-	goto RELEASE;
-
-    if (content == other->drm.base.content)
-	pipe_format = other->pipe_format;
-    else
-	pipe_format = pipe_format_from_content (content);
-
-    if (! format_is_supported_destination (device, pipe_format))
-	goto RELEASE;
-
-    surface = gallium_surface_create_internal (device,
-					       pipe_format,
-					       width, height);
-
-RELEASE:
-    cairo_device_release (&device->drm.base);
-
-    return surface;
-}
-
-static cairo_status_t
-gallium_surface_finish (void *abstract_surface)
-{
-    gallium_surface_t *surface = abstract_surface;
-    gallium_device_t *device = gallium_device (surface);
-    cairo_status_t status;
-
-    status = cairo_device_acquire (&device->drm.base);
-    if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	pipe_resource_reference (&surface->texture, NULL);
-	cairo_device_release (&device->drm.base);
-    }
-
-    return _cairo_drm_surface_finish (&surface->drm);
-}
-
-static cairo_surface_t *
-gallium_surface_map_to_image (gallium_surface_t *surface)
-{
-    gallium_device_t *device = gallium_device (surface);
-    cairo_status_t status;
-    void *ptr = NULL;
-
-    status = cairo_device_acquire (&device->drm.base);
-    if (unlikely (status))
-	return _cairo_surface_create_in_error (status);
-
-    surface->map_transfer =
-	  pipe_get_transfer (device->pipe,
-			     surface->texture, 0, 0, 0,
-			     PIPE_TRANSFER_MAP_DIRECTLY |
-			     PIPE_TRANSFER_READ_WRITE,
-			     0, 0,
-			     surface->drm.width,
-			     surface->drm.height);
-    if (likely (surface->map_transfer != NULL))
-	ptr = device->pipe->transfer_map (device->pipe, surface->map_transfer);
-
-    cairo_device_release (&device->drm.base);
-
-    if (unlikely (ptr == NULL)) {
-	if (surface->map_transfer != NULL) {
-	    device->pipe->transfer_destroy (device->pipe,
-					    surface->map_transfer);
-	    surface->map_transfer = NULL;
-	}
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    }
-
-    return cairo_image_surface_create_for_data (ptr,
-						surface->drm.format,
-						surface->drm.width,
-						surface->drm.height,
-						surface->map_transfer->stride);
-}
-
-static cairo_status_t
-gallium_surface_acquire_source_image (void *abstract_surface,
-				      cairo_image_surface_t **image_out,
-				      void **image_extra)
-{
-    gallium_surface_t *surface = abstract_surface;
-    gallium_device_t *device = gallium_device (surface);
-    cairo_format_t format;
-    cairo_surface_t *image;
-    cairo_status_t status;
-    struct pipe_transfer *transfer;
-    void *ptr;
-
-    if (surface->fallback != NULL) {
-	*image_out = (cairo_image_surface_t *)
-	    cairo_surface_reference (surface->fallback);
-	*image_extra = NULL;
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    if (unlikely (surface->drm.width == 0 || surface->drm.height == 0)) {
-	image = cairo_image_surface_create (surface->drm.format, 0, 0);
-	if (unlikely (image->status))
-	    return image->status;
-
-	*image_out = (cairo_image_surface_t *) image;
-	*image_extra = NULL;
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    format = _cairo_format_from_pipe_format (surface->pipe_format);
-    if (format == CAIRO_FORMAT_INVALID)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    status = cairo_device_acquire (&device->drm.base);
-    if (unlikely (status))
-	return status;
-
-    transfer = pipe_get_transfer (device->pipe,
-				  surface->texture, 0, 0, 0,
-				  PIPE_TRANSFER_READ,
-				  0, 0,
-				  surface->drm.width,
-				  surface->drm.height);
-    ptr = device->pipe->transfer_map (device->pipe, transfer);
-    cairo_device_release (&device->drm.base);
-
-    image = cairo_image_surface_create_for_data (ptr, format,
-						 surface->drm.width,
-						 surface->drm.height,
-						 surface->drm.stride);
-    if (unlikely (image->status))
-	return image->status;
-
-    *image_out = (cairo_image_surface_t *) image;
-    *image_extra = transfer;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-gallium_surface_release_source_image (void *abstract_surface,
-				      cairo_image_surface_t *image,
-				      void *image_extra)
-{
-    cairo_surface_destroy (&image->base);
-
-    if (image_extra != NULL) {
-	gallium_device_t *device = gallium_device (abstract_surface);
-
-	device->pipe->transfer_unmap (device->pipe, image_extra);
-	device->pipe->transfer_destroy (device->pipe, image_extra);
-    }
-}
-
-static cairo_status_t
-gallium_surface_flush (void *abstract_surface,
-		       unsigned flags)
-{
-    gallium_surface_t *surface = abstract_surface;
-    gallium_device_t *device = gallium_device (surface);
-    cairo_status_t status;
-
-    if (flags)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (surface->fallback == NULL) {
-	device->pipe->flush (device->pipe,
-			     PIPE_FLUSH_RENDER_CACHE,
-			     NULL);
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    /* kill any outstanding maps */
-    cairo_surface_finish (surface->fallback);
-
-    status = cairo_device_acquire (&device->drm.base);
-    if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	device->pipe->transfer_unmap (device->pipe,
-				      surface->map_transfer);
-	device->pipe->transfer_destroy (device->pipe,
-					surface->map_transfer);
-	surface->map_transfer = NULL;
-	cairo_device_release (&device->drm.base);
-    }
-
-    status = cairo_surface_status (surface->fallback);
-    cairo_surface_destroy (surface->fallback);
-    surface->fallback = NULL;
-
-    return status;
-}
-
-static cairo_int_status_t
-gallium_surface_paint (void			*abstract_surface,
-			  cairo_operator_t	 op,
-			  const cairo_pattern_t	*source,
-			  cairo_clip_t		*clip)
-{
-    gallium_surface_t *surface = abstract_surface;
-
-    if (surface->fallback == NULL) {
-	/* XXX insert magic */
-	surface->fallback = gallium_surface_map_to_image (surface);
-    }
-
-    return _cairo_surface_paint (surface->fallback, op, source, clip);
-}
-
-static cairo_int_status_t
-gallium_surface_mask (void			*abstract_surface,
-			 cairo_operator_t	 op,
-			 const cairo_pattern_t	*source,
-			 const cairo_pattern_t	*mask,
-			 cairo_clip_t		*clip)
-{
-    gallium_surface_t *surface = abstract_surface;
-
-    if (surface->fallback == NULL) {
-	/* XXX insert magic */
-	surface->fallback = gallium_surface_map_to_image (surface);
-    }
-
-    return _cairo_surface_mask (surface->fallback,
-				op, source, mask,
-				clip);
-}
-
-static cairo_int_status_t
-gallium_surface_stroke (void				*abstract_surface,
-			   cairo_operator_t		 op,
-			   const cairo_pattern_t	*source,
-			   cairo_path_fixed_t		*path,
-			   const cairo_stroke_style_t	*style,
-			   const cairo_matrix_t		*ctm,
-			   const cairo_matrix_t		*ctm_inverse,
-			   double			 tolerance,
-			   cairo_antialias_t		 antialias,
-			   cairo_clip_t			*clip)
-{
-    gallium_surface_t *surface = abstract_surface;
-
-    if (surface->fallback == NULL) {
-	/* XXX insert magic */
-	surface->fallback = gallium_surface_map_to_image (surface);
-    }
-
-    return _cairo_surface_stroke (surface->fallback,
-				  op, source,
-				  path, style,
-				  ctm, ctm_inverse,
-				  tolerance, antialias,
-				  clip);
-}
-
-static cairo_int_status_t
-gallium_surface_fill (void			*abstract_surface,
-			 cairo_operator_t	 op,
-			 const cairo_pattern_t	*source,
-			 cairo_path_fixed_t	*path,
-			 cairo_fill_rule_t	 fill_rule,
-			 double			 tolerance,
-			 cairo_antialias_t	 antialias,
-			 cairo_clip_t		*clip)
-{
-    gallium_surface_t *surface = abstract_surface;
-
-    if (surface->fallback == NULL) {
-	/* XXX insert magic */
-	surface->fallback = gallium_surface_map_to_image (surface);
-    }
-
-    return _cairo_surface_fill (surface->fallback,
-				op, source,
-				path, fill_rule,
-				tolerance, antialias,
-				clip);
-}
-
-static cairo_int_status_t
-gallium_surface_glyphs (void				*abstract_surface,
-			   cairo_operator_t		 op,
-			   const cairo_pattern_t	*source,
-			   cairo_glyph_t		*glyphs,
-			   int				 num_glyphs,
-			   cairo_scaled_font_t		*scaled_font,
-			   cairo_clip_t			*clip,
-			   int *num_remaining)
-{
-    gallium_surface_t *surface = abstract_surface;
-
-    *num_remaining = 0;
-
-    if (surface->fallback == NULL) {
-	/* XXX insert magic */
-	surface->fallback = gallium_surface_map_to_image (surface);
-    }
-
-    return _cairo_surface_show_text_glyphs (surface->fallback,
-					    op, source,
-					    NULL, 0,
-					    glyphs, num_glyphs,
-					    NULL, 0, 0,
-					    scaled_font,
-					    clip);
-}
-
-static const cairo_surface_backend_t gallium_surface_backend = {
-    CAIRO_SURFACE_TYPE_DRM,
-    _cairo_default_context_create,
-
-    gallium_surface_create_similar,
-    gallium_surface_finish,
-
-    NULL,
-    gallium_surface_acquire_source_image,
-    gallium_surface_release_source_image,
-
-    NULL, //gallium_surface_acquire_dest_image,
-    NULL, //gallium_surface_release_dest_image,
-    NULL, //gallium_surface_clone_similar,
-    NULL, //gallium_surface_composite,
-    NULL, //gallium_surface_fill_rectangles,
-    NULL, //gallium_surface_composite_trapezoids,
-    NULL, //gallium_surface_create_span_renderer,
-    NULL, //gallium_surface_check_span_renderer,
-    NULL, /* copy_page */
-    NULL, /* show_page */
-    _cairo_drm_surface_get_extents,
-    NULL, /* old_show_glyphs */
-    _cairo_drm_surface_get_font_options,
-    gallium_surface_flush,
-    NULL, /* mark_dirty_rectangle */
-    NULL, //gallium_surface_scaled_font_fini,
-    NULL, //gallium_surface_scaled_glyph_fini,
-
-    gallium_surface_paint,
-    gallium_surface_mask,
-    gallium_surface_stroke,
-    gallium_surface_fill,
-    gallium_surface_glyphs,
-
-    NULL, /* snapshot */
-
-    NULL, /* is_similar */
-
-    NULL, /* reset */
-};
-
-static int
-gallium_format_stride_for_width (enum pipe_format format, int width)
-{
-    int stride;
-
-    stride = 1024; /* XXX fugly */
-    while (stride < width)
-	stride *= 2;
-
-    if (format == PIPE_FORMAT_A8R8G8B8_UNORM)
-	stride *= 4;
-
-    return stride;
-}
-
-static cairo_drm_bo_t *
-_gallium_fake_bo_create (uint32_t size, uint32_t name)
-{
-    cairo_drm_bo_t *bo;
-
-    /* XXX integrate with winsys handle */
-
-    bo = _cairo_malloc (sizeof (cairo_drm_bo_t));
-
-    CAIRO_REFERENCE_COUNT_INIT (&bo->ref_count, 1);
-    bo->name = name;
-    bo->handle = 0;
-    bo->size = size;
-
-    return bo;
-}
-
-static void
-_gallium_fake_bo_release (void *dev, void *bo)
-{
-    free (bo);
-}
-
-static cairo_surface_t *
-gallium_surface_create_internal (gallium_device_t *device,
-				 enum pipe_format pipe_format,
-				 int width, int height)
-{
-    gallium_surface_t *surface;
-    struct pipe_resource template;
-    cairo_status_t status;
-    cairo_format_t format;
-    int stride, size;
-
-    surface = _cairo_malloc (sizeof (gallium_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    format = _cairo_format_from_pipe_format (pipe_format);
-    _cairo_surface_init (&surface->drm.base,
-			 &gallium_surface_backend,
-			 &device->drm.base,
-			 _cairo_content_from_format (format));
-    _cairo_drm_surface_init (&surface->drm, format, width, height);
-
-    stride = gallium_format_stride_for_width (pipe_format, width);
-    size = stride * height;
-
-    surface->drm.stride = stride;
-    surface->drm.bo = _gallium_fake_bo_create (size, 0);
-
-    memset(&template, 0, sizeof(template));
-    template.target = PIPE_TEXTURE_2D;
-    template.format = pipe_format;
-    template.width0 = width;
-    template.height0 = height;
-    template.depth0 = 1;
-    template.last_level = 0;
-    template.bind = PIPE_BIND_RENDER_TARGET;
-    surface->texture = device->screen->resource_create (device->screen,
-							&template);
-
-    if (unlikely (surface->texture == NULL)) {
-	status = _cairo_drm_surface_finish (&surface->drm);
-	free (surface);
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    }
-
-    surface->pipe_format = pipe_format;
-    surface->texture = NULL;
-
-    return &surface->drm.base;
-}
-
-static cairo_surface_t *
-gallium_surface_create (cairo_drm_device_t *base_dev,
-			cairo_format_t format,
-			int width, int height)
-{
-    gallium_device_t *device = (gallium_device_t *) base_dev;
-    cairo_surface_t *surface;
-    enum pipe_format pipe_format;
-    cairo_status_t status;
-
-    status = cairo_device_acquire (&device->drm.base);
-
-    if (MAX (width, height) > device->max_size) {
-	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
-	goto RELEASE;
-    }
-
-    pipe_format = pipe_format_from_format (format);
-    if (! format_is_supported_destination (device, pipe_format)) {
-	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-	goto RELEASE;
-    }
-
-    surface = gallium_surface_create_internal (device,
-					       pipe_format,
-					       width, height);
-
-RELEASE:
-    cairo_device_release (&device->drm.base);
-
-    return surface;
-}
-
-#if 0
-static cairo_surface_t *
-gallium_surface_create_for_name (cairo_drm_device_t *base_dev,
-				 unsigned int name,
-				 cairo_format_t format,
-				 int width, int height, int stride)
-{
-    gallium_device_t *device;
-    gallium_surface_t *surface;
-    cairo_status_t status;
-    cairo_content_t content;
-
-    surface = _cairo_malloc (sizeof (gallium_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    switch (format) {
-    default:
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-    case CAIRO_FORMAT_A8:
-	surface->pipe_format = PIPE_FORMAT_A8_UNORM;
-	break;
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_ARGB32:
-	surface->pipe_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-	break;
-    }
-
-    status = cairo_device_acquire (&device->drm.base);
-
-    if (MAX (width, height) > device->max_size) {
-	cairo_device_release (&device->drm.base);
-	free (surface);
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
-    }
-
-    if (! format_is_supported_destination (device, surface->pipe_format)) {
-	cairo_device_release (&device->drm.base);
-	free (surface);
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-    }
-
-    content = _cairo_content_from_format (format);
-    _cairo_surface_init (&surface->drm.base,
-			 &gallium_surface_backend,
-			 content);
-    _cairo_drm_surface_init (&surface->drm, base_dev);
-
-    surface->drm.bo = _gallium_fake_bo_create (height * stride, name);
-
-    surface->drm.width  = width;
-    surface->drm.height = height;
-    surface->drm.stride = stride;
-
-#if 0
-    /* XXX screen->create_from_handle */
-    surface->buffer = device->api->buffer_from_handle (device->api,
-						       device->screen,
-						       "cairo-gallium alien",
-						       name);
-    if (unlikely (surface->buffer == NULL)) {
-	status = _cairo_drm_surface_finish (&surface->drm);
-	cairo_device_release (&device->drm.base);
-	free (surface);
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    }
-#endif
-
-    surface->texture = NULL;
-
-    surface->fallback = NULL;
-
-    cairo_device_release (&device->drm.base);
-
-    return &surface->drm.base;
-}
-
-static cairo_int_status_t
-gallium_surface_flink (void *abstract_surface)
-{
-    gallium_surface_t *surface = abstract_surface;
-    gallium_device_t *device;
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
-
-    status = cairo_device_acquire (&device->drm.base);
-    if (! device->api->global_handle_from_buffer (device->api,
-						  device->screen,
-						  surface->buffer,
-						  &surface->drm.bo->name))
-    {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
-    cairo_device_release (&device->drm.base);
-
-    return status;
-}
-#endif
-
-static void
-gallium_device_destroy (void *abstract_device)
-{
-    gallium_device_t *device = abstract_device;
-
-    device->pipe->destroy (device->pipe);
-    device->screen->destroy (device->screen);
-    device->api->destroy (device->api);
-
-    dlclose (device->dlhandle);
-    free (device);
-}
-
-cairo_drm_device_t *
-_cairo_drm_gallium_device_create (int fd, dev_t dev, int vendor_id, int chip_id)
-{
-    gallium_device_t *device;
-    cairo_status_t status;
-    void *handle;
-    const char *libdir;
-    char buf[4096];
-    struct drm_api *(*ctor) (void);
-
-    /* XXX need search path + probe */
-    libdir = getenv ("CAIRO_GALLIUM_LIBDIR");
-    if (libdir == NULL)
-	libdir = "/usr/lib/dri";
-    buf[snprintf (buf, sizeof (buf)-1, "%s/i915_dri.so", libdir)] = '\0';
-
-    handle = dlopen (buf, RTLD_LAZY);
-    if (handle == NULL)
-	return NULL;
-
-    ctor = dlsym (handle, "drm_api_create");
-    if (ctor == NULL) {
-	dlclose (handle);
-	return NULL;
-    }
-
-    device = _cairo_malloc (sizeof (gallium_device_t));
-    if (device == NULL) {
-	dlclose (handle);
-	return _cairo_drm_device_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    }
-
-    device->dlhandle = handle;
-
-    device->drm.surface.create = gallium_surface_create;
-    device->drm.surface.create_for_name = NULL;
-    //device->drm.surface.create_for_name = gallium_surface_create_for_name;
-    device->drm.surface.enable_scan_out = NULL;
-    //device->drm.surface.flink = gallium_surface_flink;
-    device->drm.surface.flink = NULL;
-
-    device->drm.device.flush = NULL;
-    device->drm.device.throttle = NULL;
-    device->drm.device.destroy = gallium_device_destroy;
-
-    device->drm.bo.release = _gallium_fake_bo_release;
-
-    device->api = ctor ();
-    if (device->api == NULL) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto CLEANUP;
-    }
-
-    device->screen = device->api->create_screen (device->api, fd, NULL);
-    if (device->screen == NULL) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto CLEANUP_API;
-    }
-
-    device->max_size = 1 << device->screen->get_param (device->screen,
-						       PIPE_CAP_MAX_TEXTURE_2D_LEVELS);
-
-    device->pipe = device->screen->context_create (device->screen, device);
-    if (device->pipe == NULL) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto CLEANUP_SCREEN;
-    }
-
-    return _cairo_drm_device_init (&device->drm,
-				   fd, dev,
-				   0, 0,
-				   device->max_size);
-
-CLEANUP_SCREEN:
-    device->screen->destroy (device->screen);
-CLEANUP_API:
-    device->api->destroy (device->api);
-CLEANUP:
-    free (device);
-    dlclose (handle);
-    return _cairo_drm_device_create_in_error (status);
-}
diff --git a/src/drm/cairo-drm-i915-glyphs.c b/src/drm/cairo-drm-i915-glyphs.c
deleted file mode 100644
index 6fdcc0d2b..000000000
--- a/src/drm/cairo-drm-i915-glyphs.c
+++ /dev/null
@@ -1,566 +0,0 @@
-/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Red Hat, Inc.
- *
- * Contributor(s):
- *	Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-drm-i915-private.h"
-#include "cairo-error-private.h"
-#include "cairo-rtree-private.h"
-#include "cairo-clip-inline.h"
-
-static void
-i915_emit_glyph_rectangle_zero (i915_device_t *device,
-				i915_shader_t *shader,
-				int x1, int y1,
-				int x2, int y2,
-				intel_glyph_t *glyph)
-{
-    float *v;
-
-    /* Each vertex is:
-     *   2 vertex coordinates
-     */
-
-    v = i915_add_rectangle (device);
-    *v++ = x2; *v++ = y2;
-    *v++ = x1; *v++ = y2;
-    *v++ = x1; *v++ = y1;
-}
-
-static void
-i915_emit_glyph_rectangle_constant (i915_device_t *device,
-				    i915_shader_t *shader,
-				    int x1, int y1,
-				    int x2, int y2,
-				    intel_glyph_t *glyph)
-{
-    float *v;
-
-    /* Each vertex is:
-     *   2 vertex coordinates
-     *   2 glyph texture coordinates
-     */
-
-    v = i915_add_rectangle (device);
-
-    /* bottom right */
-    *v++ = x2; *v++ = y2;
-    *v++ = glyph->texcoord[0];
-
-    /* bottom left */
-    *v++ = x1; *v++ = y2;
-    *v++ = glyph->texcoord[1];
-
-    /* top left */
-    *v++ = x1; *v++ = y1;
-    *v++ = glyph->texcoord[2];
-}
-
-static void
-i915_emit_glyph_rectangle_general (i915_device_t *device,
-				   i915_shader_t *shader,
-				   int x1, int y1,
-				   int x2, int y2,
-				   intel_glyph_t *glyph)
-{
-    double s, t;
-    float *v;
-
-    /* Each vertex is:
-     *   2 vertex coordinates
-     *   [0-2] source texture coordinates
-     *   2 glyph texture coordinates
-     */
-
-    v = i915_add_rectangle (device);
-
-    /* bottom right */
-    *v++ = x2; *v++ = y2;
-    s = x2, t = y2;
-    switch (shader->source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*v++ = i915_shader_linear_texcoord (&shader->source.linear, s, t);
-	break;
-    case VS_TEXTURE:
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = s; *v++ = t;
-	break;
-    case VS_TEXTURE_16:
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    *v++ = glyph->texcoord[0];
-
-    /* bottom left */
-    *v++ = x1; *v++ = y2;
-    s = x1, t = y2;
-    switch (shader->source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*v++ = i915_shader_linear_texcoord (&shader->source.linear, s, t);
-	break;
-    case VS_TEXTURE:
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = s; *v++ = t;
-	break;
-    case VS_TEXTURE_16:
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    *v++ = glyph->texcoord[1];
-
-    /* top left */
-    *v++ = x1; *v++ = y1;
-    s = x1, t = y2;
-    switch (shader->source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*v++ = i915_shader_linear_texcoord (&shader->source.linear, s, t);
-	break;
-    case VS_TEXTURE:
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = s; *v++ = t;
-	break;
-    case VS_TEXTURE_16:
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    *v++ = glyph->texcoord[2];
-}
-
-typedef void
-(*i915_emit_glyph_rectangle_func_t) (i915_device_t *device,
-				     i915_shader_t *shader,
-				     int x1, int y1,
-				     int x2, int y2,
-				     intel_glyph_t *glyph);
-
-static cairo_status_t
-i915_surface_mask_internal (i915_surface_t *dst,
-			    cairo_operator_t		 op,
-			    const cairo_pattern_t	*source,
-			    i915_surface_t *mask,
-			    cairo_clip_t		*clip,
-			    const cairo_composite_rectangles_t *extents)
-{
-    i915_device_t *device;
-    i915_shader_t shader;
-    cairo_region_t *clip_region = NULL;
-    cairo_status_t status;
-
-    i915_shader_init (&shader, dst, op, 1.);
-
-    status = i915_shader_acquire_pattern (&shader, &shader.source,
-					  source, &extents->bounded);
-    if (unlikely (status))
-	return status;
-
-    shader.mask.type.vertex = VS_TEXTURE_16;
-    shader.mask.type.pattern = PATTERN_TEXTURE;
-    shader.mask.type.fragment = FS_TEXTURE;
-    shader.mask.base.content = mask->intel.drm.base.content;
-    shader.mask.base.texfmt = TEXCOORDFMT_2D_16;
-    shader.mask.base.n_samplers = 1;
-    shader.mask.base.sampler[0] =
-	(MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	i915_texture_filter (CAIRO_FILTER_NEAREST);
-    shader.mask.base.sampler[1] =
-	SS3_NORMALIZED_COORDS |
-	i915_texture_extend (CAIRO_EXTEND_NONE);
-
-    cairo_matrix_init_translate (&shader.mask.base.matrix,
-				 -extents->bounded.x,
-				 -extents->bounded.y);
-    cairo_matrix_scale (&shader.mask.base.matrix,
-			1. / mask->intel.drm.width,
-			1. / mask->intel.drm.height);
-
-    shader.mask.base.bo = intel_bo_reference (to_intel_bo (mask->intel.drm.bo));
-    shader.mask.base.offset[0] = 0;
-    shader.mask.base.map[0] = mask->map0;
-    shader.mask.base.map[1] = mask->map1;
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-
-	if (clip_region != NULL && cairo_region_num_rectangles (clip_region) == 1)
-	    clip_region = NULL;
-
-	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	    i915_shader_set_clip (&shader, clip);
-    }
-
-    status = cairo_device_acquire (dst->intel.drm.base.device);
-    if (unlikely (status))
-	goto CLEANUP_SHADER;
-
-    device = i915_device (dst);
-
-    status = i915_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto CLEANUP_DEVICE;
-
-    if (clip_region != NULL) {
-	unsigned int n, num_rectangles;
-
-	num_rectangles = cairo_region_num_rectangles (clip_region);
-	for (n = 0; n < num_rectangles; n++) {
-	    cairo_rectangle_int_t rect;
-
-	    cairo_region_get_rectangle (clip_region, n, &rect);
-
-	    shader.add_rectangle (&shader,
-				  rect.x, rect.y,
-				  rect.x + rect.width, rect.y + rect.height);
-	}
-    } else {
-	shader.add_rectangle (&shader,
-			      extents->bounded.x, extents->bounded.y,
-			      extents->bounded.x + extents->bounded.width,
-			      extents->bounded.y + extents->bounded.height);
-    }
-
-    if (! extents->is_bounded)
-	status = i915_fixup_unbounded (dst, extents, clip);
-
-CLEANUP_DEVICE:
-    cairo_device_release (&device->intel.base.base);
-CLEANUP_SHADER:
-    i915_shader_fini (&shader);
-    return status;
-}
-
-cairo_int_status_t
-i915_surface_glyphs (void			*abstract_surface,
-		     cairo_operator_t		 op,
-		     const cairo_pattern_t	*source,
-		     cairo_glyph_t		*glyphs,
-		     int			 num_glyphs,
-		     cairo_scaled_font_t	*scaled_font,
-		     cairo_clip_t		*clip,
-		     int *num_remaining)
-{
-    i915_surface_t *surface = abstract_surface;
-    i915_surface_t *mask = NULL;
-    i915_device_t *device;
-    i915_shader_t shader;
-    cairo_composite_rectangles_t extents;
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    cairo_bool_t overlap;
-    cairo_region_t *clip_region = NULL;
-    intel_bo_t *last_bo = NULL;
-    i915_emit_glyph_rectangle_func_t emit_func;
-    cairo_scaled_glyph_t *glyph_cache[64];
-    cairo_status_t status;
-    int mask_x = 0, mask_y = 0;
-    int i = 0;
-
-    *num_remaining = 0;
-    status = _cairo_composite_rectangles_init_for_glyphs (&extents,
-							  surface->intel.drm.width,
-							  surface->intel.drm.height,
-							  op, source,
-							  scaled_font,
-							  glyphs, num_glyphs,
-							  clip,
-							  &overlap);
-    if (unlikely (status))
-	return status;
-
-    if (_cairo_clip_contains_rectangle (clip, &extents.mask))
-	clip = NULL;
-
-    if (clip != NULL && extents.is_bounded) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	status = _cairo_clip_rectangle (clip, &extents.bounded);
-	if (unlikely (status))
-	    return status;
-
-	have_clip = TRUE;
-    }
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	if (unlikely (_cairo_status_is_error (status) ||
-		      status == CAIRO_INT_STATUS_NOTHING_TO_DO))
-	{
-	    if (have_clip)
-		_cairo_clip_fini (&local_clip);
-	    return status;
-	}
-    }
-
-    if (i915_surface_needs_tiling (surface)) {
-	ASSERT_NOT_REACHED;
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    if (overlap || ! extents.is_bounded) {
-	cairo_format_t format;
-
-	format = CAIRO_FORMAT_A8;
-	if (scaled_font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL)
-	    format = CAIRO_FORMAT_ARGB32;
-
-	mask = (i915_surface_t *)
-	    i915_surface_create_internal (&i915_device (surface)->intel.base,
-					  format,
-					  extents.bounded.width,
-					  extents.bounded.height,
-					  I915_TILING_DEFAULT,
-					  TRUE);
-	if (unlikely (mask->intel.drm.base.status))
-	    return mask->intel.drm.base.status;
-
-	status = i915_surface_clear (mask);
-	if (unlikely (status)) {
-	    cairo_surface_destroy (&mask->intel.drm.base);
-	    return status;
-	}
-
-	i915_shader_init (&shader, mask, CAIRO_OPERATOR_ADD, 1.);
-
-	status = i915_shader_acquire_pattern (&shader, &shader.source,
-					      &_cairo_pattern_white.base,
-					      &extents.bounded);
-	if (unlikely (status)) {
-	    cairo_surface_destroy (&mask->intel.drm.base);
-	    return status;
-	}
-
-	mask_x = -extents.bounded.x;
-	mask_y = -extents.bounded.y;
-    } else {
-	i915_shader_init (&shader, surface, op, 1.);
-
-	status = i915_shader_acquire_pattern (&shader, &shader.source,
-					      source, &extents.bounded);
-	if (unlikely (status))
-	    return status;
-
-	if (clip != NULL) {
-	    status = _cairo_clip_get_region (clip, &clip_region);
-
-	    if (clip_region != NULL && cairo_region_num_rectangles (clip_region) == 1)
-		clip_region = NULL;
-
-	    if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-		i915_shader_set_clip (&shader, clip);
-	}
-    }
-
-    shader.mask.type.fragment = FS_TEXTURE;
-    shader.mask.base.content = CAIRO_CONTENT_ALPHA; /* XXX */
-    shader.mask.base.texfmt = TEXCOORDFMT_2D_16;
-    shader.mask.base.n_samplers = 1;
-    shader.mask.base.sampler[0] =
-	(MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	i915_texture_filter (CAIRO_FILTER_NEAREST);
-    shader.mask.base.sampler[1] =
-	SS3_NORMALIZED_COORDS |
-	i915_texture_extend (CAIRO_EXTEND_NONE);
-
-    switch (shader.source.type.vertex) {
-    case VS_ZERO:
-	emit_func = i915_emit_glyph_rectangle_zero;
-	break;
-    case VS_CONSTANT:
-	emit_func = i915_emit_glyph_rectangle_constant;
-	break;
-    default:
-    case VS_LINEAR:
-    case VS_TEXTURE:
-    case VS_TEXTURE_16:
-	emit_func = i915_emit_glyph_rectangle_general;
-	break;
-    }
-
-    status = cairo_device_acquire (surface->intel.drm.base.device);
-    if (unlikely (status))
-	goto CLEANUP_SHADER;
-
-    device = i915_device (surface);
-
-    _cairo_scaled_font_freeze_cache (scaled_font);
-    if (scaled_font->surface_private == NULL) {
-	scaled_font->surface_private = device;
-	scaled_font->surface_backend = surface->intel.drm.base.backend;
-	cairo_list_add (&scaled_font->link, &device->intel.fonts);
-    }
-
-    memset (glyph_cache, 0, sizeof (glyph_cache));
-
-    for (i = 0; i < num_glyphs; i++) {
-	cairo_scaled_glyph_t *scaled_glyph;
-	int x, y, x1, x2, y1, y2;
-	int cache_index = glyphs[i].index % ARRAY_LENGTH (glyph_cache);
-	intel_glyph_t *glyph;
-
-	scaled_glyph = glyph_cache[cache_index];
-	if (scaled_glyph == NULL ||
-	    _cairo_scaled_glyph_index (scaled_glyph) != glyphs[i].index)
-	{
-	    status = _cairo_scaled_glyph_lookup (scaled_font,
-						 glyphs[i].index,
-						 CAIRO_SCALED_GLYPH_INFO_METRICS,
-						 NULL, /* foreground color */
-						 &scaled_glyph);
-	    if (unlikely (status))
-		goto FINISH;
-
-	    glyph_cache[cache_index] = scaled_glyph;
-	}
-
-	if (unlikely (scaled_glyph->metrics.width  == 0 ||
-		      scaled_glyph->metrics.height == 0))
-	{
-	    continue;
-	}
-
-	/* XXX glyph images are snapped to pixel locations */
-	x = _cairo_lround (glyphs[i].x);
-	y = _cairo_lround (glyphs[i].y);
-
-	x1 = x + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x);
-	y1 = y + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y);
-	x2 = x + _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.x);
-	y2 = y + _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.y);
-
-	if (x2 < extents.bounded.x ||
-	    y2 < extents.bounded.y ||
-	    x1 > extents.bounded.x + extents.bounded.width ||
-	    y1 > extents.bounded.y + extents.bounded.height)
-	{
-	    continue;
-	}
-
-	if (scaled_glyph->surface_private == NULL) {
-	    status = intel_get_glyph (&device->intel, scaled_font, scaled_glyph);
-	    if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO)) {
-		status = CAIRO_STATUS_SUCCESS;
-		continue;
-	    }
-	    if (unlikely (status))
-		goto FINISH;
-	}
-
-	glyph = intel_glyph_pin (scaled_glyph->surface_private);
-	if (glyph->cache->buffer.bo != last_bo) {
-	    intel_buffer_cache_t *cache = glyph->cache;
-
-	    shader.mask.base.bo = cache->buffer.bo;
-	    shader.mask.base.offset[0] = cache->buffer.offset;
-	    shader.mask.base.map[0] = cache->buffer.map0;
-	    shader.mask.base.map[1] = cache->buffer.map1;
-	    shader.mask.base.content = CAIRO_CONTENT_ALPHA; /* XXX */
-
-	    status = i915_shader_commit (&shader, device);
-	    if (unlikely (status))
-		goto FINISH;
-
-	    last_bo = cache->buffer.bo;
-	}
-
-	x2 = x1 + glyph->width;
-	y2 = y1 + glyph->height;
-
-	if (mask_x)
-	    x1 += mask_x, x2 += mask_x;
-	if (mask_y)
-	    y1 += mask_y, y2 += mask_y;
-
-	/* XXX clip glyph */
-	emit_func (device, &shader, x1, y1, x2, y2, glyph);
-    }
-
-    status = CAIRO_STATUS_SUCCESS;
-  FINISH:
-    _cairo_scaled_font_thaw_cache (scaled_font);
-    cairo_device_release (surface->intel.drm.base.device);
-  CLEANUP_SHADER:
-    i915_shader_fini (&shader);
-
-    if (unlikely (status == CAIRO_INT_STATUS_UNSUPPORTED)) {
-	cairo_path_fixed_t path;
-
-	_cairo_path_fixed_init (&path);
-	status = _cairo_scaled_font_glyph_path (scaled_font,
-						glyphs + i, num_glyphs - i,
-						&path);
-	if (mask_x | mask_y) {
-	    _cairo_path_fixed_translate (&path,
-					 _cairo_fixed_from_int (mask_x),
-					 _cairo_fixed_from_int (mask_y));
-	}
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = surface->intel.drm.base.backend->fill (shader.target,
-							    shader.op,
-							    mask != NULL ? &_cairo_pattern_white.base : source,
-							    &path,
-							    CAIRO_FILL_RULE_WINDING,
-							    0,
-							    scaled_font->options.antialias,
-							    clip);
-	}
-	_cairo_path_fixed_fini (&path);
-    }
-
-    if (mask != NULL) {
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = i915_surface_mask_internal (surface, op, source, mask,
-					         clip, &extents);
-	}
-	cairo_surface_finish (&mask->intel.drm.base);
-	cairo_surface_destroy (&mask->intel.drm.base);
-    }
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
diff --git a/src/drm/cairo-drm-i915-private.h b/src/drm/cairo-drm-i915-private.h
deleted file mode 100644
index 7585756dc..000000000
--- a/src/drm/cairo-drm-i915-private.h
+++ /dev/null
@@ -1,1270 +0,0 @@
-/*
- * Copyright © 2006, 2009 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 at anholt.net>
- *    Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#ifndef CAIRO_DRM_I915_PRIVATE_H
-#define CAIRO_DRM_I915_PRIVATE_H
-
-#include "cairo-types-private.h"
-
-#include "cairo-drm-private.h"
-#include "cairo-drm-intel-private.h"
-#include "cairo-drm-intel-command-private.h"
-#include "cairo-drm-intel-ioctl-private.h"
-#include "cairo-freelist-private.h"
-
-#include <setjmp.h>
-
-#define I915_VERBOSE 1
-
-#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_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         ((int)(1u<<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         ((int)(1u<<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 i915_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 i915_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 i915_fs_operand_reg(reg)					\
-    i915_fs_operand(reg, X, Y, Z, W)
-
-#define i915_fs_operand_reg_negate(reg)					\
-    i915_fs_operand(reg, NEG_X, NEG_Y, NEG_Z, NEG_W)
-
-/*
- * Returns an operand containing (0.0, 0.0, 0.0, 0.0).
- */
-#define i915_fs_operand_zero() i915_fs_operand(FS_R0, ZERO, ZERO, ZERO, ZERO)
-
-/*
- * Returns an unused operand
- */
-#define i915_fs_operand_none() i915_fs_operand_zero()
-
-/*
- * Returns an operand containing (1.0, 1.0, 1.0, 1.0).
- */
-#define i915_fs_operand_one() i915_fs_operand(FS_R0, ONE, ONE, ONE, ONE)
-
-#define i915_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 i915_fs_dcl(reg)						\
-do {									\
-    OUT_DWORD (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_DWORD (0); \
-    OUT_DWORD (0); \
-} while (0)
-
-#define i915_fs_texld(dest_reg, sampler_reg, address_reg)		\
-do {									\
-    OUT_DWORD (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_DWORD((REG_TYPE(address_reg) << T1_ADDRESS_REG_TYPE_SHIFT) | \
-              (REG_NR(address_reg) << T1_ADDRESS_REG_NR_SHIFT)); \
-    OUT_DWORD (0); \
-} while (0)
-
-#define i915_fs_arith_masked(op, dest_reg, dest_mask, operand0, operand1, operand2)	\
-    _i915_fs_arith_masked(A0_##op, dest_reg, dest_mask, operand0, operand1, operand2)
-
-#define i915_fs_arith(op, dest_reg, operand0, operand1, operand2)	\
-    _i915_fs_arith(A0_##op, dest_reg, operand0, operand1, operand2)
-
-#define _i915_fs_arith_masked(cmd, dest_reg, dest_mask, operand0, operand1, operand2) \
-do { \
-    /* Set up destination register and write mask */ \
-    OUT_DWORD (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_DWORD (i915_get_hardware_channel_val(REG_X(operand0), \
-					      A1_SRC0_CHANNEL_X_SHIFT, \
-					      A1_SRC0_CHANNEL_X_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Y(operand0), \
-					      A1_SRC0_CHANNEL_Y_SHIFT, \
-					      A1_SRC0_CHANNEL_Y_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Z(operand0), \
-					      A1_SRC0_CHANNEL_Z_SHIFT, \
-					      A1_SRC0_CHANNEL_Z_NEGATE) | \
-               i915_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) | \
-               i915_get_hardware_channel_val(REG_X(operand1), \
-					      A1_SRC1_CHANNEL_X_SHIFT, \
-					      A1_SRC1_CHANNEL_X_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Y(operand1), \
-					      A1_SRC1_CHANNEL_Y_SHIFT, \
-					      A1_SRC1_CHANNEL_Y_NEGATE)); \
-    OUT_DWORD (i915_get_hardware_channel_val(REG_Z(operand1), \
-					      A2_SRC1_CHANNEL_Z_SHIFT, \
-					      A2_SRC1_CHANNEL_Z_NEGATE) | \
-	       i915_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) | \
-               i915_get_hardware_channel_val(REG_X(operand2), \
-					      A2_SRC2_CHANNEL_X_SHIFT, \
-					      A2_SRC2_CHANNEL_X_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Y(operand2), \
-					      A2_SRC2_CHANNEL_Y_SHIFT, \
-					      A2_SRC2_CHANNEL_Y_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Z(operand2), \
-					      A2_SRC2_CHANNEL_Z_SHIFT, \
-					      A2_SRC2_CHANNEL_Z_NEGATE) | \
-               i915_get_hardware_channel_val(REG_W(operand2), \
-					       A2_SRC2_CHANNEL_W_SHIFT, \
-					       A2_SRC2_CHANNEL_W_NEGATE)); \
-} while (0)
-
-#define _i915_fs_arith(cmd, dest_reg, operand0, operand1, operand2) do {\
-    /* Set up destination register and write mask */ \
-    OUT_DWORD (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_DWORD (i915_get_hardware_channel_val(REG_X(operand0), \
-					      A1_SRC0_CHANNEL_X_SHIFT, \
-					      A1_SRC0_CHANNEL_X_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Y(operand0), \
-					      A1_SRC0_CHANNEL_Y_SHIFT, \
-					      A1_SRC0_CHANNEL_Y_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Z(operand0), \
-					      A1_SRC0_CHANNEL_Z_SHIFT, \
-					      A1_SRC0_CHANNEL_Z_NEGATE) | \
-               i915_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) | \
-               i915_get_hardware_channel_val(REG_X(operand1), \
-					      A1_SRC1_CHANNEL_X_SHIFT, \
-					      A1_SRC1_CHANNEL_X_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Y(operand1), \
-					      A1_SRC1_CHANNEL_Y_SHIFT, \
-					      A1_SRC1_CHANNEL_Y_NEGATE)); \
-    OUT_DWORD (i915_get_hardware_channel_val(REG_Z(operand1), \
-					      A2_SRC1_CHANNEL_Z_SHIFT, \
-					      A2_SRC1_CHANNEL_Z_NEGATE) | \
-	       i915_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) | \
-               i915_get_hardware_channel_val(REG_X(operand2), \
-					      A2_SRC2_CHANNEL_X_SHIFT, \
-					      A2_SRC2_CHANNEL_X_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Y(operand2), \
-					      A2_SRC2_CHANNEL_Y_SHIFT, \
-					      A2_SRC2_CHANNEL_Y_NEGATE) | \
-               i915_get_hardware_channel_val(REG_Z(operand2), \
-					      A2_SRC2_CHANNEL_Z_SHIFT, \
-					      A2_SRC2_CHANNEL_Z_NEGATE) | \
-               i915_get_hardware_channel_val(REG_W(operand2), \
-					       A2_SRC2_CHANNEL_W_SHIFT, \
-					       A2_SRC2_CHANNEL_W_NEGATE)); \
-} while (0)
-
-#define i915_fs_mov(dest_reg, operand0)					\
-    i915_fs_arith(MOV, dest_reg, \
-	          operand0,			\
-	          i915_fs_operand_none(),			\
-	          i915_fs_operand_none())
-
-#define i915_fs_mov_masked(dest_reg, dest_mask, operand0)		\
-    i915_fs_arith_masked (MOV, dest_reg, dest_mask, \
-	                  operand0, \
-	                  i915_fs_operand_none(), \
-	                  i915_fs_operand_none())
-
-
-#define i915_fs_frc(dest_reg, operand0)					\
-    i915_fs_arith (FRC, dest_reg, \
-	           operand0,			\
-	           i915_fs_operand_none(),			\
-	           i915_fs_operand_none())
-
-/* Add operand0 and operand1 and put the result in dest_reg */
-#define i915_fs_add(dest_reg, operand0, operand1)			\
-    i915_fs_arith (ADD, dest_reg, \
-	           operand0, operand1,	\
-		   i915_fs_operand_none())
-
-/* Multiply operand0 and operand1 and put the result in dest_reg */
-#define i915_fs_mul(dest_reg, operand0, operand1)			\
-    i915_fs_arith (MUL, dest_reg, \
-	           operand0, operand1,	\
-		   i915_fs_operand_none())
-
-/* Computes 1/sqrt(operand0.replicate_swizzle) puts the result in dest_reg */
-#define i915_fs_rsq(dest_reg, dest_mask, operand0)		\
-do {									\
-    if (dest_mask) {							\
-	i915_fs_arith_masked (RSQ, dest_reg, dest_mask, \
-		              operand0,			\
-			      i915_fs_operand_none (),			\
-			      i915_fs_operand_none ());			\
-    } else { \
-	i915_fs_arith (RSQ, dest_reg, \
-		       operand0, \
-		       i915_fs_operand_none (), \
-		       i915_fs_operand_none ()); \
-    } \
-} while (0)
-
-/* Puts the minimum of operand0 and operand1 in dest_reg */
-#define i915_fs_min(dest_reg, operand0, operand1)			\
-    i915_fs_arith (MIN, dest_reg, \
-	           operand0, operand1, \
-		   i915_fs_operand_none())
-
-/* Puts the maximum of operand0 and operand1 in dest_reg */
-#define i915_fs_max(dest_reg, operand0, operand1)			\
-    i915_fs_arith (MAX, dest_reg, \
-	           operand0, operand1, \
-	           i915_fs_operand_none())
-
-#define i915_fs_cmp(dest_reg, operand0, operand1, operand2)		\
-    i915_fs_arith (CMP, dest_reg, operand0, operand1, operand2)
-
-/* Perform operand0 * operand1 + operand2 and put the result in dest_reg */
-#define i915_fs_mad(dest_reg, dest_mask, op0, op1, op2)	\
-do {									\
-    if (dest_mask) {							\
-	i915_fs_arith_masked (MAD, dest_reg, dest_mask, op0, op1, op2); \
-    } else { \
-	i915_fs_arith (MAD, dest_reg, op0, op1, op2); \
-    } \
-} while (0)
-
-#define i915_fs_dp2add(dest_reg, dest_mask, op0, op1, op2)	\
-do {									\
-    if (dest_mask) {							\
-	i915_fs_arith_masked (DP2ADD, dest_reg, dest_mask, op0, op1, op2); \
-    } else { \
-	i915_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 i915_fs_dp3(dest_reg, dest_mask, op0, op1)	\
-do {									\
-    if (dest_mask) {							\
-	i915_fs_arith_masked (DP3, dest_reg, dest_mask, \
-		              op0, op1,\
-		              i915_fs_operand_none());			\
-    } else { \
-	i915_fs_arith (DP3, dest_reg, op0, op1,\
-		       i915_fs_operand_none());			\
-    } \
-} while (0)
-
-static inline uint32_t cairo_const
-i915_fs_operand_pure_alpha (int pure)
-{
-    if (pure & (1 << 3))
-	return i915_fs_operand_one ();
-    else
-	return i915_fs_operand_zero ();
-}
-
-#define I915_TILING_DEFAULT I915_TILING_Y
-#define I915_BO_CACHE_BUCKETS 13 /* cache surfaces up to 16 MiB */
-
-typedef struct i915_surface i915_surface_t;
-typedef struct i915_device i915_device_t;
-typedef struct i915_shader i915_shader_t;
-
-typedef void (*i915_add_rectangle_func_t) (const i915_shader_t *shader,
-					   int x, int y,
-					   int w, int h);
-
-#define IMAGE_CACHE_WIDTH 1024
-#define IMAGE_CACHE_HEIGHT 1024
-
-typedef struct i915_image_private {
-    cairo_rtree_node_t node;
-    intel_buffer_cache_t *container;
-} i915_image_private_t;
-
-#define I915_BATCH_SIZE (128*1024)
-#define I915_VBO_SIZE (512*1024)
-#define I915_MAX_RELOCS 2048
-
-enum {
-    I915_DEBUG_EXEC = 0x1,
-    I915_DEBUG_SYNC = 0x2,
-    I915_DEBUG_BATCH = 0x4,
-    I915_DEBUG_BUFFER = 0x8,
-    I915_DEBUG_BUFFER_CACHE = 0x10,
-    I915_DEBUG_BUFFER_ALLOC = 0x20,
-    I915_DEBUG_GLYPHS = 0x40,
-    I915_DEBUG_MAP = 0x80,
-    I915_DEBUG_THROTTLE = 0x100,
-};
-
-struct i915_device {
-    intel_device_t intel;
-
-    cairo_bool_t debug;
-
-    i915_shader_t *shader; /* note: only valid during geometry emission */
-
-    struct i915_batch {
-	intel_bo_t *target_bo[I915_MAX_RELOCS];
-	size_t gtt_avail_size;
-	size_t est_gtt_size;
-	size_t total_gtt_size;
-
-	uint16_t fences;
-	uint16_t fences_avail;
-	uint16_t reloc_count;
-	uint16_t exec_count;
-	uint16_t used;
-
-	struct drm_i915_gem_exec_object2 exec[I915_MAX_RELOCS];
-	struct drm_i915_gem_relocation_entry reloc[I915_MAX_RELOCS];
-    } batch;
-
-    uint32_t vbo;
-    uint32_t vbo_offset;
-    uint32_t vbo_used;
-    uint32_t vbo_max_index;
-    uint32_t vertex_index;
-    uint32_t vertex_count;
-    uint32_t floats_per_vertex;
-    uint32_t rectangle_size;
-    intel_bo_t *last_vbo;
-    uint32_t last_vbo_offset;
-    uint32_t last_vbo_space;
-
-    i915_surface_t *current_target;
-    uint32_t current_size;
-    uint32_t current_diffuse;
-    uint32_t current_colorbuf;
-    uint32_t *current_source;
-    uint32_t *current_mask;
-    uint32_t *current_clip;
-    uint32_t current_program;
-    uint32_t current_texcoords;
-    uint32_t current_blend;
-    uint32_t current_constants[8*4];
-    uint32_t current_n_constants;
-    uint32_t current_samplers[2*4];
-    uint32_t current_maps[4*4];
-    uint32_t current_n_samplers;
-    uint32_t current_n_maps;
-    uint32_t last_source_fragment;
-    uint32_t clear_alpha;
-
-    cairo_list_t image_caches[2];
-
-    uint32_t batch_header[13];
-    uint32_t batch_base[I915_BATCH_SIZE / sizeof (uint32_t)];
-    uint8_t vbo_base[I915_VBO_SIZE];
-};
-
-enum {
-    CURRENT_SOURCE = 0x1,
-    CURRENT_MASK = 0x2,
-    CURRENT_CLIP = 0x4
-};
-
-typedef enum {
-    VS_ZERO,
-    VS_CONSTANT,
-    VS_LINEAR,
-    VS_TEXTURE,
-    VS_TEXTURE_16,
-} i915_vertex_shader_t;
-
-typedef enum {
-    FS_ZERO,
-    FS_ONE,
-    FS_PURE,
-    FS_CONSTANT,
-    FS_DIFFUSE,
-    FS_LINEAR,
-    FS_RADIAL,
-    FS_TEXTURE,
-    FS_YUV,
-    FS_SPANS,
-} i915_fragment_shader_t;
-
-#define FS_DETAILS_SHIFT 4
-
-typedef enum {
-    PATTERN_BASE,
-    PATTERN_CONSTANT,
-    PATTERN_LINEAR,
-    PATTERN_RADIAL,
-    PATTERN_TEXTURE,
-} i915_shader_channel_t;
-
-struct i915_surface {
-    intel_surface_t intel;
-
-    uint32_t map0, map1;
-    uint32_t colorbuf;
-
-    cairo_bool_t deferred_clear;
-    uint32_t offset;
-    uint32_t is_current_texture;
-
-    i915_image_private_t *cache;
-
-    intel_bo_t *stencil;
-    uint32_t stencil_stride;
-    uint32_t stencil_offset;
-};
-
-typedef enum {
-    NONE = 0,
-    YUV_I420,
-    /* XXX */
-    YUV_YV12,
-    YUV_YUY2,
-    YUV_UYVY,
-} i915_packed_pixel_t;
-
-/* read-only container */
-#define I915_PACKED_PIXEL_SURFACE_TYPE 0x1000
-typedef struct i915_packed_pixel_surface {
-    cairo_surface_t base;
-
-    i915_packed_pixel_t pixel;
-
-    i915_device_t *device;
-    intel_bo_t *bo;
-    uint32_t is_current_texture;
-
-    uint32_t offset[4];
-    uint32_t stride[4];
-    uint32_t width[4];
-    uint32_t height[4];
-    uint32_t map0[4], map1[4];
-} i915_packed_pixel_surface_t;
-
-struct i915_shader {
-    i915_device_t *device;
-    i915_surface_t *target;
-
-    cairo_operator_t op;
-    uint32_t blend;
-    float opacity;
-    cairo_content_t content;
-
-    cairo_bool_t committed;
-    cairo_bool_t need_combine;
-
-    i915_add_rectangle_func_t add_rectangle;
-
-    union i915_shader_channel {
-	struct {
-	    i915_vertex_shader_t vertex;
-	    i915_fragment_shader_t fragment;
-	    i915_shader_channel_t pattern;
-	} type;
-	struct i915_shader_base {
-	    i915_vertex_shader_t vertex;
-	    i915_fragment_shader_t fragment;
-	    i915_shader_channel_t pattern;
-	    uint32_t texfmt;
-	    cairo_content_t content;
-	    uint32_t mode;
-	    intel_bo_t *bo;
-	    uint32_t n_samplers;
-	    uint32_t offset[4];
-	    uint32_t map[2*4];
-	    uint32_t sampler[2];
-	    cairo_matrix_t matrix;
-	} base;
-	struct i915_shader_solid {
-	    struct i915_shader_base base;
-	    cairo_color_t color;
-	    int pure;
-	} solid;
-	struct i915_shader_linear {
-	    struct i915_shader_base base;
-	    struct {
-		float red, green, blue, alpha;
-	    } color0, color1;
-	    float dx, dy, offset;
-	} linear;
-	struct i915_shader_radial {
-	    struct i915_shader_base base;
-	    float constants[8];
-	} radial;
-	struct i915_shader_surface {
-	    struct i915_shader_base base;
-	    i915_packed_pixel_t pixel;
-	} surface;
-    } source, mask, clip, dst;
-
-    jmp_buf unwind;
-};
-
-enum i915_shader_linear_mode {
-    /* XXX REFLECT */
-    LINEAR_TEXTURE,
-    LINEAR_NONE,
-    LINEAR_REPEAT,
-    LINEAR_PAD,
-};
-
-enum i915_shader_radial_mode {
-    RADIAL_ONE,
-    RADIAL_TWO
-};
-
-typedef cairo_status_t
-(*i915_spans_func_t) (void			*closure,
-		      cairo_span_renderer_t	*renderer,
-		      const cairo_rectangle_int_t	*extents);
-
-cairo_private cairo_status_t
-i915_clip_and_composite_spans (i915_surface_t		*dst,
-			       cairo_operator_t		 op,
-			       const cairo_pattern_t	*pattern,
-			       cairo_antialias_t	 antialias,
-			       i915_spans_func_t	 draw_func,
-			       void			*draw_closure,
-			       const cairo_composite_rectangles_t*extents,
-			       cairo_clip_t		*clip,
-			       double			 opacity);
-
-cairo_private cairo_surface_t *
-i915_surface_create_internal (cairo_drm_device_t *base_dev,
-		              cairo_format_t format,
-			      int width, int height,
-			      uint32_t tiling,
-			      cairo_bool_t gpu_target);
-
-cairo_private i915_surface_t *
-i915_surface_create_from_cacheable_image_internal (i915_device_t *device,
-						   cairo_image_surface_t *image);
-
-cairo_private void
-i915_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font);
-
-cairo_private cairo_int_status_t
-i915_surface_glyphs (void			*abstract_surface,
-		     cairo_operator_t		 op,
-		     const cairo_pattern_t	*source,
-		     cairo_glyph_t		*glyphs,
-		     int			 num_glyphs,
-		     cairo_scaled_font_t	*scaled_font,
-		     cairo_clip_t		*clip,
-		     int *num_remaining);
-
-static inline int cairo_const
-i915_tiling_height (uint32_t tiling, int height)
-{
-    switch (tiling) {
-    default:
-    case I915_TILING_NONE: return (height + 1) & -2;
-    case I915_TILING_X: return (height + 7) & -8;
-    case I915_TILING_Y: return (height + 31) & -32;
-    }
-}
-
-static inline uint32_t cairo_const
-i915_tiling_stride (int format, uint32_t stride)
-{
-    uint32_t tile_width;
-
-    /* use 64B alignment so that the buffer may be used as a scanout */
-    if (format == I915_TILING_NONE)
-	return (stride + 63) & -64;
-
-    tile_width = 512;
-    /* XXX Currently the kernel enforces a tile_width of 512 for TILING_Y.
-
-       <jbarnes> the docs are a bit confused on that front
-       <jbarnes> once we enable it on 915 we'll find out what the tile width size should be in the fence setup
-       <jbarnes> it could be that 915 has y tiling but that the minimum width is 512 or something
-       <jbarnes> yeah it's probably 128 on 915 also
-       <jbarnes> it's just that we haven't tested
-       <jbarnes> but I wasn't thinking that the tile widths were the same
-       <jbarnes> only that in order to fence y tiles on 915 you needed pitch to be a multiple of 4 y tiles (or something like that)
-
-       tile_width = format == I915_TILING_Y ? 128 : 512;
-    */
-
-    /* needs a pot tile width */
-    while (tile_width < stride)
-	tile_width <<= 1;
-
-    return tile_width;
-}
-
-static inline uint32_t cairo_const
-i915_tiling_size (uint32_t tiling, uint32_t size)
-{
-    uint32_t fence;
-
-    if (tiling == I915_TILING_NONE)
-	return (size + 4095) & -4096;
-
-    fence = 1024 * 1024; /* 1 MiB */
-    while (fence < size)
-	fence <<= 1;
-
-    return fence;
-}
-
-static inline cairo_bool_t cairo_const
-i915_texture_filter_is_nearest (cairo_filter_t filter)
-{
-    switch (filter) {
-    case CAIRO_FILTER_BEST:
-    case CAIRO_FILTER_GOOD:
-    case CAIRO_FILTER_BILINEAR:
-    case CAIRO_FILTER_GAUSSIAN:
-	return FALSE;
-    default:
-    case CAIRO_FILTER_FAST:
-    case CAIRO_FILTER_NEAREST:
-	return TRUE;
-    }
-}
-
-static inline uint32_t cairo_const
-i915_texture_filter (cairo_filter_t filter)
-{
-    switch (filter) {
-    case CAIRO_FILTER_BEST:
-    case CAIRO_FILTER_GOOD:
-    case CAIRO_FILTER_BILINEAR:
-    case CAIRO_FILTER_GAUSSIAN:
-        return
-	    (FILTER_LINEAR << SS2_MAG_FILTER_SHIFT) |
-	    (FILTER_LINEAR << SS2_MIN_FILTER_SHIFT);
-    default:
-    case CAIRO_FILTER_FAST:
-    case CAIRO_FILTER_NEAREST:
-	return
-	    (FILTER_NEAREST << SS2_MAG_FILTER_SHIFT) |
-	    (FILTER_NEAREST << SS2_MIN_FILTER_SHIFT);
-    }
-}
-
-static inline uint32_t cairo_const
-i915_texture_extend (cairo_extend_t extend)
-{
-    switch (extend) {
-    default:
-    case CAIRO_EXTEND_NONE:
-	return
-	    (TEXCOORDMODE_CLAMP_BORDER << SS3_TCX_ADDR_MODE_SHIFT) |
-	    (TEXCOORDMODE_CLAMP_BORDER << SS3_TCY_ADDR_MODE_SHIFT);
-    case CAIRO_EXTEND_REPEAT:
-	return
-	    (TEXCOORDMODE_WRAP << SS3_TCX_ADDR_MODE_SHIFT) |
-	    (TEXCOORDMODE_WRAP << SS3_TCY_ADDR_MODE_SHIFT);
-    case CAIRO_EXTEND_PAD:
-	return
-	    (TEXCOORDMODE_CLAMP_EDGE << SS3_TCX_ADDR_MODE_SHIFT) |
-	    (TEXCOORDMODE_CLAMP_EDGE << SS3_TCY_ADDR_MODE_SHIFT);
-    case CAIRO_EXTEND_REFLECT:
-	return
-	    (TEXCOORDMODE_MIRROR << SS3_TCX_ADDR_MODE_SHIFT) |
-	    (TEXCOORDMODE_MIRROR << SS3_TCY_ADDR_MODE_SHIFT);
-    }
-}
-
-static inline uint32_t cairo_const
-BUF_tiling (uint32_t tiling)
-{
-    switch (tiling) {
-    default:
-    case I915_TILING_NONE: return 0;
-    case I915_TILING_X: return BUF_3D_TILED_SURFACE | BUF_3D_TILE_WALK_X;
-    case I915_TILING_Y: return BUF_3D_TILED_SURFACE | BUF_3D_TILE_WALK_Y;
-    }
-}
-
-#define OUT_DWORD(dword) i915_batch_emit_dword (device, dword)
-#define OUT_RELOC(surface, read, write) i915_batch_emit_reloc (device, to_intel_bo (surface->intel.drm.bo), surface->offset, read, write, FALSE)
-#define OUT_RELOC_FENCED(surface, read, write) i915_batch_emit_reloc (device, to_intel_bo (surface->intel.drm.bo), surface->offset, read, write, TRUE)
-
-#define FS_LOCALS							\
-    uint32_t *_shader_start
-
-#define FS_BEGIN()							\
-do {									\
-    _shader_start = BATCH_PTR (device);					\
-    OUT_DWORD (_3DSTATE_PIXEL_SHADER_PROGRAM);				\
-} while (0)
-
-#define FS_END()							\
-do {									\
-    *_shader_start |= BATCH_PTR (device) - _shader_start - 2;		\
-} while (0);
-
-static inline int32_t
-i915_batch_space (i915_device_t *device)
-{
-    /* leave room for RECTLIST(4) + MI_BUFFER_END + MI_NOOP */
-    return sizeof (device->batch_base) - (device->batch.used << 2) - 32;
-}
-
-static inline cairo_bool_t
-i915_check_aperture_size (const i915_device_t *device, int relocs, size_t est_size, size_t size)
-{
-    return device->batch.reloc_count + relocs < I915_MAX_RELOCS - 2 &&
-	   device->batch.est_gtt_size + est_size <= device->batch.gtt_avail_size &&
-	   device->batch.total_gtt_size + size <= device->intel.gtt_avail_size;
-}
-
-static inline cairo_bool_t
-i915_check_aperture (const i915_device_t *device, intel_bo_t **bo_array, int count)
-{
-    uint32_t relocs = 0, est_size = 0, size = 0;
-
-    while (count--) {
-	const intel_bo_t *bo = *bo_array++;
-	if (bo->exec == NULL) {
-	    relocs++;
-	    size += bo->base.size;
-	    if (!bo->busy)
-		est_size += bo->base.size;
-	}
-    }
-
-    return i915_check_aperture_size (device, relocs, est_size, size);
-}
-
-static inline cairo_bool_t
-i915_check_aperture_and_fences (const i915_device_t *device, intel_bo_t **bo_array, int count)
-{
-    uint32_t relocs = 0, est_size = 0, size = 0;
-    uint32_t fences = 0;
-
-    while (count--) {
-	const intel_bo_t *bo = *bo_array++;
-	if (bo->exec == NULL) {
-	    relocs++;
-	    size += bo->base.size;
-	    if (!bo->busy)
-		est_size += bo->base.size;
-	    if (bo->tiling != I915_TILING_NONE)
-		fences++;
-	} else if (bo->tiling != I915_TILING_NONE) {
-	    if ((bo->exec->flags & EXEC_OBJECT_NEEDS_FENCE) == 0)
-		fences++;
-	}
-    }
-
-    return i915_check_aperture_size (device, relocs, est_size, size) &&
-	   device->batch.fences + fences <= device->batch.fences_avail;
-}
-
-#define BATCH_PTR(device) &(device)->batch_base[(device)->batch.used]
-static inline void
-i915_batch_emit_dword (i915_device_t *device, uint32_t dword)
-{
-    device->batch_base[device->batch.used++] = dword;
-}
-
-cairo_private void
-i915_batch_add_reloc (i915_device_t *device, uint32_t pos,
-		      intel_bo_t *bo,
-		      uint32_t offset,
-		      uint32_t read_domains,
-		      uint32_t write_domain,
-		      cairo_bool_t needs_fence);
-
-static inline void
-i915_batch_fill_reloc (i915_device_t *device, uint32_t pos,
-		       intel_bo_t *bo,
-		       uint32_t offset,
-		       uint32_t read_domains,
-		       uint32_t write_domain)
-{
-    i915_batch_add_reloc (device, pos,
-	                  bo, offset,
-			  read_domains, write_domain,
-			  FALSE);
-    device->batch_base[pos] = bo->offset + offset;
-}
-
-static inline void
-i915_batch_emit_reloc (i915_device_t *device,
-		       intel_bo_t *bo,
-		       uint32_t offset,
-		       uint32_t read_domains,
-		       uint32_t write_domain,
-		       cairo_bool_t needs_fence)
-{
-    i915_batch_add_reloc (device, device->batch.used,
-	                  bo, offset,
-			  read_domains, write_domain,
-			  needs_fence);
-    i915_batch_emit_dword (device, bo->offset + offset);
-}
-
-cairo_private void
-i915_vbo_flush (i915_device_t *device);
-
-cairo_private void
-i915_vbo_finish (i915_device_t *device);
-
-cairo_private  cairo_status_t
-i915_batch_flush (i915_device_t *device);
-
-static inline float *
-i915_add_rectangle (i915_device_t *device)
-{
-    float *vertices;
-    uint32_t size;
-
-    assert (device->floats_per_vertex);
-    assert (device->rectangle_size == 3*device->floats_per_vertex*sizeof(float));
-
-    size = device->rectangle_size;
-    if (unlikely (device->vbo_offset + size > I915_VBO_SIZE))
-	i915_vbo_finish (device);
-
-    vertices = (float *) (device->vbo_base + device->vbo_offset);
-    device->vbo_used = device->vbo_offset += size;
-    device->vertex_count += 3;
-    return vertices;
-}
-
-static inline i915_device_t *
-i915_device (i915_surface_t *surface)
-{
-    return (i915_device_t *) surface->intel.drm.base.device;
-}
-
-cairo_private cairo_status_t
-i915_surface_clear (i915_surface_t *dst);
-
-cairo_private void
-i915_set_dst (i915_device_t *device, i915_surface_t *dst);
-
-cairo_private void
-i915_shader_init (i915_shader_t *shader,
-		  i915_surface_t *dst,
-		  cairo_operator_t op,
-		  double opacity);
-
-cairo_private cairo_status_t
-i915_shader_acquire_pattern (i915_shader_t *shader,
-			     union i915_shader_channel *src,
-			     const cairo_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents);
-
-cairo_private void
-i915_shader_set_clip (i915_shader_t *shader,
-		      cairo_clip_t *clip);
-
-cairo_private int
-i915_shader_num_texcoords (const i915_shader_t *shader);
-
-static inline double cairo_const
-i915_shader_linear_texcoord (const struct i915_shader_linear *l,
-			     double src_x, double src_y)
-{
-    return l->dx * src_x + l->dy * src_y + l->offset;
-}
-
-cairo_private cairo_status_t
-i915_shader_commit (i915_shader_t *shader,
-		    i915_device_t *device);
-
-cairo_private void
-i915_shader_fini (i915_shader_t *shader);
-
-cairo_private cairo_status_t
-i915_fixup_unbounded (i915_surface_t *dst,
-		      const cairo_composite_rectangles_t *extents,
-		      cairo_clip_t *clip);
-
-static inline cairo_bool_t
-i915_surface_needs_tiling (i915_surface_t *dst)
-{
-    return dst->intel.drm.width > 2048 || dst->intel.drm.height > 2048;
-}
-
-cairo_private cairo_status_t
-i915_surface_copy_subimage (i915_device_t *device,
-			    i915_surface_t *src,
-			    const cairo_rectangle_int_t *extents,
-			    cairo_bool_t flush,
-			    i915_surface_t **clone_out);
-
-static inline uint32_t
-pack_float (float f)
-{
-    union {
-	float f;
-	uint32_t ui;
-    } t;
-    t.f = f;
-    return t.ui;
-}
-
-static inline cairo_status_t
-i915_surface_fallback_flush (i915_surface_t *surface)
-{
-    cairo_status_t status;
-
-    if (unlikely (surface->intel.drm.fallback != NULL))
-	return intel_surface_flush (&surface->intel, 0);
-
-    status = CAIRO_STATUS_SUCCESS;
-    if (unlikely (surface->deferred_clear))
-	status = i915_surface_clear (surface);
-
-    return status;
-}
-
-#endif /* CAIRO_DRM_I915_PRIVATE_H */
diff --git a/src/drm/cairo-drm-i915-shader.c b/src/drm/cairo-drm-i915-shader.c
deleted file mode 100644
index a3f01fdf2..000000000
--- a/src/drm/cairo-drm-i915-shader.c
+++ /dev/null
@@ -1,2859 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * Contributor(s):
- *	Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-
-#include "cairo-error-private.h"
-#include "cairo-drm-i915-private.h"
-#include "cairo-surface-offset-private.h"
-#include "cairo-surface-subsurface-private.h"
-#include "cairo-surface-snapshot-private.h"
-#include "cairo-image-surface-private.h"
-
-#if 0
-static cairo_status_t
-i915_packed_pixel_surface_finish (void *abstract_surface)
-{
-    i915_packed_pixel_surface_t *surface = abstract_surface;
-    i915_device_t *device;
-
-    device = i915_device_acquire (&surface->device->intel.base);
-
-    intel_bo_destroy (&device->intel, surface->bo);
-
-    if (surface->is_current_texture) {
-	if (surface->is_current_texture & CURRENT_SOURCE)
-	    device->current_source = NULL;
-	if (surface->is_current_texture & CURRENT_MASK)
-	    device->current_mask = NULL;
-	device->current_n_samplers = 0;
-    }
-
-    i915_device_release (device);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static const cairo_surface_backend_t i915_packed_pixel_surface_backend = {
-    I915_PACKED_PIXEL_SURFACE_TYPE,
-    i915_packed_pixel_surface_finish,
-};
-
-static cairo_surface_t *
-i915_packed_pixel_surface_create (i915_device_t *device,
-				   i915_packed_pixel_t pixel,
-				   const uint8_t *data,
-				   uint32_t length,
-				   uint32_t width, uint32_t height)
-{
-    i915_packed_pixel_surface_t *surface;
-    cairo_content_t content;
-    uint32_t tiling, size;
-    uint32_t stride, half_stride;
-    uint32_t i;
-
-    if (width > 2048 || height > 2048)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
-
-    surface = _cairo_malloc (sizeof (i915_packed_pixel_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    tiling = I915_TILING_NONE; /* XXX */
-    half_stride = stride = i915_tiling_stride (tiling, width/2);
-    if (stride < width)
-	stride *= 2 ;
-    height = i915_tiling_height (tiling, height);
-
-    switch (surface->pixel = pixel) {
-    case YUV_I420:
-	content = CAIRO_CONTENT_COLOR;
-
-	surface->offset[0] = 0;
-	surface->width[0] = width;
-	surface->height[0] = height;
-	surface->stride[0] = stride;
-	surface->map0[0] = MAPSURF_8BIT | MT_8BIT_I8 | MS3_tiling (tiling);
-	surface->map0[0] |= ((height - 1) << MS3_HEIGHT_SHIFT) |
-			    ((width - 1)  << MS3_WIDTH_SHIFT);
-	surface->map1[0] = (stride / 4 - 1) << MS4_PITCH_SHIFT;
-
-	surface->offset[1] = stride * height;
-	surface->width[1] = width / 2;
-	surface->height[1] = height / 2;
-	surface->stride[1] = half_stride;
-	surface->map0[1] = MAPSURF_8BIT | MT_8BIT_I8 | MS3_tiling (tiling);
-	surface->map0[1] |= ((height/2 - 1) << MS3_HEIGHT_SHIFT) |
-			    ((width/2 - 1)  << MS3_WIDTH_SHIFT);
-	surface->map1[1] = (half_stride / 4 - 1) << MS4_PITCH_SHIFT;
-
-	if (width < half_stride) {
-	    surface->offset[2] = stride * height + half_stride / 2;
-	    size = stride * height + half_stride * height / 2;
-	} else {
-	    surface->offset[2] = stride * height + half_stride * height / 2;
-	    size = stride * height + half_stride * height;
-	}
-	surface->width[2] = width / 2;
-	surface->height[2] = height / 2;
-	surface->stride[2] = half_stride;
-	surface->map0[2] = MAPSURF_8BIT | MT_8BIT_I8 | MS3_tiling (tiling);
-	surface->map0[2] |= ((height/2 - 1) << MS3_HEIGHT_SHIFT) |
-			    ((width/2 - 1)  << MS3_WIDTH_SHIFT);
-	surface->map1[2] = (half_stride / 4 - 1) << MS4_PITCH_SHIFT;
-	break;
-
-    case NONE:
-    case YUV_YV12:
-    case YUV_YUY2:
-    case YUV_UYVY:
-	ASSERT_NOT_REACHED;
-	break;
-    }
-
-    _cairo_surface_init (&surface->base,
-	                 &i915_packed_pixel_surface_backend,
-			 content);
-
-    surface->bo = intel_bo_create (&device->intel, size, FALSE);
-    assert (surface->bo->tiling == I915_TILING_NONE);
-    if (unlikely (surface->bo == NULL)) {
-	free (surface);
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    }
-
-    if (tiling == I915_TILING_NONE) {
-	intel_bo_t *bo = surface->bo;
-	uint32_t dst;
-	int uv;
-
-	dst = surface->offset[0];
-	if (width == stride) {
-	    size = stride * height;
-	    intel_bo_write (&device->intel, bo, dst, size, data);
-	    data += size;
-	} else {
-	    for (i = 0; i < height; i++) {
-		intel_bo_write (&device->intel, bo, dst, width, data);
-		dst += stride;
-		data += width;
-	    }
-	}
-
-	for (uv = 1; uv <= 2; uv++) {
-	    dst = surface->offset[uv];
-	    if (width / 2 == half_stride) {
-		size = half_stride * height / 2;
-		intel_bo_write (&device->intel, bo, dst, size, data);
-		data += size;
-	    } else {
-		size = width / 2;
-		for (i = 0; i < height / 2; i++) {
-		    intel_bo_write (&device->intel, bo, dst, size, data);
-		    dst += half_stride;
-		    data += size;
-		}
-	    }
-	}
-    } else {
-	uint8_t *dst, *base;
-
-	base = intel_bo_map (&device->intel, surface->bo);
-
-	dst = base + surface->offset[0];
-	if (width == stride) {
-	    size = stride * height;
-	    memcpy (dst, data, size);
-	    data += size;
-	} else {
-	    for (i = 0; i < height; i++) {
-		memcpy (dst, data, width);
-		dst += stride;
-		data += width;
-	    }
-	}
-
-	dst = base + surface->offset[1];
-	if (width / 2 == half_stride) {
-	    size = half_stride * height / 2;
-	    memcpy (dst, data, size);
-	    data += size;
-	} else {
-	    size = width / 2;
-	    for (i = 0; i < height / 2; i++) {
-		memcpy (dst, data, size);
-		dst += half_stride;
-		data += size;
-	    }
-	}
-
-	dst = base + surface->offset[2];
-	if (width / 2 == half_stride) {
-	    size = half_stride * height / 2;
-	    memcpy (dst, data, size);
-	    data += size;
-	} else {
-	    size = width / 2;
-	    for (i = 0; i < height / 2; i++) {
-		memcpy (dst, data, size);
-		dst += half_stride;
-		data += size;
-	    }
-	}
-    }
-
-    surface->device = device;
-    surface->is_current_texture = 0;
-
-    return &surface->base;
-}
-
-static cairo_int_status_t
-i915_clone_yuv (i915_surface_t *surface,
-		 cairo_surface_t *source,
-		 int width, int height,
-		 cairo_surface_t **clone_out)
-{
-    const uint8_t *mime_data = NULL;
-    unsigned int mime_data_length;
-    cairo_surface_t *clone;
-
-    cairo_surface_get_mime_data (source, "video/x-raw-yuv/i420",
-				 &mime_data, &mime_data_length);
-    if (mime_data == NULL)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    clone =
-	i915_packed_pixel_surface_create ((i915_device_t *) surface->base.device,
-					   YUV_I420,
-					   mime_data, mime_data_length,
-					   width, height);
-    if (clone == NULL)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    if (unlikely (clone->status))
-	return clone->status;
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-#endif
-
-/* Max instruction count: 4 */
-static void
-i915_shader_linear_color (i915_device_t *device,
-			  enum i915_shader_linear_mode mode,
-			  int in, int c0, int c1, int out)
-{
-    int tmp = FS_U0;
-
-    switch (mode) {
-    case LINEAR_TEXTURE:
-	ASSERT_NOT_REACHED;
-    case LINEAR_NONE:
-	tmp = in;
-	break;
-
-    case LINEAR_REPEAT:
-	i915_fs_frc (tmp, i915_fs_operand (in, X, X, X, X));
-	break;
-#if 0
-    case LINEAR_REFLECT:
-	/* XXX needs an extra constant: C2 [0.5, 2.0, x, x] */
-	i915_fs_mul (tmp, in, 0.5);
-	i915_fs_frc (tmp, i915_fs_operand_reg (tmp));
-	i915_fs_mul (tmp, tmp, 2.0);
-	i915_fs_add (tmp, i915_fs_operand_one (),
-		     i915_fs_operand_reg_negate (tmp));
-	i915_fs_cmp (tmp,
-		     i915_fs_operand_reg (tmp),
-		     i915_fs_operand_reg (tmp),
-		     i915_fs_operand_reg_negate (tmp));
-	i915_fs_add (tmp, i915_fs_operand_one (),
-		     i915_fs_operand_reg_negate (tmp));
-#endif
-    case LINEAR_PAD:
-	i915_fs_max (tmp,
-		     i915_fs_operand_zero (),
-		     i915_fs_operand (in, X, X, X, X));
-	i915_fs_min (tmp,
-		     i915_fs_operand_one (),
-		     i915_fs_operand_reg (tmp));
-	break;
-    }
-
-    /* interpolate */
-    i915_fs_mad (out, 0,
-		 i915_fs_operand (tmp, NEG_X, NEG_X, NEG_X, NEG_X),
-		 i915_fs_operand_reg (c0),
-		 i915_fs_operand_reg (c0));
-    i915_fs_mad (out, 0,
-		 i915_fs_operand (tmp, X, X, X, X),
-		 i915_fs_operand_reg (c1),
-		 i915_fs_operand_reg (out));
-}
-
-static void
-i915_shader_radial_init (struct i915_shader_radial *r,
-			 const cairo_radial_pattern_t *radial)
-{
-    double dx, dy, dr, r1;
-
-    dx = radial->cd2.center.x - radial->cd1.center.x;
-    dy = radial->cd2.center.y - radial->cd1.center.y;
-    dr = radial->cd2.radius   - radial->cd1.radius;
-
-    r1 = radial->cd1.radius;
-
-    if (radial->cd2.center.x == radial->cd1.center.x &&
-	radial->cd2.center.y == radial->cd1.center.y)
-    {
-	/* XXX dr == 0, meaningless with anything other than PAD */
-	r->constants[0] = radial->cd1.center.x / dr;
-	r->constants[1] = radial->cd1.center.y / dr;
-	r->constants[2] = 1. / dr;
-	r->constants[3] = -r1 / dr;
-
-	r->constants[4] = 0;
-	r->constants[5] = 0;
-	r->constants[6] = 0;
-	r->constants[7] = 0;
-
-	r->base.mode = RADIAL_ONE;
-    } else {
-	r->constants[0] = -radial->cd1.center.x;
-	r->constants[1] = -radial->cd1.center.y;
-	r->constants[2] = r1;
-	r->constants[3] = -4 * (dx*dx + dy*dy - dr*dr);
-
-	r->constants[4] = -2 * dx;
-	r->constants[5] = -2 * dy;
-	r->constants[6] = -2 * r1 * dr;
-	r->constants[7] = 1 / (2 * (dx*dx + dy*dy - dr*dr));
-
-	r->base.mode = RADIAL_TWO;
-    }
-
-    r->base.matrix = radial->base.base.matrix;
-}
-
-/* Max instruction count: 10 */
-static void
-i915_shader_radial_coord (i915_device_t *device,
-			  enum i915_shader_radial_mode mode,
-			  int in, int g0, int g1, int out)
-{
-    switch (mode) {
-    case RADIAL_ONE:
-	/*
-	   pdx = (x - c1x) / dr, pdy = (y - c1y) / dr;
-	   r² = pdx*pdx + pdy*pdy
-	   t = r²/sqrt(r²) - r1/dr;
-	   */
-	i915_fs_mad (FS_U0, MASK_X | MASK_Y,
-		     i915_fs_operand (in, X, Y, ZERO, ZERO),
-		     i915_fs_operand (g0, Z, Z, ZERO, ZERO),
-		     i915_fs_operand (g0, NEG_X, NEG_Y, ZERO, ZERO));
-	i915_fs_dp2add (FS_U0, MASK_X,
-			i915_fs_operand (FS_U0, X, Y, ZERO, ZERO),
-			i915_fs_operand (FS_U0, X, Y, ZERO, ZERO),
-			i915_fs_operand_zero ());
-	i915_fs_rsq (out, MASK_X, i915_fs_operand (FS_U0, X, X, X, X));
-	i915_fs_mad (out, MASK_X,
-		     i915_fs_operand (FS_U0, X, ZERO, ZERO, ZERO),
-		     i915_fs_operand (out, X, ZERO, ZERO, ZERO),
-		     i915_fs_operand (g0, 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; */
-	i915_fs_add (FS_U0,
-		     i915_fs_operand (in, X, Y, ZERO, ZERO),
-		     i915_fs_operand (g0, X, Y, Z, ZERO));
-	/* u0.x = pdx, u0.y = pdy, u[0].z = r1, u[0].w = B; */
-	i915_fs_dp3 (FS_U0, MASK_W,
-		     i915_fs_operand (FS_U0, X, Y, ONE, ZERO),
-		     i915_fs_operand (g1, X, Y, Z, ZERO));
-	/* u1.x = pdx² + pdy² - r1²; [C] */
-	i915_fs_dp3 (FS_U1, MASK_X,
-		     i915_fs_operand (FS_U0, X, Y, Z, ZERO),
-		     i915_fs_operand (FS_U0, X, Y, NEG_Z, ZERO));
-	/* u1.x = C, u1.y = B, u1.z=-4*A; */
-	i915_fs_mov_masked (FS_U1, MASK_Y, i915_fs_operand (FS_U0, W, W, W, W));
-	i915_fs_mov_masked (FS_U1, MASK_Z, i915_fs_operand (g0, W, W, W, W));
-	/* u1.x = B² - 4*A*C */
-	i915_fs_dp2add (FS_U1, MASK_X,
-			i915_fs_operand (FS_U1, X, Y, ZERO, ZERO),
-			i915_fs_operand (FS_U1, Z, Y, ZERO, ZERO),
-			i915_fs_operand_zero ());
-	/* out.x = -B + sqrt (B² - 4*A*C),
-	 * out.y = -B - sqrt (B² - 4*A*C),
-	 */
-	i915_fs_rsq (out, MASK_X, i915_fs_operand (FS_U1, X, X, X, X));
-	i915_fs_mad (out, MASK_X | MASK_Y,
-		     i915_fs_operand (out, X, X, ZERO, ZERO),
-		     i915_fs_operand (FS_U1, X, NEG_X, ZERO, ZERO),
-		     i915_fs_operand (FS_U0, NEG_W, NEG_W, ZERO, ZERO));
-	/* out.x = (-B + sqrt (B² - 4*A*C)) / (2 * A),
-	 * out.y = (-B - sqrt (B² - 4*A*C)) / (2 * A)
-	 */
-	i915_fs_mul (out,
-		     i915_fs_operand (out, X, Y, ZERO, ZERO),
-		     i915_fs_operand (g1, W, W, ZERO, ZERO));
-	/* if (A > 0)
-	 *   out = (-B + sqrt (B² - 4*A*C)) / (2 * A),
-	 * else
-	 *   out = (-B - sqrt (B² - 4*A*C)) / (2 * A)
-	 */
-	i915_fs_cmp (out,
-		     i915_fs_operand (g1, W, ZERO, ZERO, ZERO),
-		     i915_fs_operand (out, X, ZERO, ZERO, ZERO),
-		     i915_fs_operand (out, Y, ZERO, ZERO, ZERO));
-	break;
-    }
-}
-
-/* Max instruction count: 7 */
-static inline void
-i915_shader_yuv_color (i915_device_t *device,
-		       int y, int u, int v,
-		       int c0, int c1, int c2,
-		       int out)
-{
-    i915_fs_mov_masked (FS_U0, MASK_X, i915_fs_operand_reg (y));
-    i915_fs_mov_masked (FS_U0, MASK_Y, i915_fs_operand_reg (u));
-    i915_fs_mov_masked (FS_U0, MASK_Z, i915_fs_operand_reg (v));
-
-    i915_fs_add (FS_U0,
-		 i915_fs_operand_reg (FS_U0),
-		 i915_fs_operand_reg (c0));
-    i915_fs_dp3 (out, MASK_X,
-		 i915_fs_operand_reg (FS_U0),
-		 i915_fs_operand (c1, X, ZERO, Y, ZERO));
-    i915_fs_dp3 (out, MASK_Z,
-		 i915_fs_operand_reg (FS_U0),
-		 i915_fs_operand (c1, Z, W, ZERO, ZERO));
-    i915_fs_dp3 (out, MASK_Y,
-		 i915_fs_operand_reg (FS_U0),
-		 i915_fs_operand_reg (c2));
-}
-
-static inline uint32_t
-i915_shader_channel_key (const union i915_shader_channel *channel)
-{
-    return (channel->type.fragment & 0x0f) | (channel->base.mode << FS_DETAILS_SHIFT);
-}
-
-static uint32_t
-i915_shader_channel_get_num_tex_coords (const union i915_shader_channel *channel)
-{
-    switch (channel->type.fragment) {
-    default:
-    case FS_ZERO:
-    case FS_ONE:
-    case FS_CONSTANT:
-    case FS_PURE:
-    case FS_DIFFUSE:
-	return 0;
-
-    case FS_LINEAR:
-    case FS_RADIAL:
-    case FS_TEXTURE:
-    case FS_SPANS:
-    case FS_YUV:
-	return 1;
-    }
-}
-
-static uint32_t
-i915_shader_get_num_tex_coords (const i915_shader_t *shader)
-{
-    uint32_t num_tex_coords;
-
-    num_tex_coords = 0;
-
-    num_tex_coords += i915_shader_channel_get_num_tex_coords (&shader->source);
-    num_tex_coords += i915_shader_channel_get_num_tex_coords (&shader->mask);
-    num_tex_coords += i915_shader_channel_get_num_tex_coords (&shader->clip);
-    num_tex_coords += i915_shader_channel_get_num_tex_coords (&shader->dst);
-
-    return num_tex_coords;
-}
-
-#define i915_fs_operand_impure(reg, channel, pure) \
-    (reg | \
-     (((pure & (1 << 0)) ? channel##_CHANNEL_VAL : ZERO_CHANNEL_VAL) << X_CHANNEL_SHIFT) | \
-     (((pure & (1 << 1)) ? channel##_CHANNEL_VAL : ZERO_CHANNEL_VAL) << Y_CHANNEL_SHIFT) | \
-     (((pure & (1 << 2)) ? channel##_CHANNEL_VAL : ZERO_CHANNEL_VAL) << Z_CHANNEL_SHIFT) | \
-     (((pure & (1 << 3)) ? channel##_CHANNEL_VAL : ZERO_CHANNEL_VAL) << W_CHANNEL_SHIFT))
-
-#define i915_fs_operand_pure(pure) \
-    (FS_R0 | \
-     (((pure & (1 << 0)) ? ONE_CHANNEL_VAL : ZERO_CHANNEL_VAL) << X_CHANNEL_SHIFT) | \
-     (((pure & (1 << 1)) ? ONE_CHANNEL_VAL : ZERO_CHANNEL_VAL) << Y_CHANNEL_SHIFT) | \
-     (((pure & (1 << 2)) ? ONE_CHANNEL_VAL : ZERO_CHANNEL_VAL) << Z_CHANNEL_SHIFT) | \
-     (((pure & (1 << 3)) ? ONE_CHANNEL_VAL : ZERO_CHANNEL_VAL) << W_CHANNEL_SHIFT))
-
-static void
-i915_set_shader_program (i915_device_t *device,
-			 const i915_shader_t *shader)
-{
-    uint32_t num_tex_coords;
-    uint32_t num_samplers;
-    uint32_t n;
-    uint32_t texture_offset = 0;
-    uint32_t constant_offset = 0;
-    uint32_t sampler_offset = 0;
-    uint32_t source_reg;
-    uint32_t source_pure;
-    uint32_t mask_reg;
-    uint32_t out_reg;
-    uint32_t dest_reg;
-    FS_LOCALS;
-
-    n = (i915_shader_channel_key (&shader->source) <<  0) |
-	(i915_shader_channel_key (&shader->mask)   <<  8) |
-	(i915_shader_channel_key (&shader->clip)   << 16) |
-	(shader->op << 24) |
-	((shader->opacity < 1.) << 30) |
-	(((shader->content & CAIRO_CONTENT_ALPHA) == CAIRO_CONTENT_ALPHA) << 31);
-    if (n == device->current_program)
-	return;
-    device->current_program = n;
-
-    FS_BEGIN ();
-
-    if (shader->source.type.fragment == FS_ZERO) {
-	if (shader->clip.type.fragment == FS_TEXTURE) {
-	    /* XXX need_combine */
-	    assert (shader->mask.type.fragment == (i915_fragment_shader_t) -1);
-	    i915_fs_dcl (FS_T0);
-	    i915_fs_texld (FS_U0, FS_S0, FS_T0);
-	    if ((shader->content & CAIRO_CONTENT_COLOR) == 0)
-		i915_fs_mov (FS_OC, i915_fs_operand (FS_U0, W, W, W, W));
-	    else
-		i915_fs_mov (FS_OC, i915_fs_operand (FS_U0, ZERO, ZERO, ZERO, W));
-	} else {
-	    i915_fs_mov (FS_OC, i915_fs_operand_zero ());
-	}
-
-	FS_END ();
-	return;
-    }
-
-    num_tex_coords = i915_shader_get_num_tex_coords (shader);
-    for (n = 0; n < num_tex_coords; n++)
-	i915_fs_dcl (FS_T0 + n);
-
-    num_samplers =
-	shader->source.base.n_samplers +
-	shader->mask.base.n_samplers +
-	shader->clip.base.n_samplers +
-	shader->dst.base.n_samplers;
-    for (n = 0; n < num_samplers; n++)
-	i915_fs_dcl (FS_S0 + n);
-
-    source_reg = ~0;
-    source_pure = 0;
-    out_reg = FS_R0;
-    if (! shader->need_combine &&
-	shader->mask.type.fragment == (i915_fragment_shader_t) -1 &&
-	shader->clip.type.fragment != FS_TEXTURE &&
-	shader->content != CAIRO_CONTENT_ALPHA)
-    {
-	out_reg = FS_OC;
-    }
-
-    switch (shader->source.type.fragment) {
-    default:
-    case FS_ZERO:
-    case FS_SPANS:
-	ASSERT_NOT_REACHED;
-
-    case FS_PURE:
-	source_pure = shader->source.solid.pure;
-    case FS_ONE:
-	break;
-
-    case FS_CONSTANT:
-	source_reg = FS_C0;
-	constant_offset += 1;
-	break;
-
-    case FS_DIFFUSE:
-	i915_fs_dcl (FS_T8);
-	source_reg = FS_T8;
-	break;
-
-    case FS_LINEAR:
-	i915_shader_linear_color (device, shader->source.base.mode,
-				  FS_T0, /* input */
-				  FS_C0, FS_C1, /* colour ramp */
-				  FS_U3); /* unpremultiplied output */
-	/* XXX can we defer premultiplication? */
-	i915_fs_mul (out_reg,
-		     i915_fs_operand_reg (FS_U3),
-		     i915_fs_operand (FS_U3, W, W, W, ONE));
-
-	constant_offset += 2;
-	texture_offset += 1;
-	source_reg = out_reg;
-	break;
-
-    case FS_RADIAL:
-	i915_shader_radial_coord (device, shader->source.base.mode,
-				  FS_T0, /* input */
-				  FS_C0, FS_C1, /* gradient constants */
-				  FS_R0); /* coordinate */
-
-	i915_fs_texld (out_reg, FS_S0, FS_R0);
-	constant_offset += 2;
-	texture_offset += 1;
-	sampler_offset += 1;
-	source_reg = out_reg;
-	break;
-
-    case FS_TEXTURE:
-	i915_fs_texld (out_reg, FS_S0, FS_T0);
-	texture_offset += 1;
-	sampler_offset += 1;
-	source_reg = out_reg;
-	break;
-
-    case FS_YUV:
-	/* Load samplers to temporaries. */
-	i915_fs_texld (FS_R0, FS_S0, FS_T0);
-	i915_fs_texld (FS_R1, FS_S1, FS_T0);
-	i915_fs_texld (FS_R2, FS_S2, FS_T0);
-
-	i915_shader_yuv_color (device,
-			       FS_R0, FS_R1, FS_R2, /* y, u, v */
-			       FS_C0, FS_C1, FS_C2, /* coefficients */
-			       out_reg);
-
-	constant_offset += 3;
-	texture_offset += 1;
-	sampler_offset += 3;
-	source_reg = out_reg;
-	break;
-    }
-
-    mask_reg = ~0;
-    switch (shader->mask.type.fragment) {
-    case FS_PURE:
-    case FS_ZERO:
-    case FS_YUV:
-    case FS_DIFFUSE:
-	ASSERT_NOT_REACHED;
-    case FS_ONE:
-    default:
-	break;
-
-    case FS_SPANS:
-	mask_reg = FS_T0 + texture_offset;
-	texture_offset += 1;
-	break;
-
-    case FS_CONSTANT:
-	mask_reg = FS_C0 + constant_offset;
-	constant_offset += 1;
-	break;
-
-    case FS_LINEAR:
-	i915_shader_linear_color (device, shader->mask.base.mode,
-				  FS_T0 + texture_offset, /* input */
-				  FS_C0 + constant_offset,
-				  FS_C0 + constant_offset + 1, /* colour ramp */
-				  FS_R1); /* unpremultiplied output */
-	constant_offset += 2;
-	texture_offset += 1;
-	mask_reg = FS_R1;
-	break;
-
-    case FS_RADIAL:
-	i915_shader_radial_coord (device, shader->mask.base.mode,
-				  FS_T0 + texture_offset, /* input */
-				  FS_C0 + constant_offset,
-				  FS_C0 + constant_offset + 1, /* gradient constants */
-				  FS_R1); /* coordinate */
-
-	i915_fs_texld (FS_R1, FS_S0 + sampler_offset, FS_R1);
-	constant_offset += 2;
-	texture_offset += 1;
-	sampler_offset += 1;
-	mask_reg = FS_R1;
-	break;
-
-    case FS_TEXTURE:
-	i915_fs_texld (FS_R1, FS_S0 + sampler_offset, FS_T0 + texture_offset);
-	texture_offset += 1;
-	sampler_offset += 1;
-	mask_reg = FS_R1;
-	break;
-    }
-
-    if (mask_reg != ~0U) {
-	if (! shader->need_combine &&
-	    shader->clip.type.fragment != FS_TEXTURE &&
-	    (shader->content != CAIRO_CONTENT_ALPHA || source_reg == ~0U))
-	{
-	    out_reg = FS_OC;
-	}
-	if (source_reg == ~0U) {
-	    if (source_pure) {
-		if (shader->mask.type.fragment == FS_SPANS) {
-		    if (out_reg == FS_OC && shader->content == CAIRO_CONTENT_ALPHA) {
-			if (source_pure & (1 << 3))
-			    i915_fs_mov (out_reg, i915_fs_operand (mask_reg, X, X, X, X));
-			else
-			    i915_fs_mov (out_reg, i915_fs_operand_zero ());
-		    } else {
-			i915_fs_mov (out_reg,
-				     i915_fs_operand_impure (mask_reg, X, source_pure));
-		    }
-		} else {
-		    /* XXX ComponentAlpha
-		       i915_fs_mov (out_reg,
-		       i915_fs_operand_pure (mask_reg,
-		       shader->source.solid.pure));
-		       */
-		    if (out_reg == FS_OC && shader->content == CAIRO_CONTENT_ALPHA) {
-			if (source_pure & (1 << 3))
-			    i915_fs_mov (out_reg, i915_fs_operand (mask_reg, W, W, W, W));
-			else
-			    i915_fs_mov (out_reg, i915_fs_operand_zero ());
-		    } else {
-			i915_fs_mov (out_reg,
-				     i915_fs_operand_impure (mask_reg, W, source_pure));
-		    }
-		}
-		source_reg = out_reg;
-	    } else if (shader->mask.type.fragment == FS_SPANS) {
-		i915_fs_mov (out_reg,
-			     i915_fs_operand (mask_reg, X, X, X, X));
-		source_reg = out_reg;
-	    } else {
-		source_reg = mask_reg;
-	    }
-	} else {
-	    if (shader->mask.type.fragment == FS_SPANS) {
-		    if (out_reg == FS_OC && shader->content == CAIRO_CONTENT_ALPHA) {
-			i915_fs_mul (out_reg,
-				     i915_fs_operand (source_reg, W, W, W, W),
-				     i915_fs_operand (mask_reg, X, X, X, X));
-		    } else {
-			i915_fs_mul (out_reg,
-				     i915_fs_operand_reg (source_reg),
-				     i915_fs_operand (mask_reg, X, X, X, X));
-		    }
-	    } else {
-		/* XXX ComponentAlpha
-		i915_fs_mul (FS_R0,
-			     i915_fs_operand_reg (source_reg),
-			     i915_fs_operand_reg (mask_reg));
-		 */
-		if (out_reg == FS_OC && shader->content == CAIRO_CONTENT_ALPHA) {
-		    i915_fs_mul (out_reg,
-				 i915_fs_operand (source_reg, W, W, W, W),
-				 i915_fs_operand (mask_reg, W, W, W, W));
-		} else {
-		    i915_fs_mul (out_reg,
-				 i915_fs_operand_reg (source_reg),
-				 i915_fs_operand (mask_reg, W, W, W, W));
-		}
-	    }
-
-	    source_reg = out_reg;
-	}
-    }
-
-    if (shader->opacity < 1.) {
-	i915_fs_mul (source_reg,
-		     i915_fs_operand_reg (source_reg),
-		     i915_fs_operand_reg (FS_C0 + constant_offset));
-	constant_offset++;
-    }
-
-    /* need to preserve order of src, mask, clip, dst */
-    mask_reg = ~0;
-    if (shader->clip.type.fragment == FS_TEXTURE) {
-	i915_fs_texld (FS_R1, FS_S0 + sampler_offset, FS_T0 + texture_offset);
-	texture_offset += 1;
-	sampler_offset += 1;
-	mask_reg = FS_R1;
-    }
-
-    if (shader->need_combine) {
-	assert (shader->dst.type.fragment == FS_TEXTURE);
-
-	i915_fs_texld (FS_R2, FS_S0 + sampler_offset, FS_T0 + texture_offset);
-	texture_offset += 1;
-	sampler_offset += 1;
-	dest_reg = FS_R2;
-
-	switch (shader->op) {
-	case CAIRO_OPERATOR_CLEAR:
-	case CAIRO_OPERATOR_SOURCE:
-	    ASSERT_NOT_REACHED;
-
-	case CAIRO_OPERATOR_OVER:
-	    if (source_reg == ~0U) {
-		/* XXX shader->source.type.fragment == FS_PURE */
-		dest_reg = FS_OC;
-	    } else {
-		i915_fs_add (FS_U0,
-			     i915_fs_operand (source_reg, NEG_W, NEG_W, NEG_W, NEG_W),
-			     i915_fs_operand_one ());
-		i915_fs_mul (FS_U0,
-			     i915_fs_operand_reg (FS_U0),
-			     dest_reg);
-		i915_fs_add (FS_R3,
-			     i915_fs_operand_reg (source_reg),
-			     i915_fs_operand_reg (FS_U0));
-		source_reg = FS_R3;
-	    }
-	    break;
-
-	case CAIRO_OPERATOR_IN:
-	    if (source_reg == ~0U) {
-		/* XXX shader->source.type.fragment == FS_PURE */
-		source_reg = dest_reg;
-	    } else {
-		i915_fs_mul (FS_R3,
-			     i915_fs_operand_reg (source_reg),
-			     dest_reg);
-		source_reg = FS_R3;
-	    }
-	    break;
-
-	case CAIRO_OPERATOR_OUT:
-	    if (source_reg == ~0U) {
-		/* XXX shader->source.type.fragment == FS_PURE */
-		i915_fs_mov (FS_R3, i915_fs_operand_zero ());
-		source_reg = FS_R3;
-	    } else {
-		i915_fs_add (FS_U0,
-			     i915_fs_operand (source_reg, NEG_W, NEG_W, NEG_W, NEG_W),
-			     i915_fs_operand_one ());
-		i915_fs_mul (FS_R3,
-			     i915_fs_operand_reg (FS_U0),
-			     dest_reg);
-		source_reg = FS_R3;
-	    }
-	    break;
-
-	case CAIRO_OPERATOR_ATOP:
-
-	case CAIRO_OPERATOR_DEST:
-	case CAIRO_OPERATOR_DEST_OVER:
-	case CAIRO_OPERATOR_DEST_IN:
-	case CAIRO_OPERATOR_DEST_OUT:
-	case CAIRO_OPERATOR_DEST_ATOP:
-
-	case CAIRO_OPERATOR_XOR:
-	case CAIRO_OPERATOR_ADD:
-	case CAIRO_OPERATOR_SATURATE:
-
-	case CAIRO_OPERATOR_MULTIPLY:
-	case CAIRO_OPERATOR_SCREEN:
-	case CAIRO_OPERATOR_OVERLAY:
-	case CAIRO_OPERATOR_DARKEN:
-	case CAIRO_OPERATOR_LIGHTEN:
-	case CAIRO_OPERATOR_COLOR_DODGE:
-	case CAIRO_OPERATOR_COLOR_BURN:
-	case CAIRO_OPERATOR_HARD_LIGHT:
-	case CAIRO_OPERATOR_SOFT_LIGHT:
-	case CAIRO_OPERATOR_DIFFERENCE:
-	case CAIRO_OPERATOR_EXCLUSION:
-	case CAIRO_OPERATOR_HSL_HUE:
-	case CAIRO_OPERATOR_HSL_SATURATION:
-	case CAIRO_OPERATOR_HSL_COLOR:
-	case CAIRO_OPERATOR_HSL_LUMINOSITY:
-	    ASSERT_NOT_REACHED;
-	    break;
-	}
-    }
-
-    if (shader->clip.type.fragment == FS_TEXTURE) {
-	assert (mask_reg != ~0U);
-
-	if (! shader->need_combine) {
-	    /* (source IN clip) */
-	    if (source_reg == ~0U) {
-		if (source_pure == 0) {
-		    source_reg = mask_reg;
-		} else {
-		    out_reg = FS_OC;
-		    if ((shader->content & CAIRO_CONTENT_COLOR) == 0) {
-			if (source_pure & (1 << 3))
-			    i915_fs_mov (out_reg, i915_fs_operand (mask_reg, W, W, W, W));
-			else
-			    i915_fs_mov (out_reg, i915_fs_operand_zero ());
-		    } else {
-			i915_fs_mov (out_reg,
-				     i915_fs_operand_impure (mask_reg, W, source_pure));
-		    }
-		    source_reg = out_reg;
-		}
-	    } else if (mask_reg) {
-		out_reg = FS_OC;
-		if ((shader->content & CAIRO_CONTENT_COLOR) == 0) {
-		    i915_fs_mul (out_reg,
-				 i915_fs_operand (source_reg, W, W, W, W),
-				 i915_fs_operand (mask_reg, W, W, W, W));
-		} else {
-		    i915_fs_mul (out_reg,
-				 i915_fs_operand_reg (source_reg),
-				 i915_fs_operand (mask_reg, W, W, W, W));
-		}
-
-		source_reg = out_reg;
-	    }
-	} else {
-	    /* (source OP dest) LERP_clip dest */
-	    if (source_reg == ~0U) {
-		if (source_pure == 0) {
-		    i915_fs_mov (FS_R3,
-				 i915_fs_operand (mask_reg, W, W, W, W));
-		} else {
-		    i915_fs_mov (FS_R3,
-				 i915_fs_operand_impure (mask_reg, W, source_pure));
-		}
-	    } else {
-		i915_fs_mul (FS_R3,
-			     i915_fs_operand_reg (source_reg),
-			     i915_fs_operand (mask_reg, W, W, W, W));
-	    }
-
-	    i915_fs_add (mask_reg,
-			 i915_fs_operand_one (),
-			 i915_fs_operand (mask_reg, NEG_W, NEG_W, NEG_W, NEG_W));
-
-	    if (dest_reg != FS_OC) {
-		if (dest_reg == ~0U) {
-		    assert (shader->dst.type.fragment == FS_TEXTURE);
-
-		    i915_fs_texld (FS_R2, FS_S0 + sampler_offset, FS_T0 + texture_offset);
-		    texture_offset += 1;
-		    sampler_offset += 1;
-		    dest_reg = FS_R2;
-		}
-
-		i915_fs_mul (FS_U1,
-			     i915_fs_operand_reg (dest_reg),
-			     i915_fs_operand_reg (mask_reg));
-		mask_reg = FS_U1;
-	    }
-
-	    source_reg = FS_OC;
-	    if ((shader->content & CAIRO_CONTENT_COLOR) == 0) {
-		i915_fs_add (source_reg,
-			     i915_fs_operand (FS_R3, W, W, W, W),
-			     i915_fs_operand (mask_reg, W, W, W, W));
-	    } else {
-		i915_fs_add (source_reg,
-			     i915_fs_operand_reg (FS_R3),
-			     i915_fs_operand_reg (mask_reg));
-	    }
-	}
-    }
-
-    if (source_reg != FS_OC) {
-	if (source_reg == ~0U) {
-	    if (source_pure) {
-		if ((shader->content & CAIRO_CONTENT_COLOR) == 0) {
-		    if (source_pure & (1 << 3))
-			i915_fs_mov (FS_OC, i915_fs_operand_one ());
-		    else
-			i915_fs_mov (FS_OC, i915_fs_operand_zero ());
-		} else
-		    i915_fs_mov (FS_OC, i915_fs_operand_pure (source_pure));
-	    } else {
-		i915_fs_mov (FS_OC, i915_fs_operand_one ());
-	    }
-	} else if ((shader->content & CAIRO_CONTENT_COLOR) == 0) {
-	    i915_fs_mov (FS_OC, i915_fs_operand (source_reg, W, W, W, W));
-	} else {
-	    i915_fs_mov (FS_OC, i915_fs_operand_reg (source_reg));
-	}
-    }
-
-    FS_END ();
-}
-
-static cairo_bool_t
-i915_shader_linear_init (struct i915_shader_linear *l,
-			 const cairo_linear_pattern_t *linear)
-{
-    double x0, y0, sf;
-    double dx, dy, offset;
-
-    dx = linear->pd2.x - linear->pd1.x;
-    dy = linear->pd2.y - linear->pd1.y;
-    sf = dx * dx + dy * dy;
-    if (sf <= 1e-5)
-	return FALSE;
-
-    dx /= sf;
-    dy /= sf;
-
-    x0 = linear->pd1.x;
-    y0 = linear->pd1.y;
-    offset = dx*x0 + dy*y0;
-
-    if (_cairo_matrix_is_identity (&linear->base.base.matrix)) {
-	l->dx = dx;
-	l->dy = dy;
-	l->offset = -offset;
-    } else {
-	cairo_matrix_t m;
-
-	cairo_matrix_init (&m, dx, 0, dy, 0, -offset, 0);
-	cairo_matrix_multiply (&m, &linear->base.base.matrix, &m);
-	l->dx = m.xx;
-	l->dy = m.xy;
-	l->offset = m.x0;
-    }
-
-    return TRUE;
-}
-
-static cairo_bool_t
-i915_shader_linear_contains_rectangle (struct i915_shader_linear *l,
-				       const cairo_rectangle_int_t *extents)
-{
-    double v;
-
-    v = i915_shader_linear_texcoord (l,
-				     extents->x,
-				     extents->y);
-    if (v < 0.)
-	return FALSE;
-    if (v > 1.)
-	return FALSE;
-
-    v = i915_shader_linear_texcoord (l,
-				     extents->x + extents->width,
-				     extents->y);
-    if (v < 0.)
-	return FALSE;
-    if (v > 1.)
-	return FALSE;
-
-    v = i915_shader_linear_texcoord (l,
-				     extents->x,
-				     extents->y + extents->height);
-    if (v < 0.)
-	return FALSE;
-    if (v > 1.)
-	return FALSE;
-
-    v = i915_shader_linear_texcoord (l,
-				     extents->x + extents->width,
-				     extents->y + extents->height);
-    if (v < 0.)
-	return FALSE;
-    if (v > 1.)
-	return FALSE;
-
-    return TRUE;
-}
-
-#define is_pure(C,mask) (((mask) == 0) || (C) <= 0x00ff || (C) >= 0xff00)
-#define is_one(C,mask) (((mask) != 0) && (C) >= 0xff00)
-#define is_zero(C,mask) (((mask) != 0) && (C) <= 0x00ff)
-
-static cairo_status_t
-i915_shader_acquire_solid (i915_shader_t *shader,
-			   union i915_shader_channel *src,
-			   const cairo_solid_pattern_t *solid,
-			   const cairo_rectangle_int_t *extents)
-{
-    cairo_content_t content;
-
-    content = CAIRO_CONTENT_COLOR_ALPHA;
-    src->solid.color = solid->color;
-    if (content == 0 || solid->color.alpha_short <= 0x00ff)
-    {
-	src->base.content = CAIRO_CONTENT_ALPHA;
-	src->type.fragment = FS_ZERO;
-    }
-    else if ((((content & CAIRO_CONTENT_COLOR) == 0)  ||
-	      (solid->color.red_short >= 0xff00 &&
-	       solid->color.green_short >= 0xff00 &&
-	       solid->color.blue_short >= 0xff00)) &&
-	     ((content & CAIRO_CONTENT_ALPHA) == 0 ||
-	      solid->color.alpha_short >= 0xff00))
-    {
-	src->base.content = CAIRO_CONTENT_ALPHA;
-	src->type.fragment = FS_ONE;
-    }
-    else if (is_pure (solid->color.red_short, content & CAIRO_CONTENT_COLOR) &&
-	     is_pure (solid->color.green_short, content & CAIRO_CONTENT_COLOR) &&
-	     is_pure (solid->color.blue_short, content & CAIRO_CONTENT_COLOR) &&
-	     is_pure (solid->color.alpha_short, content & CAIRO_CONTENT_ALPHA))
-    {
-	src->solid.pure = 0;
-	src->solid.pure |= is_one (solid->color.red_short,   content & CAIRO_CONTENT_COLOR) << 0;
-	src->solid.pure |= is_one (solid->color.green_short, content & CAIRO_CONTENT_COLOR) << 1;
-	src->solid.pure |= is_one (solid->color.blue_short,  content & CAIRO_CONTENT_COLOR) << 2;
-	src->solid.pure |= (! is_zero (solid->color.alpha_short, content & CAIRO_CONTENT_ALPHA)) << 3;
-
-	if (src->solid.pure == 0) {
-	    src->base.content = CAIRO_CONTENT_ALPHA;
-	    src->type.fragment = FS_ZERO;
-	} else if (src->solid.pure == 0x7) {
-	    src->base.content = CAIRO_CONTENT_ALPHA;
-	    src->type.fragment = FS_ONE;
-	} else {
-	    src->base.content = content;
-	    src->type.fragment = FS_PURE;
-	    src->base.mode = src->solid.pure;
-	}
-    }
-    else
-    {
-	src->base.content = content;
-	src->type.fragment = src == &shader->source ? FS_DIFFUSE : FS_CONSTANT;
-    }
-    src->type.vertex = src->type.fragment == FS_ZERO ? VS_ZERO : VS_CONSTANT;
-    src->type.pattern = PATTERN_CONSTANT;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_shader_acquire_linear (i915_shader_t *shader,
-			    union i915_shader_channel *src,
-			    const cairo_linear_pattern_t *linear,
-			    const cairo_rectangle_int_t *extents)
-{
-    cairo_bool_t mode = LINEAR_TEXTURE;
-    cairo_status_t status;
-
-    if (i915_shader_linear_init (&src->linear, linear) &&
-	linear->base.n_stops == 2 &&
-	linear->base.stops[0].offset == 0.0 &&
-	linear->base.stops[1].offset == 1.0)
-    {
-	if (i915_shader_linear_contains_rectangle (&src->linear,
-						   extents))
-	{
-	    /* XXX can also lerp if contained within offset range */
-	    mode = LINEAR_NONE;
-	}
-	else switch (linear->base.base.extend) {
-	case CAIRO_EXTEND_REPEAT:
-	    mode = LINEAR_REPEAT;
-	    break;
-	case CAIRO_EXTEND_PAD:
-	    mode = LINEAR_PAD;
-	    break;
-	case CAIRO_EXTEND_NONE:
-	    break;
-	case CAIRO_EXTEND_REFLECT:
-	    break;
-	default:
-	    ASSERT_NOT_REACHED;
-	    break;
-	}
-    }
-
-    src->type.vertex = VS_LINEAR;
-    src->type.pattern = PATTERN_LINEAR;
-    src->base.texfmt = TEXCOORDFMT_1D;
-    src->base.content = CAIRO_CONTENT_COLOR_ALPHA;
-    src->base.mode = mode;
-    if (mode == LINEAR_TEXTURE) {
-	intel_buffer_t buffer;
-
-	status = intel_gradient_render ((intel_device_t *) shader->target->intel.drm.base.device,
-					&linear->base, &buffer);
-	if (unlikely (status))
-	    return status;
-
-	src->type.fragment = FS_TEXTURE;
-	src->base.bo = intel_bo_reference (buffer.bo);
-	src->base.n_samplers = 1;
-	src->base.offset[0] = buffer.offset;
-	src->base.map[0] = buffer.map0;
-	src->base.map[1] = buffer.map1;
-	src->base.sampler[0] =
-	    (MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	    i915_texture_filter (CAIRO_FILTER_BILINEAR);
-	src->base.sampler[1] =
-	    SS3_NORMALIZED_COORDS |
-	    i915_texture_extend (linear->base.base.extend);
-    } else {
-	src->type.fragment = FS_LINEAR;
-	src->linear.color0.red   = linear->base.stops[0].color.red;
-	src->linear.color0.green = linear->base.stops[0].color.green;
-	src->linear.color0.blue  = linear->base.stops[0].color.blue;
-	src->linear.color0.alpha = linear->base.stops[0].color.alpha;
-
-	src->linear.color1.red   = linear->base.stops[1].color.red;
-	src->linear.color1.green = linear->base.stops[1].color.green;
-	src->linear.color1.blue  = linear->base.stops[1].color.blue;
-	src->linear.color1.alpha = linear->base.stops[1].color.alpha;
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_shader_acquire_radial (i915_shader_t *shader,
-			    union i915_shader_channel *src,
-			    const cairo_radial_pattern_t *radial,
-			    const cairo_rectangle_int_t *extents)
-{
-    intel_buffer_t buffer;
-    cairo_status_t status;
-
-    status = intel_gradient_render ((intel_device_t *) shader->target->intel.drm.base.device,
-				    &radial->base, &buffer);
-    if (unlikely (status))
-	return status;
-
-    i915_shader_radial_init (&src->radial, radial);
-
-    src->type.vertex = VS_TEXTURE;
-    src->type.fragment = FS_RADIAL;
-    src->type.pattern = PATTERN_RADIAL;
-    src->base.texfmt = TEXCOORDFMT_2D;
-
-    src->base.content = CAIRO_CONTENT_COLOR_ALPHA;
-    src->base.bo = intel_bo_reference (buffer.bo);
-    src->base.n_samplers = 1;
-    src->base.offset[0] = buffer.offset;
-    src->base.map[0] = buffer.map0;
-    src->base.map[1] = buffer.map1;
-    src->base.sampler[0] =
-	(MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	i915_texture_filter (CAIRO_FILTER_BILINEAR);
-    src->base.sampler[1] =
-	SS3_NORMALIZED_COORDS |
-	i915_texture_extend (radial->base.base.extend);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_surface_clone (i915_device_t *device,
-		    cairo_image_surface_t *image,
-		    i915_surface_t **clone_out)
-{
-    i915_surface_t *clone;
-    cairo_status_t status;
-
-#if 0
-    clone =
-	i915_surface_create_from_cacheable_image_internal (device, image);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-#else
-    cairo_format_t format;
-
-    format = image->format;
-    if (format == CAIRO_FORMAT_A1)
-	format = CAIRO_FORMAT_A8;
-
-    clone = (i915_surface_t *)
-	i915_surface_create_internal (&device->intel.base,
-				      format,
-				      image->width,
-				      image->height,
-				      I915_TILING_DEFAULT,
-				      FALSE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    status = intel_bo_put_image (&device->intel,
-				 to_intel_bo (clone->intel.drm.bo),
-				 image,
-				 0, 0,
-				 image->width, image->height,
-				 0, 0);
-
-    if (unlikely (status))
-	return status;
-#endif
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_surface_clone_subimage (i915_device_t *device,
-			     cairo_image_surface_t *image,
-			     const cairo_rectangle_int_t *extents,
-			     i915_surface_t **clone_out)
-{
-    i915_surface_t *clone;
-    cairo_status_t status;
-    cairo_format_t format;
-
-    format = image->format;
-    if (format == CAIRO_FORMAT_A1)
-	format = CAIRO_FORMAT_A8;
-
-    clone = (i915_surface_t *)
-	i915_surface_create_internal (&device->intel.base,
-				      format,
-				      extents->width,
-				      extents->height,
-				      I915_TILING_NONE,
-				      FALSE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    status = intel_bo_put_image (&device->intel,
-				 to_intel_bo (clone->intel.drm.bo),
-				 image,
-				 extents->x, extents->y,
-				 extents->width, extents->height,
-				 0, 0);
-
-    if (unlikely (status))
-	return status;
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_surface_render_pattern (i915_device_t *device,
-			     const cairo_surface_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents,
-			     i915_surface_t **clone_out)
-{
-    i915_surface_t *clone;
-    cairo_surface_t *image;
-    cairo_status_t status;
-    void *ptr;
-
-    clone = (i915_surface_t *)
-	i915_surface_create_internal (&device->intel.base,
-				      _cairo_format_from_content (pattern->surface->content),
-				      extents->width,
-				      extents->height,
-				      I915_TILING_NONE,
-				      FALSE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    ptr = intel_bo_map (&device->intel,
-			to_intel_bo (clone->intel.drm.bo));
-    if (unlikely (ptr == NULL)) {
-	cairo_surface_destroy (&clone->intel.drm.base);
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-    }
-
-    image = cairo_image_surface_create_for_data (ptr,
-						 clone->intel.drm.format,
-						 clone->intel.drm.width,
-						 clone->intel.drm.height,
-						 clone->intel.drm.stride);
-    if (unlikely (image->status)) {
-	cairo_surface_destroy (&clone->intel.drm.base);
-	return image->status;
-    }
-
-    status = _cairo_surface_offset_paint (image,
-					  extents->x, extents->y,
-					  CAIRO_OPERATOR_SOURCE,
-					  &pattern->base,
-					  NULL);
-    cairo_surface_destroy (image);
-
-    if (unlikely (status)) {
-	cairo_surface_destroy (&clone->intel.drm.base);
-	return status;
-    }
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_shader_acquire_solid_surface (i915_shader_t *shader,
-				   union i915_shader_channel *src,
-				   cairo_surface_t *surface,
-				   const cairo_rectangle_int_t *extents)
-{
-    cairo_surface_pattern_t pattern;
-    cairo_surface_t *pixel;
-    cairo_image_surface_t *image;
-    void *image_extra;
-    cairo_status_t status;
-    uint32_t argb;
-
-    status = _cairo_surface_acquire_source_image (surface, &image, &image_extra);
-    if (unlikely (status))
-	return status;
-
-    /* extract the pixel as argb32 */
-    pixel = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
-    _cairo_pattern_init_for_surface (&pattern, &image->base);
-    cairo_matrix_init_translate (&pattern.base.matrix, extents->x, extents->y);
-    pattern.base.filter = CAIRO_FILTER_NEAREST;
-    status = _cairo_surface_paint (pixel, CAIRO_OPERATOR_SOURCE, &pattern.base, NULL);
-    _cairo_pattern_fini (&pattern.base);
-
-    _cairo_surface_release_source_image (surface, image, image_extra);
-
-    if (unlikely (status)) {
-	cairo_surface_destroy (pixel);
-	return status;
-    }
-
-    image = (cairo_image_surface_t *) pixel;
-    argb = *(uint32_t *) image->data;
-    cairo_surface_destroy (pixel);
-
-    if (argb >> 24 == 0) {
-	_cairo_color_init_rgba (&src->solid.color, 0, 0, 0, 0);
-    } else {
-	uint8_t alpha = argb >> 24;
-
-	_cairo_color_init_rgba (&src->solid.color,
-				((((argb >> 16) & 0xff) * 255 + alpha / 2) / alpha) / 255.,
-				((((argb >>  8) & 0xff) * 255 + alpha / 2) / alpha) / 255.,
-				((((argb >>  0) & 0xff) * 255 + alpha / 2) / alpha) / 255.,
-				alpha / 255.);
-    }
-
-    src->base.content = CAIRO_CONTENT_COLOR_ALPHA;
-    src->type.fragment = FS_CONSTANT;
-    src->type.vertex = VS_CONSTANT;
-    src->type.pattern = PATTERN_CONSTANT;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_shader_acquire_surface (i915_shader_t *shader,
-			     union i915_shader_channel *src,
-			     const cairo_surface_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents)
-{
-    int surface_width, surface_height;
-    cairo_surface_t *surface, *drm;
-    cairo_extend_t extend;
-    cairo_filter_t filter;
-    cairo_matrix_t m;
-    int src_x = 0, src_y = 0;
-    cairo_surface_t *free_me = NULL;
-    cairo_status_t status;
-    cairo_rectangle_int_t sample;
-
-    assert (src->type.fragment == (i915_fragment_shader_t) -1);
-    drm = surface = pattern->surface;
-
-    extend = pattern->base.extend;
-    src->base.matrix = pattern->base.matrix;
-    filter = pattern->base.filter;
-    _cairo_pattern_sampled_area(&pattern->base, extents, sample);
-
-    if (surface->type == CAIRO_SURFACE_TYPE_DRM) {
-	if (surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
-	    drm = ((cairo_surface_subsurface_t *) surface)->target;
-	} else if (surface->backend->type == CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT) {
-	    drm = ((cairo_surface_snapshot_t *) surface)->target;
-	}
-    }
-
-    if (drm->type == CAIRO_SURFACE_TYPE_DRM) {
-	i915_surface_t *s = (i915_surface_t *) drm;
-
-	if (surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
-	    if (s->intel.drm.base.device == shader->target->intel.drm.base.device &&
-		s != shader->target)
-	    {
-		cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) surface;
-		int x;
-
-		status = i915_surface_fallback_flush (s);
-		if (unlikely (status))
-		    return status;
-
-		/* XXX blt subimage and cache snapshot */
-
-		if (to_intel_bo (s->intel.drm.bo)->batch_write_domain) {
-		    /* XXX pipelined flush of RENDER/TEXTURE cache */
-		}
-
-		src->type.fragment = FS_TEXTURE;
-		src->surface.pixel = NONE;
-		surface_width  = sub->extents.width;
-		surface_height = sub->extents.height;
-
-		src->base.bo = intel_bo_reference (to_intel_bo (s->intel.drm.bo));
-		src->base.n_samplers = 1;
-
-		x = sub->extents.x;
-		if (s->intel.drm.format != CAIRO_FORMAT_A8)
-		    x *= 4;
-
-		/* XXX tiling restrictions upon offset? */
-		src->base.offset[0] = s->offset + sub->extents.y * s->intel.drm.stride + x;
-		src->base.map[0] = s->map0;
-		src->base.map[0] &= ~((2047 << MS3_HEIGHT_SHIFT) | (2047 << MS3_WIDTH_SHIFT));
-		src->base.map[0] |=
-		    ((sub->extents.height - 1) << MS3_HEIGHT_SHIFT) |
-		    ((sub->extents.width - 1)  << MS3_WIDTH_SHIFT);
-		src->base.map[1] = (s->intel.drm.stride / 4 - 1) << MS4_PITCH_SHIFT;
-	    }
-	} else {
-	    /* XXX if s == shader->dst allow if FILTER_NEAREST, EXTEND_NONE? */
-	    if (s->intel.drm.base.device == shader->target->intel.drm.base.device) {
-		status = i915_surface_fallback_flush (s);
-		if (unlikely (status))
-		    return status;
-
-		if (s == shader->target || i915_surface_needs_tiling (s)) {
-		    status = i915_surface_copy_subimage (i915_device (shader->target),
-							 s, &sample, TRUE, &s);
-		    if (unlikely (status))
-			return status;
-
-		    free_me = drm = &s->intel.drm.base;
-		}
-
-		src->type.fragment = FS_TEXTURE;
-		src->surface.pixel = NONE;
-
-		surface_width  = s->intel.drm.width;
-		surface_height = s->intel.drm.height;
-
-		src->base.bo = intel_bo_reference (to_intel_bo (s->intel.drm.bo));
-		src->base.n_samplers = 1;
-		src->base.offset[0] = s->offset;
-		src->base.map[0] = s->map0;
-		src->base.map[1] = s->map1;
-	    }
-	}
-    }
-
-    if (src->type.fragment == (i915_fragment_shader_t) -1) {
-	i915_surface_t *s;
-
-	if (extents->width == 1 && extents->height == 1) {
-	    return i915_shader_acquire_solid_surface (shader, src,
-						      surface, extents);
-	}
-
-	s = (i915_surface_t *)
-	    _cairo_surface_has_snapshot (surface,
-					 shader->target->intel.drm.base.backend);
-	if (s == NULL) {
-	    cairo_status_t status;
-
-#if 0
-	    /* XXX hackity hack hack */
-	    status = i915_clone_yuv (surface, src,
-				     image->width, image->height,
-				     clone_out);
-#endif
-
-	    if (sample.width > 2048 || sample.height > 2048) {
-		status = i915_surface_render_pattern (i915_device (shader->target),
-						      pattern, extents,
-						      &s);
-		if (unlikely (status))
-		    return status;
-
-		extend = CAIRO_EXTEND_NONE;
-		filter = CAIRO_FILTER_NEAREST;
-		cairo_matrix_init_translate (&src->base.matrix,
-					     -extents->x, -extents->y);
-	    } else {
-		cairo_image_surface_t *image;
-		void *image_extra;
-
-		status = _cairo_surface_acquire_source_image (surface, &image, &image_extra);
-		if (unlikely (status))
-		    return status;
-
-		if (image->width  < 2048 &&
-		    image->height < 2048 &&
-		    sample.width  >= image->width / 4 &&
-		    sample.height >= image->height /4)
-		{
-
-		    status = i915_surface_clone (i915_device (shader->target),
-						 image, &s);
-
-		    if (likely (status == CAIRO_STATUS_SUCCESS)) {
-			_cairo_surface_attach_snapshot (surface,
-							&s->intel.drm.base,
-							intel_surface_detach_snapshot);
-
-			status = intel_snapshot_cache_insert (&i915_device (shader->target)->intel,
-							      &s->intel);
-			if (unlikely (status)) {
-			    cairo_surface_finish (&s->intel.drm.base);
-			    cairo_surface_destroy (&s->intel.drm.base);
-			}
-		    }
-		}
-		else
-		{
-		    status = i915_surface_clone_subimage (i915_device (shader->target),
-							  image, &sample, &s);
-		    src_x = -extents->x;
-		    src_y = -extents->y;
-		}
-
-		_cairo_surface_release_source_image (surface, image, image_extra);
-		if (unlikely (status))
-		    return status;
-	    }
-
-	    free_me = &s->intel.drm.base;
-	}
-
-	src->type.fragment = FS_TEXTURE;
-	src->surface.pixel = NONE;
-
-	src->base.bo = intel_bo_reference (to_intel_bo (s->intel.drm.bo));
-	src->base.n_samplers = 1;
-	src->base.offset[0] = s->offset;
-	src->base.map[0] = s->map0;
-	src->base.map[1] = s->map1;
-
-	drm = &s->intel.drm.base;
-
-	surface_width  = s->intel.drm.width;
-	surface_height = s->intel.drm.height;
-    }
-
-    /* XXX transform nx1 or 1xn surfaces to 1D */
-
-    src->type.pattern = PATTERN_TEXTURE;
-    if (extend != CAIRO_EXTEND_NONE &&
-	sample.x >= 0 && sample.y >= 0 &&
-	sample.x + sample.width  <= surface_width &&
-	sample.y + sample.height <= surface_height)
-    {
-	extend = CAIRO_EXTEND_NONE;
-    }
-    if (extend == CAIRO_EXTEND_NONE) {
-	src->type.vertex = VS_TEXTURE_16;
-	src->base.texfmt = TEXCOORDFMT_2D_16;
-    } else {
-	src->type.vertex = VS_TEXTURE;
-	src->base.texfmt = TEXCOORDFMT_2D;
-    }
-    src->base.content = drm->content;
-
-    src->base.sampler[0] =
-	(MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	i915_texture_filter (filter);
-    src->base.sampler[1] =
-	SS3_NORMALIZED_COORDS |
-	i915_texture_extend (extend);
-
-    /* tweak the src matrix to map from dst to texture coordinates */
-    if (src_x | src_y)
-	cairo_matrix_translate (&src->base.matrix, src_x, src_x);
-    cairo_matrix_init_scale (&m, 1. / surface_width, 1. / surface_height);
-    cairo_matrix_multiply (&src->base.matrix, &src->base.matrix, &m);
-
-    if (free_me != NULL)
-	cairo_surface_destroy (free_me);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
-i915_shader_acquire_pattern (i915_shader_t *shader,
-			     union i915_shader_channel *src,
-			     const cairo_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents)
-{
-    switch (pattern->type) {
-    case CAIRO_PATTERN_TYPE_SOLID:
-	return i915_shader_acquire_solid (shader, src,
-					  (cairo_solid_pattern_t *) pattern,
-					  extents);
-
-    case CAIRO_PATTERN_TYPE_LINEAR:
-	return i915_shader_acquire_linear (shader, src,
-					   (cairo_linear_pattern_t *) pattern,
-					   extents);
-
-    case CAIRO_PATTERN_TYPE_RADIAL:
-	return i915_shader_acquire_radial (shader, src,
-					   (cairo_radial_pattern_t *) pattern,
-					   extents);
-
-    case CAIRO_PATTERN_TYPE_SURFACE:
-	return i915_shader_acquire_surface (shader, src,
-					    (cairo_surface_pattern_t *) pattern,
-					    extents);
-
-    default:
-	ASSERT_NOT_REACHED;
-	return CAIRO_STATUS_SUCCESS;
-    }
-}
-
-static uint32_t
-i915_get_blend (cairo_operator_t op,
-		i915_surface_t *dst)
-{
-#define SBLEND(X) ((BLENDFACT_##X) << S6_CBUF_SRC_BLEND_FACT_SHIFT)
-#define DBLEND(X) ((BLENDFACT_##X) << S6_CBUF_DST_BLEND_FACT_SHIFT)
-    static const struct blendinfo {
-	cairo_bool_t dst_alpha;
-	uint32_t src_blend;
-	uint32_t dst_blend;
-	enum {
-	    BOUNDED,
-	    SIMPLE,
-	    XRENDER,
-	} kind;
-    } i915_blend_op[] = {
-	{0, SBLEND (ZERO),          DBLEND (ZERO), BOUNDED}, /* Clear */
-	{0, SBLEND (ONE),           DBLEND (ZERO), BOUNDED}, /* Src */
-
-	{0, SBLEND (ONE),           DBLEND (INV_SRC_ALPHA), SIMPLE}, /* Over */
-	{1, SBLEND (DST_ALPHA),     DBLEND (ZERO), XRENDER}, /* In */
-	{1, SBLEND (INV_DST_ALPHA), DBLEND (ZERO), XRENDER}, /* Out */
-	{1, SBLEND (DST_ALPHA),     DBLEND (INV_SRC_ALPHA), SIMPLE}, /* Atop */
-
-	{0, SBLEND (ZERO),          DBLEND (ONE), SIMPLE}, /* Dst */
-	{1, SBLEND (INV_DST_ALPHA), DBLEND (ONE), SIMPLE}, /* OverReverse */
-	{0, SBLEND (ZERO),          DBLEND (SRC_ALPHA), XRENDER}, /* InReverse */
-	{0, SBLEND (ZERO),          DBLEND (INV_SRC_ALPHA), SIMPLE}, /* OutReverse */
-	{1, SBLEND (INV_DST_ALPHA), DBLEND (SRC_ALPHA), XRENDER}, /* AtopReverse */
-
-	{1, SBLEND (INV_DST_ALPHA), DBLEND (INV_SRC_ALPHA), SIMPLE}, /* Xor */
-	{0, SBLEND (ONE),           DBLEND (ONE), SIMPLE}, /* Add */
-	//{0, 0, SBLEND (SRC_ALPHA_SATURATE),	    DBLEND (ONE), SIMPLE}, /* XXX Saturate */
-    };
-    uint32_t sblend, dblend;
-
-    if (op >= ARRAY_LENGTH (i915_blend_op))
-	return 0;
-
-    if (i915_blend_op[op].kind == BOUNDED)
-	return 0;
-
-    sblend = i915_blend_op[op].src_blend;
-    dblend = i915_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 ((dst->intel.drm.base.content & CAIRO_CONTENT_ALPHA) == 0 &&
-	i915_blend_op[op].dst_alpha)
-    {
-	if (sblend == SBLEND (DST_ALPHA))
-	    sblend = SBLEND (ONE);
-	else if (sblend == SBLEND (INV_DST_ALPHA))
-	    sblend = SBLEND (ZERO);
-    }
-
-    /* i915 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->intel.drm.format == CAIRO_FORMAT_A8 && i915_blend_op[op].dst_alpha) {
-	if (sblend == SBLEND (DST_ALPHA))
-	    sblend = SBLEND (DST_COLR);
-	else if (sblend == SBLEND (INV_DST_ALPHA))
-	    sblend = SBLEND (INV_DST_COLR);
-    }
-
-    return sblend | dblend;
-#undef SBLEND
-#undef DBLEND
-}
-
-static void
-i915_shader_channel_init (union i915_shader_channel *channel)
-{
-    channel->type.vertex = (i915_vertex_shader_t) -1;
-    channel->type.fragment = (i915_fragment_shader_t) -1;
-    channel->type.pattern = (i915_shader_channel_t) -1;
-    channel->base.texfmt = TEXCOORDFMT_NOT_PRESENT;
-    channel->base.bo = NULL;
-    channel->base.n_samplers = 0;
-    channel->base.mode = 0;
-}
-
-static void
-i915_shader_channel_fini (i915_device_t *device,
-			   union i915_shader_channel *channel)
-{
-    switch (channel->type.pattern) {
-    case PATTERN_TEXTURE:
-    case PATTERN_BASE:
-    case PATTERN_LINEAR:
-    case PATTERN_RADIAL:
-	if (channel->base.bo != NULL)
-	    intel_bo_destroy (&device->intel, channel->base.bo);
-	break;
-
-    default:
-    case PATTERN_CONSTANT:
-	break;
-    }
-}
-
-static void
-i915_shader_channel_reset (i915_device_t *device,
-			   union i915_shader_channel *channel)
-{
-    i915_shader_channel_fini (device, channel);
-    i915_shader_channel_init (channel);
-}
-
-void
-i915_shader_init (i915_shader_t *shader,
-		  i915_surface_t *dst,
-		  cairo_operator_t op,
-		  double opacity)
-{
-    shader->committed = FALSE;
-    shader->device = i915_device (dst);
-    shader->target = dst;
-    shader->op = op;
-    shader->opacity = opacity;
-
-    shader->blend = i915_get_blend (op, dst);
-    shader->need_combine = FALSE;
-
-    shader->content = dst->intel.drm.base.content;
-
-    i915_shader_channel_init (&shader->source);
-    i915_shader_channel_init (&shader->mask);
-    i915_shader_channel_init (&shader->clip);
-    i915_shader_channel_init (&shader->dst);
-}
-
-static void
-i915_set_shader_samplers (i915_device_t *device,
-	                  const i915_shader_t *shader)
-{
-    uint32_t n_samplers, n_maps, n;
-    uint32_t samplers[2*4];
-    uint32_t maps[4*4];
-    uint32_t mask, s, m;
-
-    n_maps =
-	shader->source.base.n_samplers +
-	shader->mask.base.n_samplers +
-	shader->clip.base.n_samplers +
-	shader->dst.base.n_samplers;
-    assert (n_maps <= 4);
-
-    if (n_maps == 0)
-	return;
-
-    n_samplers =
-	!! shader->source.base.bo +
-	!! shader->mask.base.bo +
-	!! shader->clip.base.bo +
-	!! shader->dst.base.bo;
-
-    mask  = (1 << n_maps) - 1;
-
-    /* We check for repeated setting of sample state mainly to catch
-     * continuation of text strings across multiple show-glyphs.
-     */
-    s = m = 0;
-    if (shader->source.base.bo != NULL) {
-	samplers[s++] = shader->source.base.sampler[0];
-	samplers[s++] = shader->source.base.sampler[1];
-	maps[m++] = shader->source.base.bo->base.handle;
-	for (n = 0; n < shader->source.base.n_samplers; n++) {
-	    maps[m++] = shader->source.base.offset[n];
-	    maps[m++] = shader->source.base.map[2*n+0];
-	    maps[m++] = shader->source.base.map[2*n+1];
-	}
-    }
-    if (shader->mask.base.bo != NULL) {
-	samplers[s++] = shader->mask.base.sampler[0];
-	samplers[s++] = shader->mask.base.sampler[1];
-	maps[m++] = shader->mask.base.bo->base.handle;
-	for (n = 0; n < shader->mask.base.n_samplers; n++) {
-	    maps[m++] = shader->mask.base.offset[n];
-	    maps[m++] = shader->mask.base.map[2*n+0];
-	    maps[m++] = shader->mask.base.map[2*n+1];
-	}
-    }
-    if (shader->clip.base.bo != NULL) {
-	samplers[s++] = shader->clip.base.sampler[0];
-	samplers[s++] = shader->clip.base.sampler[1];
-	maps[m++] = shader->clip.base.bo->base.handle;
-	for (n = 0; n < shader->clip.base.n_samplers; n++) {
-	    maps[m++] = shader->clip.base.offset[n];
-	    maps[m++] = shader->clip.base.map[2*n+0];
-	    maps[m++] = shader->clip.base.map[2*n+1];
-	}
-    }
-    if (shader->dst.base.bo != NULL) {
-	samplers[s++] = shader->dst.base.sampler[0];
-	samplers[s++] = shader->dst.base.sampler[1];
-	maps[m++] = shader->dst.base.bo->base.handle;
-	for (n = 0; n < shader->dst.base.n_samplers; n++) {
-	    maps[m++] = shader->dst.base.offset[n];
-	    maps[m++] = shader->dst.base.map[2*n+0];
-	    maps[m++] = shader->dst.base.map[2*n+1];
-	}
-    }
-
-    if (n_maps > device->current_n_maps ||
-	memcmp (device->current_maps,
-		maps,
-		m * sizeof (uint32_t)))
-    {
-	memcpy (device->current_maps, maps, m * sizeof (uint32_t));
-	device->current_n_maps = n_maps;
-
-	if (device->current_source != NULL)
-	    *device->current_source = 0;
-	if (device->current_mask != NULL)
-	    *device->current_mask = 0;
-	if (device->current_clip != NULL)
-	    *device->current_clip = 0;
-
-#if 0
-	if (shader->source.type.pattern == PATTERN_TEXTURE) {
-	    switch ((int) shader->source.surface.surface->type) {
-	    case CAIRO_SURFACE_TYPE_DRM:
-		{
-		    i915_surface_t *surface =
-			(i915_surface_t *) shader->source.surface.surface;
-		    device->current_source = &surface->is_current_texture;
-		    surface->is_current_texture |= CURRENT_SOURCE;
-		    break;
-		}
-
-	    case I915_PACKED_PIXEL_SURFACE_TYPE:
-		{
-		    i915_packed_pixel_surface_t *surface =
-			(i915_packed_pixel_surface_t *) shader->source.surface.surface;
-		    device->current_source = &surface->is_current_texture;
-		    surface->is_current_texture |= CURRENT_SOURCE;
-		    break;
-		}
-
-	    default:
-		device->current_source = NULL;
-		break;
-	    }
-	} else
-	    device->current_source = NULL;
-
-	if (shader->mask.type.pattern == PATTERN_TEXTURE) {
-	    switch ((int) shader->mask.surface.surface->type) {
-	    case CAIRO_SURFACE_TYPE_DRM:
-		{
-		    i915_surface_t *surface =
-			(i915_surface_t *) shader->mask.surface.surface;
-		    device->current_mask = &surface->is_current_texture;
-		    surface->is_current_texture |= CURRENT_MASK;
-		    break;
-		}
-
-	    case I915_PACKED_PIXEL_SURFACE_TYPE:
-		{
-		    i915_packed_pixel_surface_t *surface =
-			(i915_packed_pixel_surface_t *) shader->mask.surface.surface;
-		    device->current_mask = &surface->is_current_texture;
-		    surface->is_current_texture |= CURRENT_MASK;
-		    break;
-		}
-
-	    default:
-		device->current_mask = NULL;
-		break;
-	    }
-	} else
-	    device->current_mask = NULL;
-#endif
-
-	OUT_DWORD (_3DSTATE_MAP_STATE | (3 * n_maps));
-	OUT_DWORD (mask);
-	for (n = 0; n < shader->source.base.n_samplers; n++) {
-	    i915_batch_emit_reloc (device, shader->source.base.bo,
-				   shader->source.base.offset[n],
-				   I915_GEM_DOMAIN_SAMPLER, 0,
-				   FALSE);
-	    OUT_DWORD (shader->source.base.map[2*n+0]);
-	    OUT_DWORD (shader->source.base.map[2*n+1]);
-	}
-	for (n = 0; n < shader->mask.base.n_samplers; n++) {
-	    i915_batch_emit_reloc (device, shader->mask.base.bo,
-				   shader->mask.base.offset[n],
-				   I915_GEM_DOMAIN_SAMPLER, 0,
-				   FALSE);
-	    OUT_DWORD (shader->mask.base.map[2*n+0]);
-	    OUT_DWORD (shader->mask.base.map[2*n+1]);
-	}
-	for (n = 0; n < shader->clip.base.n_samplers; n++) {
-	    i915_batch_emit_reloc (device, shader->clip.base.bo,
-				   shader->clip.base.offset[n],
-				   I915_GEM_DOMAIN_SAMPLER, 0,
-				   FALSE);
-	    OUT_DWORD (shader->clip.base.map[2*n+0]);
-	    OUT_DWORD (shader->clip.base.map[2*n+1]);
-	}
-	for (n = 0; n < shader->dst.base.n_samplers; n++) {
-	    i915_batch_emit_reloc (device, shader->dst.base.bo,
-				   shader->dst.base.offset[n],
-				   I915_GEM_DOMAIN_SAMPLER, 0,
-				   FALSE);
-	    OUT_DWORD (shader->dst.base.map[2*n+0]);
-	    OUT_DWORD (shader->dst.base.map[2*n+1]);
-	}
-    }
-
-    if (n_samplers > device->current_n_samplers ||
-	memcmp (device->current_samplers,
-		samplers,
-		s * sizeof (uint32_t)))
-    {
-	device->current_n_samplers = s;
-	memcpy (device->current_samplers, samplers, s * sizeof (uint32_t));
-
-	OUT_DWORD (_3DSTATE_SAMPLER_STATE | (3 * n_maps));
-	OUT_DWORD (mask);
-	s = 0;
-	for (n = 0; n < shader->source.base.n_samplers; n++) {
-	    OUT_DWORD (shader->source.base.sampler[0]);
-	    OUT_DWORD (shader->source.base.sampler[1] |
-		       (s << SS3_TEXTUREMAP_INDEX_SHIFT));
-	    OUT_DWORD (0x0);
-	    s++;
-	}
-	for (n = 0; n < shader->mask.base.n_samplers; n++) {
-	    OUT_DWORD (shader->mask.base.sampler[0]);
-	    OUT_DWORD (shader->mask.base.sampler[1] |
-		       (s << SS3_TEXTUREMAP_INDEX_SHIFT));
-	    OUT_DWORD (0x0);
-	    s++;
-	}
-	for (n = 0; n < shader->clip.base.n_samplers; n++) {
-	    OUT_DWORD (shader->clip.base.sampler[0]);
-	    OUT_DWORD (shader->clip.base.sampler[1] |
-		       (s << SS3_TEXTUREMAP_INDEX_SHIFT));
-	    OUT_DWORD (0x0);
-	    s++;
-	}
-	for (n = 0; n < shader->dst.base.n_samplers; n++) {
-	    OUT_DWORD (shader->dst.base.sampler[0]);
-	    OUT_DWORD (shader->dst.base.sampler[1] |
-		       (s << SS3_TEXTUREMAP_INDEX_SHIFT));
-	    OUT_DWORD (0x0);
-	    s++;
-	}
-    }
-}
-
-static uint32_t
-i915_shader_get_texcoords (const i915_shader_t *shader)
-{
-    uint32_t texcoords;
-    uint32_t tu;
-
-    texcoords = S2_TEXCOORD_NONE;
-    tu = 0;
-    if (shader->source.base.texfmt != TEXCOORDFMT_NOT_PRESENT) {
-	texcoords &= ~S2_TEXCOORD_FMT (tu, S2_TEXCOORD_FMT0_MASK);
-	texcoords |= S2_TEXCOORD_FMT (tu, shader->source.base.texfmt);
-	tu++;
-    }
-    if (shader->mask.base.texfmt != TEXCOORDFMT_NOT_PRESENT) {
-	texcoords &= ~S2_TEXCOORD_FMT (tu, S2_TEXCOORD_FMT0_MASK);
-	texcoords |= S2_TEXCOORD_FMT (tu, shader->mask.base.texfmt);
-	tu++;
-    }
-    if (shader->clip.base.texfmt != TEXCOORDFMT_NOT_PRESENT) {
-	texcoords &= ~S2_TEXCOORD_FMT (tu, S2_TEXCOORD_FMT0_MASK);
-	texcoords |= S2_TEXCOORD_FMT (tu, shader->clip.base.texfmt);
-	tu++;
-    }
-    if (shader->dst.base.texfmt != TEXCOORDFMT_NOT_PRESENT) {
-	texcoords &= ~S2_TEXCOORD_FMT (tu, S2_TEXCOORD_FMT0_MASK);
-	texcoords |= S2_TEXCOORD_FMT (tu, shader->dst.base.texfmt);
-	tu++;
-    }
-
-    return texcoords;
-}
-
-static void
-i915_set_shader_mode (i915_device_t *device,
-	              const i915_shader_t *shader)
-{
-    uint32_t texcoords;
-    uint32_t mask, cnt;
-
-    texcoords = i915_shader_get_texcoords (shader);
-
-    mask = cnt = 0;
-
-    if (device->current_texcoords != texcoords)
-	mask |= I1_LOAD_S (2), cnt++;
-
-    if (device->current_blend != shader->blend)
-	mask |= I1_LOAD_S (6), cnt++;
-
-    if (cnt == 0)
-	return;
-
-    OUT_DWORD (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | mask | (cnt-1));
-
-    if (device->current_texcoords != texcoords) {
-	OUT_DWORD (texcoords);
-	device->current_texcoords = texcoords;
-    }
-
-    if (device->current_blend != shader->blend) {
-	if (shader->blend) {
-	    OUT_DWORD (S6_CBUF_BLEND_ENABLE | S6_COLOR_WRITE_ENABLE |
-		       (BLENDFUNC_ADD << S6_CBUF_BLEND_FUNC_SHIFT) |
-		       shader->blend);
-	} else {
-	    OUT_DWORD (S6_COLOR_WRITE_ENABLE);
-	}
-
-	device->current_blend = shader->blend;
-    }
-}
-
-static void
-i915_set_constants (i915_device_t *device,
-		    const uint32_t *constants,
-		    uint32_t n_constants)
-{
-    uint32_t n;
-
-    OUT_DWORD (_3DSTATE_PIXEL_SHADER_CONSTANTS | n_constants);
-    OUT_DWORD ((1 << (n_constants >> 2)) - 1);
-
-    for (n = 0; n < n_constants; n++)
-	OUT_DWORD (constants[n]);
-
-    device->current_n_constants = n_constants;
-    memcpy (device->current_constants, constants, n_constants*4);
-}
-
-static uint32_t
-pack_constants (const union i915_shader_channel *channel,
-		uint32_t *constants)
-{
-    uint32_t count = 0, n;
-
-    switch (channel->type.fragment) {
-    case FS_ZERO:
-    case FS_ONE:
-    case FS_PURE:
-    case FS_DIFFUSE:
-	break;
-
-    case FS_CONSTANT:
-	constants[count++] = pack_float (channel->solid.color.red);
-	constants[count++] = pack_float (channel->solid.color.green);
-	constants[count++] = pack_float (channel->solid.color.blue);
-	constants[count++] = pack_float (channel->solid.color.alpha);
-	break;
-
-    case FS_LINEAR:
-	constants[count++] = pack_float (channel->linear.color0.red);
-	constants[count++] = pack_float (channel->linear.color0.green);
-	constants[count++] = pack_float (channel->linear.color0.blue);
-	constants[count++] = pack_float (channel->linear.color0.alpha);
-
-	constants[count++] = pack_float (channel->linear.color1.red);
-	constants[count++] = pack_float (channel->linear.color1.green);
-	constants[count++] = pack_float (channel->linear.color1.blue);
-	constants[count++] = pack_float (channel->linear.color1.alpha);
-	break;
-
-    case FS_RADIAL:
-	for (n = 0; n < ARRAY_LENGTH (channel->radial.constants); n++)
-	    constants[count++] = pack_float (channel->radial.constants[n]);
-	break;
-
-    case FS_TEXTURE:
-    case FS_YUV:
-    case FS_SPANS:
-	break;
-    }
-
-    return count;
-}
-
-static void
-i915_set_shader_constants (i915_device_t *device,
-	                   const i915_shader_t *shader)
-{
-    uint32_t constants[4*4*3+4];
-    unsigned n_constants;
-
-    n_constants = 0;
-    if (shader->source.type.fragment == FS_DIFFUSE) {
-	uint32_t diffuse;
-
-	diffuse =
-	    ((uint32_t)(shader->source.solid.color.alpha_short >> 8) << 24) |
-	    ((shader->source.solid.color.red_short   >> 8) << 16) |
-	    ((shader->source.solid.color.green_short >> 8) << 8) |
-	    ((shader->source.solid.color.blue_short  >> 8) << 0);
-
-	if (diffuse != device->current_diffuse) {
-	    OUT_DWORD (_3DSTATE_DFLT_DIFFUSE_CMD);
-	    OUT_DWORD (diffuse);
-	    device->current_diffuse = diffuse;
-	}
-    } else {
-	n_constants += pack_constants (&shader->source, constants + n_constants);
-    }
-    n_constants += pack_constants (&shader->mask, constants + n_constants);
-
-    if (shader->opacity < 1.) {
-	constants[n_constants+0] =
-	    constants[n_constants+1] =
-	    constants[n_constants+2] =
-	    constants[n_constants+3] = pack_float (shader->opacity);
-	n_constants += 4;
-    }
-
-    if (n_constants != 0 &&
-	(device->current_n_constants != n_constants ||
-	 memcmp (device->current_constants, constants, n_constants*4)))
-    {
-	i915_set_constants (device, constants, n_constants);
-    }
-}
-
-static cairo_bool_t
-i915_shader_needs_update (const i915_shader_t *shader,
-			  const i915_device_t *device)
-{
-    uint32_t count, n;
-    uint32_t buf[64];
-
-    if (device->current_target != shader->target)
-	return TRUE;
-
-    count =
-	!! shader->source.base.bo +
-	!! shader->mask.base.bo +
-	!! shader->clip.base.bo +
-	!! shader->dst.base.bo;
-    if (count > device->current_n_samplers)
-	return TRUE;
-
-    count =
-	shader->source.base.n_samplers +
-	shader->mask.base.n_samplers +
-	shader->clip.base.n_samplers +
-	shader->dst.base.n_samplers;
-    if (count > device->current_n_maps)
-	return TRUE;
-
-    if (count) {
-	count = 0;
-	if (shader->source.base.bo != NULL) {
-	    buf[count++] = shader->source.base.sampler[0];
-	    buf[count++] = shader->source.base.sampler[1];
-	}
-	if (shader->mask.base.bo != NULL) {
-	    buf[count++] = shader->mask.base.sampler[0];
-	    buf[count++] = shader->mask.base.sampler[1];
-	}
-	if (shader->clip.base.bo != NULL) {
-	    buf[count++] = shader->clip.base.sampler[0];
-	    buf[count++] = shader->clip.base.sampler[1];
-	}
-	if (shader->dst.base.bo != NULL) {
-	    buf[count++] = shader->dst.base.sampler[0];
-	    buf[count++] = shader->dst.base.sampler[1];
-	}
-	if (memcmp (device->current_samplers, buf, count * sizeof (uint32_t)))
-	    return TRUE;
-
-	count = 0;
-	if (shader->source.base.bo != NULL) {
-	    buf[count++] = shader->source.base.bo->base.handle;
-	    for (n = 0; n < shader->source.base.n_samplers; n++) {
-		buf[count++] = shader->source.base.offset[n];
-		buf[count++] = shader->source.base.map[2*n+0];
-		buf[count++] = shader->source.base.map[2*n+1];
-	    }
-	}
-	if (shader->mask.base.bo != NULL) {
-	    buf[count++] = shader->mask.base.bo->base.handle;
-	    for (n = 0; n < shader->mask.base.n_samplers; n++) {
-		buf[count++] = shader->mask.base.offset[n];
-		buf[count++] = shader->mask.base.map[2*n+0];
-		buf[count++] = shader->mask.base.map[2*n+1];
-	    }
-	}
-	if (shader->clip.base.bo != NULL) {
-	    buf[count++] = shader->clip.base.bo->base.handle;
-	    for (n = 0; n < shader->clip.base.n_samplers; n++) {
-		buf[count++] = shader->clip.base.offset[n];
-		buf[count++] = shader->clip.base.map[2*n+0];
-		buf[count++] = shader->clip.base.map[2*n+1];
-	    }
-	}
-	if (shader->dst.base.bo != NULL) {
-	    buf[count++] = shader->dst.base.bo->base.handle;
-	    for (n = 0; n < shader->dst.base.n_samplers; n++) {
-		buf[count++] = shader->dst.base.offset[n];
-		buf[count++] = shader->dst.base.map[2*n+0];
-		buf[count++] = shader->dst.base.map[2*n+1];
-	    }
-	}
-	if (memcmp (device->current_maps, buf, count * sizeof (uint32_t)))
-	    return TRUE;
-    }
-
-    if (i915_shader_get_texcoords (shader) != device->current_texcoords)
-	return TRUE;
-    if (device->current_blend != shader->blend)
-	return TRUE;
-
-    count = 0;
-    if (shader->source.type.fragment == FS_DIFFUSE) {
-	uint32_t diffuse;
-
-	diffuse =
-	    ((uint32_t)(shader->source.solid.color.alpha_short >> 8) << 24) |
-	    ((shader->source.solid.color.red_short   >> 8) << 16) |
-	    ((shader->source.solid.color.green_short >> 8) << 8) |
-	    ((shader->source.solid.color.blue_short  >> 8) << 0);
-
-	if (diffuse != device->current_diffuse)
-	    return TRUE;
-    } else {
-	count += pack_constants (&shader->source, buf + count);
-    }
-    count += pack_constants (&shader->mask, buf + count);
-
-    if (count &&
-	(device->current_n_constants != count ||
-	 memcmp (device->current_constants, buf, count*4)))
-    {
-	return TRUE;
-    }
-
-    n = (i915_shader_channel_key (&shader->source) <<  0) |
-	(i915_shader_channel_key (&shader->mask)   <<  8) |
-	(i915_shader_channel_key (&shader->clip)   << 16) |
-	(shader->op << 24) |
-	((shader->opacity < 1.) << 30) |
-	(((shader->content & CAIRO_CONTENT_ALPHA) == CAIRO_CONTENT_ALPHA) << 31);
-    return n != device->current_program;
-}
-
-void
-i915_set_dst (i915_device_t *device, i915_surface_t *dst)
-{
-    uint32_t size;
-
-    if (device->current_target != dst) {
-	intel_bo_t *bo;
-
-	bo = to_intel_bo (dst->intel.drm.bo);
-	assert (bo != NULL);
-
-	OUT_DWORD (_3DSTATE_BUF_INFO_CMD);
-	OUT_DWORD (BUF_3D_ID_COLOR_BACK |
-		   BUF_tiling (bo->tiling) |
-		   BUF_3D_PITCH (dst->intel.drm.stride));
-	OUT_RELOC (dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-
-	device->current_target = dst;
-    }
-
-    if (dst->colorbuf != device->current_colorbuf) {
-	OUT_DWORD (_3DSTATE_DST_BUF_VARS_CMD);
-	OUT_DWORD (dst->colorbuf);
-	device->current_colorbuf = dst->colorbuf;
-    }
-
-    size = DRAW_YMAX (dst->intel.drm.height) | DRAW_XMAX (dst->intel.drm.width);
-    if (size != device->current_size) {
-	OUT_DWORD (_3DSTATE_DRAW_RECT_CMD);
-	OUT_DWORD (0); /* dither */
-	OUT_DWORD (0); /* top-left */
-	OUT_DWORD (size);
-	OUT_DWORD (0);  /* origin */
-	device->current_size = size;
-    }
-}
-
-static void
-i915_set_shader_target (i915_device_t *device,
-		        const i915_shader_t *shader)
-{
-    i915_set_dst (device, shader->target);
-}
-
-int
-i915_shader_num_texcoords (const i915_shader_t *shader)
-{
-    int cnt = 0;
-
-    switch (shader->source.base.texfmt) {
-    default:
-	ASSERT_NOT_REACHED;
-    case TEXCOORDFMT_NOT_PRESENT: break;
-    case TEXCOORDFMT_2D: cnt += 2; break;
-    case TEXCOORDFMT_3D: cnt += 3; break;
-    case TEXCOORDFMT_4D: cnt += 4; break;
-    case TEXCOORDFMT_1D: cnt += 1; break;
-    case TEXCOORDFMT_2D_16: cnt += 1; break;
-    }
-
-    switch (shader->mask.base.texfmt) {
-    default:
-	ASSERT_NOT_REACHED;
-    case TEXCOORDFMT_NOT_PRESENT: break;
-    case TEXCOORDFMT_2D: cnt += 2; break;
-    case TEXCOORDFMT_3D: cnt += 3; break;
-    case TEXCOORDFMT_4D: cnt += 4; break;
-    case TEXCOORDFMT_1D: cnt += 1; break;
-    case TEXCOORDFMT_2D_16: cnt += 1; break;
-    }
-
-    switch (shader->clip.base.texfmt) {
-    default:
-	ASSERT_NOT_REACHED;
-    case TEXCOORDFMT_NOT_PRESENT: break;
-    case TEXCOORDFMT_2D: cnt += 2; break;
-    case TEXCOORDFMT_3D: cnt += 3; break;
-    case TEXCOORDFMT_4D: cnt += 4; break;
-    case TEXCOORDFMT_1D: cnt += 1; break;
-    case TEXCOORDFMT_2D_16: cnt += 1; break;
-    }
-
-    switch (shader->dst.base.texfmt) {
-    default:
-	ASSERT_NOT_REACHED;
-    case TEXCOORDFMT_NOT_PRESENT: break;
-    case TEXCOORDFMT_2D: cnt += 2; break;
-    case TEXCOORDFMT_3D: cnt += 3; break;
-    case TEXCOORDFMT_4D: cnt += 4; break;
-    case TEXCOORDFMT_1D: cnt += 1; break;
-    case TEXCOORDFMT_2D_16: cnt += 1; break;
-    }
-
-    return cnt;
-}
-
-void
-i915_shader_fini (i915_shader_t *shader)
-{
-    i915_device_t *device = i915_device (shader->target);
-
-    i915_shader_channel_fini (device, &shader->source);
-    i915_shader_channel_fini (device, &shader->mask);
-    i915_shader_channel_fini (device, &shader->clip);
-}
-
-void
-i915_shader_set_clip (i915_shader_t *shader,
-		      cairo_clip_t *clip)
-{
-    cairo_surface_t *clip_surface;
-    int clip_x, clip_y;
-    union i915_shader_channel *channel;
-    i915_surface_t *s;
-
-    clip_surface = _cairo_clip_get_surface (clip, &shader->target->intel.drm.base, &clip_x, &clip_y);
-    assert (clip_surface->status == CAIRO_STATUS_SUCCESS);
-    assert (clip_surface->type == CAIRO_SURFACE_TYPE_DRM);
-
-    channel = &shader->clip;
-    channel->type.vertex = VS_TEXTURE_16;
-    channel->base.texfmt = TEXCOORDFMT_2D_16;
-    channel->base.content = CAIRO_CONTENT_ALPHA;
-
-    channel->type.fragment = FS_TEXTURE;
-    channel->surface.pixel = NONE;
-
-    s = (i915_surface_t *) clip_surface;
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
-    channel->base.n_samplers = 1;
-    channel->base.offset[0] = s->offset;
-    channel->base.map[0] = s->map0;
-    channel->base.map[1] = s->map1;
-
-    channel->base.sampler[0] =
-	(MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	i915_texture_filter (CAIRO_FILTER_NEAREST);
-    channel->base.sampler[1] =
-	SS3_NORMALIZED_COORDS |
-	i915_texture_extend (CAIRO_EXTEND_NONE);
-
-    cairo_matrix_init_scale (&shader->clip.base.matrix,
-			     1. / s->intel.drm.width,
-			     1. / s->intel.drm.height);
-    cairo_matrix_translate (&shader->clip.base.matrix,
-			    -clip_x, -clip_y);
-}
-
-static cairo_status_t
-i915_shader_check_aperture (i915_shader_t *shader,
-			    i915_device_t *device)
-{
-    cairo_status_t status;
-    intel_bo_t *bo_array[4];
-    uint32_t n = 0;
-
-    if (shader->target != device->current_target)
-	bo_array[n++] = to_intel_bo (shader->target->intel.drm.bo);
-
-    if (shader->source.base.bo != NULL)
-	bo_array[n++] = shader->source.base.bo;
-
-    if (shader->mask.base.bo != NULL)
-	bo_array[n++] = shader->mask.base.bo;
-
-    if (shader->clip.base.bo != NULL)
-	bo_array[n++] = shader->clip.base.bo;
-
-    if (n == 0 || i915_check_aperture (device, bo_array, n))
-	return CAIRO_STATUS_SUCCESS;
-
-    status = i915_batch_flush (device);
-    if (unlikely (status))
-	return status;
-
-    assert (i915_check_aperture (device, bo_array, n));
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-i915_shader_combine_mask (i915_shader_t *shader, i915_device_t *device)
-{
-    if (shader->mask.type.fragment == (i915_fragment_shader_t) -1 ||
-	shader->mask.type.fragment == FS_CONSTANT)
-    {
-	return;
-    }
-
-    if (shader->mask.type.fragment == FS_PURE) {
-	if (shader->mask.solid.pure & (1<<3)) {
-	    shader->mask.type.fragment = FS_ONE;
-	} else {
-	    shader->mask.type.fragment = FS_ZERO;
-	}
-    }
-
-    if (shader->mask.type.fragment == FS_ONE ||
-	(shader->mask.base.content & CAIRO_CONTENT_ALPHA) == 0)
-    {
-	i915_shader_channel_reset (device, &shader->mask);
-    }
-
-    if (shader->mask.type.fragment == FS_ZERO) {
-	i915_shader_channel_fini (device, &shader->source);
-
-	shader->source.type.fragment = FS_ZERO;
-	shader->source.type.vertex = VS_ZERO;
-	shader->source.base.texfmt = TEXCOORDFMT_NOT_PRESENT;
-	shader->source.base.mode = 0;
-	shader->source.base.n_samplers = 0;
-    }
-
-    if (shader->source.type.fragment == FS_ZERO) {
-	i915_shader_channel_reset (device, &shader->mask);
-	i915_shader_channel_reset (device, &shader->clip);
-    }
-}
-
-static void
-i915_shader_setup_dst (i915_shader_t *shader)
-{
-    union i915_shader_channel *channel;
-    i915_surface_t *s;
-
-    /* We need to manual blending if we have a clip surface and an unbounded op,
-     * or an extended blend mode.
-     */
-    if (shader->need_combine ||
-	(shader->op < CAIRO_OPERATOR_SATURATE &&
-	 (shader->clip.type.fragment == (i915_fragment_shader_t) -1 ||
-	  _cairo_operator_bounded_by_mask (shader->op))))
-    {
-	return;
-    }
-
-    shader->need_combine = TRUE;
-
-    channel = &shader->dst;
-    channel->type.vertex = VS_TEXTURE_16;
-    channel->base.texfmt = TEXCOORDFMT_2D_16;
-    channel->base.content = shader->content;
-
-    channel->type.fragment = FS_TEXTURE;
-    channel->surface.pixel = NONE;
-
-    s = shader->target;
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
-    channel->base.n_samplers = 1;
-    channel->base.offset[0] = s->offset;
-    channel->base.map[0] = s->map0;
-    channel->base.map[1] = s->map1;
-
-    channel->base.sampler[0] =
-	(MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT) |
-	i915_texture_filter (CAIRO_FILTER_NEAREST);
-    channel->base.sampler[1] =
-	SS3_NORMALIZED_COORDS |
-	i915_texture_extend (CAIRO_EXTEND_NONE);
-
-    cairo_matrix_init_scale (&shader->dst.base.matrix,
-			     1. / s->intel.drm.width,
-			     1. / s->intel.drm.height);
-}
-
-static void
-i915_shader_combine_source (i915_shader_t *shader,
-			    i915_device_t *device)
-{
-    if (device->last_source_fragment == shader->source.type.fragment)
-	return;
-
-    if (device->last_source_fragment == FS_DIFFUSE) {
-	switch (shader->source.type.fragment) {
-	case FS_ONE:
-	case FS_PURE:
-	case FS_CONSTANT:
-	case FS_DIFFUSE:
-	    shader->source.type.fragment = FS_DIFFUSE;
-	    shader->source.base.mode = 0;
-	    break;
-	case FS_ZERO:
-	case FS_LINEAR:
-	case FS_RADIAL:
-	case FS_TEXTURE:
-	case FS_YUV:
-	case FS_SPANS:
-	default:
-	    break;
-	}
-    }
-
-    device->last_source_fragment = shader->source.type.fragment;
-}
-
-static inline float *
-i915_composite_vertex (float *v,
-		       const i915_shader_t *shader,
-		       double x, double y)
-{
-    double s, t;
-
-    /* Each vertex is:
-     *   2 vertex coordinates
-     *   [0-2] source texture coordinates
-     *   [0-2] mask texture coordinates
-     */
-
-    *v++ = x; *v++ = y;
-    switch (shader->source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*v++ = i915_shader_linear_texcoord (&shader->source.linear, x, y);
-	break;
-    case VS_TEXTURE:
-	s = x, t = y;
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = s; *v++ = t;
-	break;
-    case VS_TEXTURE_16:
-	s = x, t = y;
-	cairo_matrix_transform_point (&shader->source.base.matrix, &s, &t);
-	*v++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    switch (shader->mask.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*v++ = i915_shader_linear_texcoord (&shader->mask.linear, x, y);
-	break;
-    case VS_TEXTURE:
-	s = x, t = y;
-	cairo_matrix_transform_point (&shader->mask.base.matrix, &s, &t);
-	*v++ = s; *v++ = t;
-	break;
-    case VS_TEXTURE_16:
-	s = x, t = y;
-	cairo_matrix_transform_point (&shader->mask.base.matrix, &s, &t);
-	*v++ = texcoord_2d_16 (s, t);
-	break;
-    }
-
-    return v;
-}
-
-static inline void
-i915_shader_add_rectangle_general (const i915_shader_t *shader,
-				   int x, int y,
-				   int w, int h)
-{
-    float *vertices;
-
-    vertices = i915_add_rectangle (shader->device);
-    vertices = i915_composite_vertex (vertices, shader, x + w, y + h);
-    vertices = i915_composite_vertex (vertices, shader, x, y + h);
-    vertices = i915_composite_vertex (vertices, shader, x, y);
-    /* XXX overflow! */
-}
-
-void
-i915_vbo_flush (i915_device_t *device)
-{
-    assert (device->floats_per_vertex);
-    assert (device->vertex_count);
-
-    if (device->vbo == 0) {
-	OUT_DWORD (_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
-		   I1_LOAD_S (0) |
-		   I1_LOAD_S (1) |
-		   1);
-	device->vbo = device->batch.used++;
-	device->vbo_max_index = device->batch.used;
-	OUT_DWORD ((device->floats_per_vertex << S1_VERTEX_WIDTH_SHIFT) |
-		   (device->floats_per_vertex << S1_VERTEX_PITCH_SHIFT));
-    }
-
-    OUT_DWORD (PRIM3D_RECTLIST |
-	       PRIM3D_INDIRECT_SEQUENTIAL |
-	       device->vertex_count);
-    OUT_DWORD (device->vertex_index);
-
-    device->vertex_index += device->vertex_count;
-    device->vertex_count = 0;
-}
-
-cairo_status_t
-i915_shader_commit (i915_shader_t *shader,
-		    i915_device_t *device)
-{
-    unsigned floats_per_vertex;
-    cairo_status_t status;
-
-    assert (CAIRO_MUTEX_IS_LOCKED (device->intel.base.base.mutex));
-
-    if (! shader->committed) {
-	device->shader = shader;
-
-	i915_shader_combine_mask (shader, device);
-	i915_shader_combine_source (shader, device);
-	i915_shader_setup_dst (shader);
-
-	shader->add_rectangle = i915_shader_add_rectangle_general;
-
-	if ((status = setjmp (shader->unwind)))
-	    return status;
-
-	shader->committed = TRUE;
-    }
-
-    if (i915_shader_needs_update (shader, device)) {
-	if (i915_batch_space (device) < 256) {
-	    status = i915_batch_flush (device);
-	    if (unlikely (status))
-		return status;
-	}
-
-	if (device->vertex_count)
-	    i915_vbo_flush (device);
-
-	status = i915_shader_check_aperture (shader, device);
-	if (unlikely (status))
-	    return status;
-
-  update_shader:
-	i915_set_shader_target (device, shader);
-	i915_set_shader_mode (device, shader);
-	i915_set_shader_samplers (device, shader);
-	i915_set_shader_constants (device, shader);
-	i915_set_shader_program (device, shader);
-    }
-
-    floats_per_vertex = 2 + i915_shader_num_texcoords (shader);
-    if (device->floats_per_vertex == floats_per_vertex)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (i915_batch_space (device) < 8) {
-	status = i915_batch_flush (device);
-	if (unlikely (status))
-	    return status;
-
-	goto update_shader;
-    }
-
-    if (device->vertex_count)
-	i915_vbo_flush (device);
-
-    if (device->vbo) {
-	device->batch_base[device->vbo_max_index] |= device->vertex_index;
-	OUT_DWORD (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S (1) | 0);
-	device->vbo_max_index = device->batch.used;
-	OUT_DWORD ((floats_per_vertex << S1_VERTEX_WIDTH_SHIFT) |
-		   (floats_per_vertex << S1_VERTEX_PITCH_SHIFT));
-    }
-
-    device->floats_per_vertex = floats_per_vertex;
-    device->rectangle_size = floats_per_vertex * 3 * sizeof (float);
-    device->vertex_index =
-	(device->vbo_used + 4*floats_per_vertex - 1) / (4 * floats_per_vertex);
-    device->vbo_offset = 4 * device->vertex_index * floats_per_vertex;
-
-    return CAIRO_STATUS_SUCCESS;
-}
diff --git a/src/drm/cairo-drm-i915-spans.c b/src/drm/cairo-drm-i915-spans.c
deleted file mode 100644
index f40bb2f2e..000000000
--- a/src/drm/cairo-drm-i915-spans.c
+++ /dev/null
@@ -1,799 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Red Hat, Inc.
- *
- * Contributor(s):
- *	Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-boxes-private.h"
-#include "cairo-error-private.h"
-#include "cairo-drm-i915-private.h"
-
-/* Operates in either immediate or retained mode.
- * When given a clip region we record the sequence of vbo and then
- * replay them for each clip rectangle, otherwise we simply emit
- * the vbo straight into the command stream.
- */
-
-typedef struct _i915_spans i915_spans_t;
-
-typedef float *
-(*i915_get_rectangle_func_t) (i915_spans_t *spans);
-
-typedef void
-(*i915_span_func_t) (i915_spans_t *spans,
-		     int x0, int x1, int y0, int y1,
-		     int alpha);
-
-struct _i915_spans {
-    cairo_span_renderer_t renderer;
-
-    i915_device_t *device;
-
-    int xmin, xmax;
-    cairo_bool_t is_bounded;
-    const cairo_rectangle_int_t *extents;
-
-    i915_get_rectangle_func_t get_rectangle;
-    i915_span_func_t span;
-    i915_shader_t shader;
-
-    cairo_region_t *clip_region;
-    cairo_bool_t need_clip_surface;
-
-    struct vbo {
-	struct vbo *next;
-	intel_bo_t *bo;
-	unsigned int count;
-    } head, *tail;
-
-    unsigned int vbo_offset;
-    float *vbo_base;
-};
-
-static float *
-i915_emit_rectangle (i915_spans_t *spans)
-{
-    return i915_add_rectangle (spans->device);
-}
-
-static float *
-i915_accumulate_rectangle (i915_spans_t *spans)
-{
-    float *vertices;
-    uint32_t size;
-
-    size = spans->device->rectangle_size;
-    if (unlikely (spans->vbo_offset + size > I915_VBO_SIZE)) {
-	struct vbo *vbo;
-
-	vbo = _cairo_malloc (sizeof (struct vbo));
-	if (unlikely (vbo == NULL)) {
-	    /* throw error! */
-	}
-
-	spans->tail->next = vbo;
-	spans->tail = vbo;
-
-	vbo->next = NULL;
-	vbo->bo = intel_bo_create (&spans->device->intel,
-				   I915_VBO_SIZE, I915_VBO_SIZE,
-				   FALSE, I915_TILING_NONE, 0);
-	vbo->count = 0;
-
-	spans->vbo_offset = 0;
-	spans->vbo_base = intel_bo_map (&spans->device->intel, vbo->bo);
-    }
-
-    vertices = spans->vbo_base + spans->vbo_offset;
-    spans->vbo_offset += size;
-    spans->tail->count += 3;
-
-    return vertices;
-}
-
-static void
-i915_span_zero (i915_spans_t *spans,
-		int x0, int x1, int y0, int y1,
-		int alpha)
-{
-    float *vertices;
-
-    vertices = spans->get_rectangle (spans);
-
-    *vertices++ = x1;
-    *vertices++ = y1;
-
-    *vertices++ = x0;
-    *vertices++ = y1;
-
-    *vertices++ = x0;
-    *vertices++ = y0;
-}
-
-static void
-i915_span_constant (i915_spans_t *spans,
-		    int x0, int x1, int y0, int y1,
-		    int alpha)
-{
-    float *vertices;
-    float a = alpha / 255.;
-
-    vertices = spans->get_rectangle (spans);
-
-    *vertices++ = x1;
-    *vertices++ = y1;
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y1;
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y0;
-    *vertices++ = a;
-}
-
-static void
-i915_span_linear (i915_spans_t *spans,
-		  int x0, int x1, int y0, int y1,
-		  int alpha)
-{
-    float *vertices;
-    float a = alpha / 255.;
-    double s, t;
-
-    vertices = spans->get_rectangle (spans);
-
-    *vertices++ = x1;
-    *vertices++ = y1;
-    s = x0, t = y0;
-    *vertices++ = i915_shader_linear_texcoord (&spans->shader.source.linear, s, t);
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y1;
-    s = x1, t = y0;
-    *vertices++ = i915_shader_linear_texcoord (&spans->shader.source.linear, s, t);
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y0;
-    s = x1, t = y1;
-    *vertices++ = i915_shader_linear_texcoord (&spans->shader.source.linear, s, t);
-    *vertices++ = a;
-}
-
-static void
-i915_span_texture (i915_spans_t *spans,
-		   int x0, int x1, int y0, int y1,
-		   int alpha)
-{
-    float *vertices;
-    float a = alpha / 255.;
-    double s, t;
-
-    vertices = spans->get_rectangle (spans);
-
-    *vertices++ = x1;
-    *vertices++ = y1;
-    s = x0, t = y0;
-    cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-    *vertices++ = s; *vertices++ = t;
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y1;
-    s = x1, t = y0;
-    cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-    *vertices++ = s; *vertices++ = t;
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y0;
-    s = x1, t = y1;
-    cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-    *vertices++ = s; *vertices++ = t;
-    *vertices++ = a;
-}
-
-static void
-i915_span_texture16 (i915_spans_t *spans,
-		     int x0, int x1, int y0, int y1, int alpha)
-{
-    float *vertices;
-    float a = alpha / 255.;
-    double s, t;
-
-    vertices = spans->get_rectangle (spans);
-
-    *vertices++ = x1;
-    *vertices++ = y1;
-    s = x0, t = y0;
-    cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-    *vertices++ = texcoord_2d_16 (s, t);
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y1;
-    s = x1, t = y0;
-    cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-    *vertices++ = texcoord_2d_16 (s, t);
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y0;
-    s = x1, t = y1;
-    cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-    *vertices++ = texcoord_2d_16 (s, t);
-    *vertices++ = a;
-}
-
-static void
-i915_span_generic (i915_spans_t *spans,
-		   int x0, int x1, int y0, int y1, int alpha)
-{
-    double s, t;
-    float *vertices;
-    float a = alpha / 255.;
-
-    /* Each vertex is:
-     *   2 vertex coordinates
-     *   [0-2] source texture coordinates
-     *   1 alpha value.
-     *   [0,2] clip mask coordinates
-     */
-
-    vertices = spans->get_rectangle (spans);
-
-    /* bottom right */
-    *vertices++ = x1; *vertices++ = y1;
-    s = x1, t = y1;
-    switch (spans->shader.source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*vertices++ = i915_shader_linear_texcoord (&spans->shader.source.linear, s, t);
-	break;
-    case VS_TEXTURE:
-	cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-	*vertices++ = s; *vertices++ = t;
-	break;
-    case VS_TEXTURE_16:
-	cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    *vertices++ = a;
-    if (spans->need_clip_surface) {
-	s = x1, t = y1;
-	cairo_matrix_transform_point (&spans->shader.clip.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-    }
-    if (spans->shader.need_combine) {
-	s = x1, t = y1;
-	cairo_matrix_transform_point (&spans->shader.dst.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-    }
-
-    /* bottom left */
-    *vertices++ = x0; *vertices++ = y1;
-    s = x0, t = y1;
-    switch (spans->shader.source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*vertices++ = i915_shader_linear_texcoord (&spans->shader.source.linear, s, t);
-	break;
-    case VS_TEXTURE:
-	cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-	*vertices++ = s; *vertices++ = t;
-	break;
-    case VS_TEXTURE_16:
-	cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    *vertices++ = a;
-    if (spans->need_clip_surface) {
-	s = x0, t = y1;
-	cairo_matrix_transform_point (&spans->shader.clip.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-    }
-    if (spans->shader.need_combine) {
-	s = x0, t = y1;
-	cairo_matrix_transform_point (&spans->shader.dst.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-    }
-
-    /* top left */
-    *vertices++ = x0; *vertices++ = y0;
-    s = x0, t = y0;
-    switch (spans->shader.source.type.vertex) {
-    case VS_ZERO:
-    case VS_CONSTANT:
-	break;
-    case VS_LINEAR:
-	*vertices++ = i915_shader_linear_texcoord (&spans->shader.source.linear, s, t);
-	break;
-    case VS_TEXTURE:
-	cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-	*vertices++ = s; *vertices++ = t;
-	break;
-    case VS_TEXTURE_16:
-	cairo_matrix_transform_point (&spans->shader.source.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-	break;
-    }
-    *vertices++ = a;
-    if (spans->need_clip_surface) {
-	s = x0, t = y0;
-	cairo_matrix_transform_point (&spans->shader.clip.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-    }
-    if (spans->shader.need_combine) {
-	s = x0, t = y0;
-	cairo_matrix_transform_point (&spans->shader.dst.base.matrix, &s, &t);
-	*vertices++ = texcoord_2d_16 (s, t);
-    }
-}
-
-static cairo_status_t
-i915_zero_spans_mono (void *abstract_renderer,
-		      int y, int height,
-		      const cairo_half_open_span_t *half,
-		      unsigned num_spans)
-{
-    i915_spans_t *spans = abstract_renderer;
-    int x0, x1;
-
-    if (num_spans == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    do {
-	while (num_spans && half[0].coverage < 128)
-	    half++, num_spans--;
-	if (num_spans == 0)
-	    break;
-
-	x0 = x1 = half[0].x;
-	while (num_spans--) {
-	    half++;
-
-	    x1 = half[0].x;
-	    if (half[0].coverage < 128)
-		break;
-	}
-
-	i915_span_zero (spans,
-			x0, x1,
-			y, y + height,
-			0);
-    } while (num_spans);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_zero_spans (void *abstract_renderer,
-		 int y, int height,
-		 const cairo_half_open_span_t *half,
-		 unsigned num_spans)
-{
-    i915_spans_t *spans = abstract_renderer;
-    int x0, x1;
-
-    if (num_spans == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    do {
-	while (num_spans && half[0].coverage == 0)
-	    half++, num_spans--;
-	if (num_spans == 0)
-	    break;
-
-	x0 = x1 = half[0].x;
-	while (num_spans--) {
-	    half++;
-
-	    x1 = half[0].x;
-	    if (half[0].coverage == 0)
-		break;
-	}
-
-	i915_span_zero (spans,
-			x0, x1,
-			y, y + height,
-			0);
-    } while (num_spans);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_bounded_spans_mono (void *abstract_renderer,
-			 int y, int height,
-			 const cairo_half_open_span_t *half,
-			 unsigned num_spans)
-{
-    i915_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    do {
-	if (half[0].coverage >= 128) {
-	    spans->span (spans,
-			 half[0].x, half[1].x,
-			 y, y + height,
-			 255);
-	}
-	half++;
-    } while (--num_spans > 1);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_bounded_spans (void *abstract_renderer,
-		    int y, int height,
-		    const cairo_half_open_span_t *half,
-		    unsigned num_spans)
-{
-    i915_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    do {
-	if (half[0].coverage) {
-	    spans->span (spans,
-			 half[0].x, half[1].x,
-			 y, y + height,
-			 half[0].coverage);
-	}
-	half++;
-    } while (--num_spans > 1);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_unbounded_spans (void *abstract_renderer,
-		      int y, int height,
-		      const cairo_half_open_span_t *half,
-		      unsigned num_spans)
-{
-    i915_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0) {
-	spans->span (spans,
-		     spans->xmin, spans->xmax,
-		     y, y + height,
-		     0);
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    if (half[0].x != spans->xmin) {
-	spans->span (spans,
-		     spans->xmin, half[0].x,
-		     y, y + height,
-		     0);
-    }
-
-    do {
-	spans->span (spans,
-		     half[0].x, half[1].x,
-		     y, y + height,
-		     half[0].coverage);
-	half++;
-    } while (--num_spans > 1);
-
-    if (half[0].x != spans->xmax) {
-	spans->span (spans,
-		     half[0].x, spans->xmax,
-		     y, y + height,
-		     0);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_unbounded_spans_mono (void *abstract_renderer,
-			   int y, int height,
-			   const cairo_half_open_span_t *half,
-			   unsigned num_spans)
-{
-    i915_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0) {
-	spans->span (spans,
-		     spans->xmin, spans->xmax,
-		     y, y + height,
-		     0);
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    if (half[0].x != spans->xmin) {
-	spans->span (spans,
-		     spans->xmin, half[0].x,
-		     y, y + height,
-		     0);
-    }
-
-    do {
-	int alpha = 0;
-	if (half[0].coverage >= 128)
-	    alpha = 255;
-	spans->span (spans,
-		     half[0].x, half[1].x,
-		     y, y + height,
-		     alpha);
-	half++;
-    } while (--num_spans > 1);
-
-    if (half[0].x != spans->xmax) {
-	spans->span (spans,
-		     half[0].x, spans->xmax,
-		     y, y + height,
-		     0);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_spans_init (i915_spans_t *spans,
-		 i915_surface_t *dst,
-		 cairo_operator_t op,
-		 const cairo_pattern_t *pattern,
-		 cairo_antialias_t antialias,
-		 cairo_clip_t *clip,
-		 double opacity,
-		 const cairo_composite_rectangles_t *extents)
-{
-    cairo_status_t status;
-
-    spans->device = (i915_device_t *) dst->intel.drm.base.device;
-
-    spans->is_bounded = extents->is_bounded;
-    if (extents->is_bounded) {
-	if (antialias == CAIRO_ANTIALIAS_NONE)
-	    spans->renderer.render_rows = i915_bounded_spans_mono;
-	else
-	    spans->renderer.render_rows = i915_bounded_spans;
-
-	spans->extents = &extents->bounded;
-    } else {
-	if (antialias == CAIRO_ANTIALIAS_NONE)
-	    spans->renderer.render_rows = i915_unbounded_spans_mono;
-	else
-	    spans->renderer.render_rows = i915_unbounded_spans;
-
-	spans->extents = &extents->unbounded;
-    }
-    spans->xmin = spans->extents->x;
-    spans->xmax = spans->extents->x + spans->extents->width;
-
-    spans->clip_region = NULL;
-    spans->need_clip_surface = FALSE;
-    if (clip != NULL) {
-	cairo_region_t *clip_region = NULL;
-
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-
-	if (clip_region != NULL && cairo_region_num_rectangles (clip_region) == 1)
-	    clip_region = NULL;
-
-	spans->clip_region = clip_region;
-	spans->need_clip_surface = status == CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    spans->head.next = NULL;
-    spans->head.bo = NULL;
-    spans->head.count = 0;
-    spans->tail = &spans->head;
-
-    if (spans->clip_region == NULL) {
-	spans->get_rectangle = i915_emit_rectangle;
-    } else {
-	assert (! extents->is_bounded);
-	spans->get_rectangle = i915_accumulate_rectangle;
-	spans->head.bo = intel_bo_create (&spans->device->intel,
-					  I915_VBO_SIZE, I915_VBO_SIZE,
-					  FALSE, I915_TILING_NONE, 0);
-	if (unlikely (spans->head.bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	spans->vbo_base = intel_bo_map (&spans->device->intel, spans->head.bo);
-    }
-    spans->vbo_offset = 0;
-
-    i915_shader_init (&spans->shader, dst, op, opacity);
-    if (spans->need_clip_surface)
-	i915_shader_set_clip (&spans->shader, clip);
-
-    status = i915_shader_acquire_pattern (&spans->shader, &spans->shader.source,
-					  pattern, &extents->bounded);
-    if (unlikely (status))
-	return status;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static void
-i915_spans_fini (i915_spans_t *spans)
-{
-    i915_shader_fini (&spans->shader);
-
-    if (spans->head.bo != NULL) {
-	struct vbo *vbo, *next;
-
-	intel_bo_destroy (&spans->device->intel, spans->head.bo);
-	for (vbo = spans->head.next; vbo != NULL; vbo = next) {
-	    next = vbo->next;
-	    intel_bo_destroy (&spans->device->intel, vbo->bo);
-	    free (vbo);
-	}
-    }
-}
-
-cairo_status_t
-i915_clip_and_composite_spans (i915_surface_t		*dst,
-			       cairo_operator_t		 op,
-			       const cairo_pattern_t	*pattern,
-			       cairo_antialias_t	 antialias,
-			       i915_spans_func_t	 draw_func,
-			       void			*draw_closure,
-			       const cairo_composite_rectangles_t*extents,
-			       cairo_clip_t		*clip,
-			       double opacity)
-{
-    i915_spans_t spans;
-    i915_device_t *device;
-    cairo_status_t status;
-    struct vbo *vbo;
-
-    if (i915_surface_needs_tiling (dst)) {
-	ASSERT_NOT_REACHED;
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    if (op == CAIRO_OPERATOR_CLEAR) {
-	pattern = &_cairo_pattern_white.base;
-	op = CAIRO_OPERATOR_DEST_OUT;
-    }
-
-    status = i915_spans_init (&spans, dst, op, pattern, antialias, clip, opacity, extents);
-    if (unlikely (status))
-	return status;
-
-    spans.shader.mask.base.texfmt = TEXCOORDFMT_1D;
-    spans.shader.mask.base.content = CAIRO_CONTENT_ALPHA;
-    spans.shader.mask.type.fragment = FS_SPANS;
-
-    status = cairo_device_acquire (dst->intel.drm.base.device);
-    if (unlikely (status))
-	goto CLEANUP_SPANS;
-
-    if (dst->deferred_clear) {
-	status = i915_surface_clear (dst);
-	if (unlikely (status))
-	    goto CLEANUP_SPANS;
-    }
-
-    device = i915_device (dst);
-    status = i915_shader_commit (&spans.shader, device);
-    if (unlikely (status))
-	goto CLEANUP_DEVICE;
-
-    if (! spans.shader.need_combine && ! spans.need_clip_surface) {
-	switch (spans.shader.source.type.vertex) {
-	case VS_ZERO:
-	    spans.span = i915_span_zero;
-	    if (extents->is_bounded) {
-		if (antialias == CAIRO_ANTIALIAS_NONE)
-		    spans.renderer.render_rows = i915_zero_spans_mono;
-		else
-		    spans.renderer.render_rows = i915_zero_spans;
-	    }
-	    break;
-	case VS_CONSTANT:
-	    spans.span = i915_span_constant;
-	    break;
-	case VS_LINEAR:
-	    spans.span = i915_span_linear;
-	    break;
-	case VS_TEXTURE:
-	    spans.span = i915_span_texture;
-	    break;
-	case VS_TEXTURE_16:
-	    spans.span = i915_span_texture16;
-	    break;
-	default:
-	    spans.span = i915_span_generic;
-	    break;
-	}
-    } else {
-	spans.span = i915_span_generic;
-    }
-
-    status = draw_func (draw_closure, &spans.renderer, spans.extents);
-    if (spans.clip_region != NULL && status == CAIRO_STATUS_SUCCESS) {
-	i915_vbo_finish (device);
-
-	OUT_DWORD (_3DSTATE_SCISSOR_ENABLE_CMD | ENABLE_SCISSOR_RECT);
-	for (vbo = &spans.head; vbo != NULL; vbo = vbo->next) {
-	    int i, num_rectangles;
-
-	    /* XXX require_space & batch_flush */
-
-	    OUT_DWORD (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S (0) | I1_LOAD_S (1) | 1);
-	    i915_batch_emit_reloc (device, vbo->bo, 0,
-				   I915_GEM_DOMAIN_VERTEX, 0,
-				   FALSE);
-	    OUT_DWORD ((device->floats_per_vertex << S1_VERTEX_WIDTH_SHIFT) |
-		       (device->floats_per_vertex << S1_VERTEX_PITCH_SHIFT) |
-		       vbo->count);
-
-	    num_rectangles = cairo_region_num_rectangles (spans.clip_region);
-	    for (i = 0; i < num_rectangles; i++) {
-		cairo_rectangle_int_t rect;
-
-		cairo_region_get_rectangle (spans.clip_region, i, &rect);
-
-		OUT_DWORD (_3DSTATE_SCISSOR_RECT_0_CMD);
-		OUT_DWORD (SCISSOR_RECT_0_XMIN (rect.x) |
-			   SCISSOR_RECT_0_YMIN (rect.y));
-		OUT_DWORD (SCISSOR_RECT_0_XMAX (rect.x + rect.width) |
-			   SCISSOR_RECT_0_YMAX (rect.y + rect.height));
-
-		OUT_DWORD (PRIM3D_RECTLIST | PRIM3D_INDIRECT_SEQUENTIAL | vbo->count);
-		OUT_DWORD (0);
-	    }
-	}
-	OUT_DWORD (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
-    }
-
-CLEANUP_DEVICE:
-    cairo_device_release (dst->intel.drm.base.device);
-CLEANUP_SPANS:
-    i915_spans_fini (&spans);
-
-    return status;
-}
diff --git a/src/drm/cairo-drm-i915-surface.c b/src/drm/cairo-drm-i915-surface.c
deleted file mode 100644
index 8fc5f7a9d..000000000
--- a/src/drm/cairo-drm-i915-surface.c
+++ /dev/null
@@ -1,2942 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Chris Wilson
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * **************************************************************************
- * This work was initially based upon xf86-video-intel/src/i915_render.c:
- * 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 at intel.com>
- *    Eric Anholt <eric at anholt.net>
- *
- * **************************************************************************
- * and also upon libdrm/intel/intel_bufmgr_gem.c:
- * Copyright © 2007 Red Hat Inc.
- * Copyright © 2007 Intel Corporation
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
- * 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 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, AUTHORS 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
- *          Keith Whitwell <keithw-at-tungstengraphics-dot-com>
- *          Eric Anholt <eric at anholt.net>
- *          Dave Airlie <airlied at linux.ie>
- */
-
-/* XXX
- *
- * - Per thread context? Would it actually avoid many locks?
- *
- */
-
-#include "cairoint.h"
-
-#include "cairo-drm-private.h"
-#include "cairo-drm-intel-private.h"
-#include "cairo-drm-intel-command-private.h"
-#include "cairo-drm-intel-ioctl-private.h"
-#include "cairo-drm-i915-private.h"
-
-#include "cairo-boxes-private.h"
-#include "cairo-cache-private.h"
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-default-context-private.h"
-#include "cairo-error-private.h"
-#include "cairo-freelist-private.h"
-#include "cairo-list-private.h"
-#include "cairo-path-fixed-private.h"
-#include "cairo-region-private.h"
-#include "cairo-surface-offset-private.h"
-#include "cairo-image-surface-private.h"
-
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <errno.h>
-
-static const uint32_t i915_batch_setup[] = {
-    /* Disable line anti-aliasing */
-    _3DSTATE_AA_CMD,
-
-    /* Disable independent alpha blend */
-    _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),
-
-    /* Disable texture crossbar */
-    _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),
-
-    _3DSTATE_MODES_4_CMD | ENABLE_LOGIC_OP_FUNC | LOGIC_OP_FUNC (LOGICOP_COPY),
-
-    _3DSTATE_LOAD_STATE_IMMEDIATE_1 |
-	I1_LOAD_S (2) |
-	I1_LOAD_S (3) |
-	I1_LOAD_S (4) |
-	I1_LOAD_S (5) |
-	I1_LOAD_S (6) |
-	4,
-    S2_TEXCOORD_NONE,
-    0, /* Disable texture coordinate wrap-shortest */
-    (1 << S4_POINT_WIDTH_SHIFT) |
-	S4_LINE_WIDTH_ONE |
-	S4_FLATSHADE_ALPHA |
-	S4_FLATSHADE_FOG |
-	S4_FLATSHADE_SPECULAR |
-	S4_FLATSHADE_COLOR |
-	S4_CULLMODE_NONE |
-	S4_VFMT_XY,
-    0, /* Disable stencil buffer */
-    S6_COLOR_WRITE_ENABLE,
-
-    _3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT,
-
-    /* disable indirect state */
-    _3DSTATE_LOAD_INDIRECT,
-    0,
-};
-
-static const cairo_surface_backend_t i915_surface_backend;
-
-static cairo_surface_t *
-i915_surface_create_from_cacheable_image (cairo_drm_device_t *base_dev,
-	                                   cairo_surface_t *source);
-
-static cairo_status_t
-i915_bo_exec (i915_device_t *device, intel_bo_t *bo, uint32_t offset)
-{
-    struct drm_i915_gem_execbuffer2 execbuf;
-    int ret, cnt, i;
-
-    /* Add the batch buffer to the validation list.  */
-    cnt = device->batch.exec_count;
-    if (cnt > 0 && bo->base.handle == device->batch.exec[cnt-1].handle)
-	i = cnt - 1;
-    else
-	i = device->batch.exec_count++;
-    device->batch.exec[i].handle = bo->base.handle;
-    device->batch.exec[i].relocation_count = device->batch.reloc_count;
-    device->batch.exec[i].relocs_ptr = (uintptr_t) device->batch.reloc;
-    device->batch.exec[i].alignment = 0;
-    device->batch.exec[i].offset = 0;
-    device->batch.exec[i].flags = 0;
-    device->batch.exec[i].rsvd1 = 0;
-    device->batch.exec[i].rsvd2 = 0;
-
-    execbuf.buffers_ptr = (uintptr_t) device->batch.exec;
-    execbuf.buffer_count = device->batch.exec_count;
-    execbuf.batch_start_offset = offset;
-    execbuf.batch_len = (device->batch.used << 2) + sizeof (device->batch_header);
-    execbuf.DR1 = 0;
-    execbuf.DR4 = 0;
-    execbuf.num_cliprects = 0;
-    execbuf.cliprects_ptr = 0;
-    execbuf.flags = 0;
-    execbuf.rsvd1 = 0;
-    execbuf.rsvd2 = 0;
-
-    do {
-	ret = ioctl (device->intel.base.fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
-    } while (ret != 0 && errno == EINTR);
-
-    if (device->debug & I915_DEBUG_SYNC && ret == 0)
-	ret = ! intel_bo_wait (&device->intel, bo);
-
-    if (0 && ret) {
-	int n, m;
-
-	fprintf (stderr, "Batch submission failed: %d\n", errno);
-	fprintf (stderr, "   relocation entries: %d/%d\n",
-		 device->batch.reloc_count, I915_MAX_RELOCS);
-	fprintf (stderr, "   gtt size: (%zd/%zd), (%zd/%zd)\n",
-		 device->batch.est_gtt_size, device->batch.gtt_avail_size,
-		 device->batch.total_gtt_size, device->intel.gtt_avail_size);
-
-	fprintf (stderr, "   buffers:\n");
-	for (n = 0; n < device->batch.exec_count; n++) {
-	    fprintf (stderr, "  exec[%d] = %d, %d/%d bytes, gtt = %qx\n",
-		    n,
-		    device->batch.exec[n].handle,
-		    n == device->batch.exec_count - 1 ? bo->base.size : device->batch.target_bo[n]->base.size,
-		    n == device->batch.exec_count - 1 ? bo->full_size : device->batch.target_bo[n]->full_size,
-		    device->batch.exec[n].offset);
-	}
-	for (n = 0; n < device->batch.reloc_count; n++) {
-	    for (m = 0; m < device->batch.exec_count; m++)
-		if (device->batch.exec[m].handle == device->batch.reloc[n].target_handle)
-		    break;
-
-	    fprintf (stderr, "  reloc[%d] = %d @ %qx -> %qx + %qx\n", n,
-		     device->batch.reloc[n].target_handle,
-		     device->batch.reloc[n].offset,
-		     (unsigned long long) device->batch.exec[m].offset,
-		     (unsigned long long) device->batch.reloc[n].delta);
-
-	    device->batch_base[(device->batch.reloc[n].offset - sizeof (device->batch_header)) / 4] =
-		device->batch.exec[m].offset + device->batch.reloc[n].delta;
-	}
-
-	intel_dump_batchbuffer (device->batch_header,
-				execbuf.batch_len,
-				device->intel.base.chip_id);
-    }
-    assert (ret == 0);
-
-    VG (VALGRIND_MAKE_MEM_DEFINED (device->batch.exec, sizeof (device->batch.exec[0]) * i));
-
-    bo->offset = device->batch.exec[i].offset;
-    bo->busy = TRUE;
-    if (bo->virtual)
-	intel_bo_unmap (bo);
-    bo->cpu = FALSE;
-
-    while (cnt--) {
-	intel_bo_t *bo = device->batch.target_bo[cnt];
-
-	bo->offset = device->batch.exec[cnt].offset;
-	bo->exec = NULL;
-	bo->busy = TRUE;
-	bo->batch_read_domains = 0;
-	bo->batch_write_domain = 0;
-	cairo_list_del (&bo->cache_list);
-
-	if (bo->virtual)
-	    intel_bo_unmap (bo);
-	bo->cpu = FALSE;
-
-	intel_bo_destroy (&device->intel, bo);
-    }
-    assert (cairo_list_is_empty (&device->intel.bo_in_flight));
-
-    device->batch.exec_count = 0;
-    device->batch.reloc_count = 0;
-    device->batch.fences = 0;
-
-    device->batch.est_gtt_size = I915_BATCH_SIZE;
-    device->batch.total_gtt_size = I915_BATCH_SIZE;
-
-    return ret == 0 ? CAIRO_STATUS_SUCCESS : _cairo_error (CAIRO_STATUS_NO_MEMORY);
-}
-
-void
-i915_batch_add_reloc (i915_device_t *device,
-		      uint32_t pos,
-		      intel_bo_t *bo,
-		      uint32_t offset,
-		      uint32_t read_domains,
-		      uint32_t write_domain,
-		      cairo_bool_t needs_fence)
-{
-    int index;
-
-    assert (offset < bo->base.size);
-
-    if (bo->exec == NULL) {
-	device->batch.total_gtt_size += bo->base.size;
-
-	if (! bo->busy)
-	    device->batch.est_gtt_size += bo->base.size;
-
-	assert (device->batch.exec_count < ARRAY_LENGTH (device->batch.exec));
-
-	index = device->batch.exec_count++;
-	device->batch.exec[index].handle = bo->base.handle;
-	device->batch.exec[index].relocation_count = 0;
-	device->batch.exec[index].relocs_ptr = 0;
-	device->batch.exec[index].alignment = 0;
-	device->batch.exec[index].offset = 0;
-	device->batch.exec[index].flags = 0;
-	device->batch.exec[index].rsvd1 = 0;
-	device->batch.exec[index].rsvd2 = 0;
-
-	device->batch.target_bo[index] = intel_bo_reference (bo);
-
-	bo->exec = &device->batch.exec[index];
-    }
-
-    if (bo->tiling != I915_TILING_NONE) {
-	uint32_t alignment;
-
-#if 0
-	/* We presume that we will want to use a fence with X tiled objects... */
-	if (needs_fence || bo->tiling == I915_TILING_X)
-	    alignment = bo->full_size;
-	else
-	    alignment = 2*((bo->stride + 4095) & -4096);
-#else
-	alignment = bo->full_size;
-#endif
-	if (bo->exec->alignment < alignment)
-	    bo->exec->alignment = alignment;
-
-	if (needs_fence && (bo->exec->flags & EXEC_OBJECT_NEEDS_FENCE) == 0) {
-	    bo->exec->flags |= EXEC_OBJECT_NEEDS_FENCE;
-	    device->batch.fences++;
-
-	    intel_bo_set_tiling (&device->intel, bo);
-	}
-    }
-
-    assert (device->batch.reloc_count < ARRAY_LENGTH (device->batch.reloc));
-
-    index = device->batch.reloc_count++;
-    device->batch.reloc[index].offset = (pos << 2) + sizeof (device->batch_header);
-    device->batch.reloc[index].delta = offset;
-    device->batch.reloc[index].target_handle = bo->base.handle;
-    device->batch.reloc[index].read_domains = read_domains;
-    device->batch.reloc[index].write_domain = write_domain;
-    device->batch.reloc[index].presumed_offset = bo->offset;
-
-    assert (write_domain == 0 || bo->batch_write_domain == 0 || bo->batch_write_domain == write_domain);
-    bo->batch_read_domains |= read_domains;
-    bo->batch_write_domain |= write_domain;
-}
-
-void
-i915_vbo_finish (i915_device_t *device)
-{
-    intel_bo_t *vbo;
-
-    assert (CAIRO_MUTEX_IS_LOCKED (device->intel.base.base.mutex));
-    assert (device->vbo_used);
-
-    if (device->vertex_count) {
-	if (device->vbo == 0) {
-	    OUT_DWORD (_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
-		       I1_LOAD_S (0) |
-		       I1_LOAD_S (1) |
-		       1);
-	    device->vbo = device->batch.used++;
-	    device->vbo_max_index = device->batch.used;
-	    OUT_DWORD ((device->floats_per_vertex << S1_VERTEX_WIDTH_SHIFT) |
-		       (device->floats_per_vertex << S1_VERTEX_PITCH_SHIFT));
-	}
-
-	OUT_DWORD (PRIM3D_RECTLIST |
-		   PRIM3D_INDIRECT_SEQUENTIAL |
-		   device->vertex_count);
-	OUT_DWORD (device->vertex_index);
-    }
-
-    if (device->last_vbo != NULL) {
-	intel_bo_in_flight_add (&device->intel, device->last_vbo);
-	intel_bo_destroy (&device->intel, device->last_vbo);
-    }
-
-    device->batch_base[device->vbo_max_index] |= device->vertex_index + device->vertex_count;
-
-    /* will include a few bytes of inter-array padding */
-    vbo = intel_bo_create (&device->intel,
-			   device->vbo_used, device->vbo_used,
-			   FALSE, I915_TILING_NONE, 0);
-    i915_batch_fill_reloc (device, device->vbo, vbo, 0,
-			   I915_GEM_DOMAIN_VERTEX, 0);
-    intel_bo_write (&device->intel, vbo, 0, device->vbo_used, device->vbo_base);
-    device->last_vbo = vbo;
-    device->last_vbo_offset = (device->vbo_used+7)&-8;
-    device->last_vbo_space = vbo->base.size - device->last_vbo_offset;
-
-    device->vbo = 0;
-
-    device->vbo_used = device->vbo_offset = 0;
-    device->vertex_index = device->vertex_count = 0;
-
-    if (! i915_check_aperture_size (device, 1, I915_VBO_SIZE, I915_VBO_SIZE)) {
-	cairo_status_t status;
-
-	status = i915_batch_flush (device);
-	if (unlikely (status))
-	    longjmp (device->shader->unwind, status);
-
-	status = i915_shader_commit (device->shader, device);
-	if (unlikely (status))
-	    longjmp (device->shader->unwind, status);
-    }
-}
-
-/* XXX improve state tracker/difference and flush state on vertex emission */
-static void
-i915_device_reset (i915_device_t *device)
-{
-    if (device->current_source != NULL)
-	*device->current_source = 0;
-    if (device->current_mask != NULL)
-	*device->current_mask = 0;
-    if (device->current_clip != NULL)
-	*device->current_clip = 0;
-
-    device->current_target = NULL;
-    device->current_size = 0;
-    device->current_source = NULL;
-    device->current_mask = NULL;
-    device->current_clip = NULL;
-    device->current_texcoords = ~0;
-    device->current_blend = 0;
-    device->current_n_constants = 0;
-    device->current_n_samplers = 0;
-    device->current_n_maps = 0;
-    device->current_colorbuf = 0;
-    device->current_diffuse = 0;
-    device->current_program = ~0;
-    device->clear_alpha = ~0;
-
-    device->last_source_fragment = ~0;
-}
-
-static void
-i915_batch_cleanup (i915_device_t *device)
-{
-    int i;
-
-    for (i = 0; i < device->batch.exec_count; i++) {
-	intel_bo_t *bo = device->batch.target_bo[i];
-
-	bo->exec = NULL;
-	bo->batch_read_domains = 0;
-	bo->batch_write_domain = 0;
-	cairo_list_del (&bo->cache_list);
-
-	intel_bo_destroy (&device->intel, bo);
-    }
-
-    device->batch.exec_count = 0;
-    device->batch.reloc_count = 0;
-}
-
-static void
-i915_batch_vbo_finish (i915_device_t *device)
-{
-    assert (CAIRO_MUTEX_IS_LOCKED (device->intel.base.base.mutex));
-
-    if (device->vbo || i915_batch_space (device) < (int32_t) device->vbo_used) {
-	intel_bo_t *vbo;
-
-	if (device->vertex_count) {
-	    if (device->vbo == 0) {
-		OUT_DWORD (_3DSTATE_LOAD_STATE_IMMEDIATE_1 |
-			   I1_LOAD_S (0) |
-			   I1_LOAD_S (1) |
-			   1);
-		device->vbo = device->batch.used++;
-		device->vbo_max_index = device->batch.used;
-		OUT_DWORD ((device->floats_per_vertex << S1_VERTEX_WIDTH_SHIFT) |
-			(device->floats_per_vertex << S1_VERTEX_PITCH_SHIFT));
-	    }
-
-	    OUT_DWORD (PRIM3D_RECTLIST |
-		       PRIM3D_INDIRECT_SEQUENTIAL |
-		       device->vertex_count);
-	    OUT_DWORD (device->vertex_index);
-	}
-
-	if (device->last_vbo != NULL)
-	    intel_bo_destroy (&device->intel, device->last_vbo);
-
-	device->batch_base[device->vbo_max_index] |= device->vertex_index + device->vertex_count;
-
-	/* will include a few bytes of inter-array padding */
-	vbo = intel_bo_create (&device->intel,
-			       device->vbo_used, device->vbo_used,
-			       FALSE, I915_TILING_NONE, 0);
-	i915_batch_fill_reloc (device, device->vbo,
-			       vbo, 0,
-			       I915_GEM_DOMAIN_VERTEX, 0);
-	intel_bo_write (&device->intel, vbo, 0, device->vbo_used, device->vbo_base);
-	device->last_vbo = vbo;
-	device->last_vbo_offset = (device->vbo_used+7)&-8;
-	device->last_vbo_space = vbo->base.size - device->last_vbo_offset;
-
-	device->vbo = 0;
-    }
-    else
-    {
-	/* Only a single rectlist in this batch, and no active vertex buffer. */
-	OUT_DWORD (PRIM3D_RECTLIST | (device->vbo_used / 4 - 1));
-
-	memcpy (BATCH_PTR (device), device->vbo_base, device->vbo_used);
-	device->batch.used += device->vbo_used >> 2;
-    }
-
-    device->vbo_used = device->vbo_offset = 0;
-    device->vertex_index = device->vertex_count = 0;
-}
-
-cairo_status_t
-i915_batch_flush (i915_device_t *device)
-{
-    intel_bo_t *batch;
-    cairo_status_t status;
-    uint32_t length, offset;
-    int n;
-
-    assert (CAIRO_MUTEX_IS_LOCKED (device->intel.base.base.mutex));
-
-    if (device->vbo_used)
-	i915_batch_vbo_finish (device);
-
-    if (device->batch.used == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    i915_batch_emit_dword (device, MI_BATCH_BUFFER_END);
-    if ((device->batch.used & 1) != ((sizeof (device->batch_header)>>2) & 1))
-	i915_batch_emit_dword (device, MI_NOOP);
-
-    length = (device->batch.used << 2) + sizeof (device->batch_header);
-
-    /* NB: it is faster to copy the data then map/unmap the batch,
-     * presumably because we frequently only use a small part of the buffer.
-     */
-    batch = NULL;
-    if (device->last_vbo) {
-	if (length <= device->last_vbo_space) {
-	    batch = device->last_vbo;
-	    offset = device->last_vbo_offset;
-
-	    /* fixup the relocations */
-	    for (n = 0; n < device->batch.reloc_count; n++)
-		device->batch.reloc[n].offset += offset;
-	} else
-	    intel_bo_destroy (&device->intel, device->last_vbo);
-	device->last_vbo = NULL;
-    }
-    if (batch == NULL) {
-	batch = intel_bo_create (&device->intel,
-				 length, length,
-				 FALSE, I915_TILING_NONE, 0);
-	if (unlikely (batch == NULL)) {
-	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    i915_batch_cleanup (device);
-	    goto BAIL;
-	}
-
-	offset = 0;
-    }
-    intel_bo_write (&device->intel, batch, offset, length, device->batch_header);
-    status = i915_bo_exec (device, batch, offset);
-    intel_bo_destroy (&device->intel, batch);
-
-BAIL:
-    device->batch.used = 0;
-
-    intel_glyph_cache_unpin (&device->intel);
-    intel_snapshot_cache_thaw (&device->intel);
-
-    i915_device_reset (device);
-
-    return status;
-}
-
-#if 0
-static float *
-i915_add_rectangles (i915_device_t *device, int num_rects, int *count)
-{
-    float *vertices;
-    uint32_t size;
-    int cnt;
-
-    assert (device->floats_per_vertex);
-
-    size = device->rectangle_size;
-    if (unlikely (device->vbo_offset + size > I915_VBO_SIZE))
-	i915_vbo_finish (device);
-
-    vertices = (float *) (device->vbo_base + device->vbo_offset);
-    cnt = (I915_VBO_SIZE - device->vbo_offset) / size;
-    if (cnt > num_rects)
-	cnt = num_rects;
-    device->vbo_used = device->vbo_offset += size * cnt;
-    device->vertex_count += 3 * cnt;
-    *count = cnt;
-    return vertices;
-}
-#endif
-
-static cairo_surface_t *
-i915_surface_create_similar (void *abstract_other,
-			     cairo_content_t content,
-			     int width, int height)
-{
-    i915_surface_t *other;
-    cairo_format_t format;
-    uint32_t tiling = I915_TILING_DEFAULT;
-
-    other = abstract_other;
-    if (content == other->intel.drm.base.content)
-	format = other->intel.drm.format;
-    else
-	format = _cairo_format_from_content (content);
-
-    if (width * _cairo_format_bits_per_pixel (format) > 8 * 32*1024 || height > 64*1024)
-	return NULL;
-
-    /* we presume that a similar surface will be used for blitting */
-    if (i915_surface_needs_tiling (other))
-	tiling = I915_TILING_X;
-
-    return i915_surface_create_internal ((cairo_drm_device_t *) other->intel.drm.base.device,
-					 format,
-					 width, height,
-					 tiling, TRUE);
-}
-
-static cairo_status_t
-i915_surface_finish (void *abstract_surface)
-{
-    i915_surface_t *surface = abstract_surface;
-    i915_device_t *device = i915_device (surface);
-
-    if (surface->stencil != NULL) {
-	intel_bo_in_flight_add (&device->intel, surface->stencil);
-	intel_bo_destroy (&device->intel, surface->stencil);
-    }
-
-    if (surface->is_current_texture) {
-	if (surface->is_current_texture & CURRENT_SOURCE)
-	    device->current_source = NULL;
-	if (surface->is_current_texture & CURRENT_MASK)
-	    device->current_mask = NULL;
-	if (surface->is_current_texture & CURRENT_CLIP)
-	    device->current_clip = NULL;
-	device->current_n_samplers = 0;
-    }
-
-    if (surface == device->current_target)
-	device->current_target = NULL;
-
-    if (surface->cache != NULL) {
-	i915_image_private_t *node = surface->cache;
-	intel_buffer_cache_t *cache = node->container;
-
-	if (--cache->ref_count == 0) {
-	    intel_bo_in_flight_add (&device->intel, cache->buffer.bo);
-	    intel_bo_destroy (&device->intel, cache->buffer.bo);
-	    _cairo_rtree_fini (&cache->rtree);
-	    cairo_list_del (&cache->link);
-	    free (cache);
-	} else {
-	    node->node.state = CAIRO_RTREE_NODE_AVAILABLE;
-	    cairo_list_move (&node->node.link, &cache->rtree.available);
-	    _cairo_rtree_node_collapse (&cache->rtree, node->node.parent);
-	}
-    }
-
-    return intel_surface_finish (&surface->intel);
-}
-
-static cairo_status_t
-i915_surface_batch_flush (i915_surface_t *surface)
-{
-    cairo_status_t status;
-    intel_bo_t *bo;
-
-    assert (surface->intel.drm.fallback == NULL);
-
-    bo = to_intel_bo (surface->intel.drm.bo);
-    if (bo == NULL || bo->batch_write_domain == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    status = cairo_device_acquire (surface->intel.drm.base.device);
-    if (unlikely (status))
-	return status;
-
-    status = i915_batch_flush (i915_device (surface));
-    cairo_device_release (surface->intel.drm.base.device);
-
-    return status;
-}
-
-static cairo_status_t
-i915_surface_flush (void *abstract_surface,
-		    unsigned flags)
-{
-    i915_surface_t *surface = abstract_surface;
-    cairo_status_t status;
-
-    if (flags)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (surface->intel.drm.fallback == NULL) {
-	if (surface->intel.drm.base.finished) {
-	    /* Forgo flushing on finish as the user cannot access the surface directly. */
-	    return CAIRO_STATUS_SUCCESS;
-	}
-
-	if (surface->deferred_clear) {
-	    status = i915_surface_clear (surface);
-	    if (unlikely (status))
-		return status;
-	}
-
-	return i915_surface_batch_flush (surface);
-    }
-
-    return intel_surface_flush (abstract_surface, flags);
-}
-
-/* rasterisation */
-
-static cairo_status_t
-_composite_boxes_spans (void			*closure,
-			cairo_span_renderer_t	*renderer,
-			const cairo_rectangle_int_t	*extents)
-{
-    cairo_boxes_t *boxes = closure;
-    cairo_rectangular_scan_converter_t converter;
-    struct _cairo_boxes_chunk *chunk;
-    cairo_status_t status;
-    int i;
-
-    _cairo_rectangular_scan_converter_init (&converter, extents);
-    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	cairo_box_t *box = chunk->base;
-	for (i = 0; i < chunk->count; i++) {
-	    status = _cairo_rectangular_scan_converter_add_box (&converter, &box[i], 1);
-	    if (unlikely (status))
-		goto CLEANUP;
-	}
-    }
-
-    status = converter.base.generate (&converter.base, renderer);
-
-CLEANUP:
-    converter.base.destroy (&converter.base);
-    return status;
-}
-
-cairo_status_t
-i915_fixup_unbounded (i915_surface_t *dst,
-		      const cairo_composite_rectangles_t *extents,
-		      cairo_clip_t *clip)
-{
-    i915_shader_t shader;
-    i915_device_t *device;
-    cairo_status_t status;
-
-    if (clip != NULL) {
-	cairo_region_t *clip_region = NULL;
-
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-	assert (clip_region == NULL);
-
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    clip = NULL;
-    } else {
-	if (extents->bounded.width == extents->unbounded.width &&
-	    extents->bounded.height == extents->unbounded.height)
-	{
-	    return CAIRO_STATUS_SUCCESS;
-	}
-    }
-
-    if (clip != NULL) {
-	i915_shader_init (&shader, dst, CAIRO_OPERATOR_DEST_OVER, 1.);
-	i915_shader_set_clip (&shader, clip);
-	status = i915_shader_acquire_pattern (&shader,
-					      &shader.source,
-					      &_cairo_pattern_white.base,
-					      &extents->unbounded);
-	assert (status == CAIRO_STATUS_SUCCESS);
-    } else {
-	i915_shader_init (&shader, dst, CAIRO_OPERATOR_CLEAR, 1.);
-	status = i915_shader_acquire_pattern (&shader,
-					      &shader.source,
-					      &_cairo_pattern_clear.base,
-					      &extents->unbounded);
-	assert (status == CAIRO_STATUS_SUCCESS);
-    }
-
-    device = i915_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	return status;
-
-    status = i915_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto BAIL;
-
-    if (extents->bounded.width == 0 || extents->bounded.height == 0) {
-	shader.add_rectangle (&shader,
-			      extents->unbounded.x,
-			      extents->unbounded.y,
-			      extents->unbounded.width,
-			      extents->unbounded.height);
-    } else {
-	/* top */
-	if (extents->bounded.y != extents->unbounded.y) {
-	    shader.add_rectangle (&shader,
-				  extents->unbounded.x,
-				  extents->unbounded.y,
-				  extents->unbounded.width,
-				  extents->bounded.y - extents->unbounded.y);
-	}
-
-	/* left */
-	if (extents->bounded.x != extents->unbounded.x) {
-	    shader.add_rectangle (&shader,
-				  extents->unbounded.x,
-				  extents->bounded.y,
-				  extents->bounded.x - extents->unbounded.x,
-				  extents->bounded.height);
-	}
-
-	/* right */
-	if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) {
-	    shader.add_rectangle (&shader,
-				  extents->bounded.x + extents->bounded.width,
-				  extents->bounded.y,
-				  extents->unbounded.x + extents->unbounded.width - (extents->bounded.x + extents->bounded.width),
-				  extents->bounded.height);
-	}
-
-	/* bottom */
-	if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) {
-	    shader.add_rectangle (&shader,
-				  extents->unbounded.x,
-				  extents->bounded.y + extents->bounded.height,
-				  extents->unbounded.width,
-				  extents->unbounded.y + extents->unbounded.height - (extents->bounded.y + extents->bounded.height));
-	}
-    }
-
-    i915_shader_fini (&shader);
-  BAIL:
-    cairo_device_release (&device->intel.base.base);
-    return status;
-}
-
-static cairo_status_t
-i915_fixup_unbounded_boxes (i915_surface_t *dst,
-			    const cairo_composite_rectangles_t *extents,
-			    cairo_clip_t *clip,
-			    cairo_boxes_t *boxes)
-{
-    cairo_boxes_t clear;
-    cairo_box_t box;
-    cairo_region_t *clip_region = NULL;
-    cairo_status_t status;
-    struct _cairo_boxes_chunk *chunk;
-    int i;
-
-    if (boxes->num_boxes <= 1)
-	return i915_fixup_unbounded (dst, extents, clip);
-
-    _cairo_boxes_init (&clear);
-
-    box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width);
-    box.p1.y = _cairo_fixed_from_int (extents->unbounded.y);
-    box.p2.x = _cairo_fixed_from_int (extents->unbounded.x);
-    box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height);
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    clip = NULL;
-    }
-
-    if (clip_region == NULL) {
-	cairo_boxes_t tmp;
-
-	_cairo_boxes_init (&tmp);
-
-	status = _cairo_boxes_add (&tmp, &box);
-	assert (status == CAIRO_STATUS_SUCCESS);
-
-	tmp.chunks.next = &boxes->chunks;
-	tmp.num_boxes += boxes->num_boxes;
-
-	status = _cairo_bentley_ottmann_tessellate_boxes (&tmp,
-							  CAIRO_FILL_RULE_WINDING,
-							  &clear);
-
-	tmp.chunks.next = NULL;
-    } else {
-	pixman_box32_t *pbox;
-
-	pbox = pixman_region32_rectangles (&clip_region->rgn, &i);
-	_cairo_boxes_limit (&clear, (cairo_box_t *) pbox, i);
-
-	status = _cairo_boxes_add (&clear, &box);
-	assert (status == CAIRO_STATUS_SUCCESS);
-
-	for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	    for (i = 0; i < chunk->count; i++) {
-		status = _cairo_boxes_add (&clear, &chunk->base[i]);
-		if (unlikely (status)) {
-		    _cairo_boxes_fini (&clear);
-		    return status;
-		}
-	    }
-	}
-
-	status = _cairo_bentley_ottmann_tessellate_boxes (&clear,
-							  CAIRO_FILL_RULE_WINDING,
-							  &clear);
-    }
-
-    if (likely (status == CAIRO_STATUS_SUCCESS && clear.num_boxes)) {
-	i915_shader_t shader;
-	i915_device_t *device;
-
-	if (clip != NULL) {
-	    i915_shader_init (&shader, dst, CAIRO_OPERATOR_DEST_OVER, 1.);
-	    i915_shader_set_clip (&shader, clip);
-	    status = i915_shader_acquire_pattern (&shader,
-						  &shader.source,
-						  &_cairo_pattern_white.base,
-						  &extents->unbounded);
-	    assert (status == CAIRO_STATUS_SUCCESS);
-	} else {
-	    i915_shader_init (&shader, dst, CAIRO_OPERATOR_CLEAR, 1.);
-	    status = i915_shader_acquire_pattern (&shader,
-						  &shader.source,
-						  &_cairo_pattern_clear.base,
-						  &extents->unbounded);
-	    assert (status == CAIRO_STATUS_SUCCESS);
-	}
-
-	device = i915_device (dst);
-	status = cairo_device_acquire (&device->intel.base.base);
-	if (unlikely (status))
-	    goto err_shader;
-
-	status = i915_shader_commit (&shader, device);
-	if (unlikely (status))
-	    goto err_device;
-
-	for (chunk = &clear.chunks; chunk != NULL; chunk = chunk->next) {
-	    for (i = 0; i < chunk->count; i++) {
-		int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
-		int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
-		int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
-		int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
-
-		shader.add_rectangle (&shader, x1, y1, x2 - x1, y2 - y1);
-	    }
-	}
-err_device:
-	cairo_device_release (&device->intel.base.base);
-err_shader:
-	i915_shader_fini (&shader);
-    }
-
-    _cairo_boxes_fini (&clear);
-
-    return status;
-}
-
-static cairo_bool_t
-i915_can_blt (i915_surface_t *dst,
-	      const cairo_pattern_t *pattern)
-{
-    const cairo_surface_pattern_t *spattern;
-    i915_surface_t *src;
-
-    spattern = (const cairo_surface_pattern_t *) pattern;
-    src = (i915_surface_t *) spattern->surface;
-
-    if (src->intel.drm.base.device != dst->intel.drm.base.device)
-	return FALSE;
-
-    if (! i915_surface_needs_tiling (dst))
-	return FALSE;
-
-    if (! _cairo_matrix_is_translation (&pattern->matrix))
-	return FALSE;
-
-    if (! (pattern->filter == CAIRO_FILTER_NEAREST ||
-	   pattern->filter == CAIRO_FILTER_FAST))
-    {
-	if (! _cairo_fixed_is_integer (_cairo_fixed_from_double (pattern->matrix.x0)) ||
-	    ! _cairo_fixed_is_integer (_cairo_fixed_from_double (pattern->matrix.y0)))
-	{
-	    return FALSE;
-	}
-    }
-
-    return _cairo_format_bits_per_pixel (src->intel.drm.format) ==
-	_cairo_format_bits_per_pixel (dst->intel.drm.format);
-}
-
-static cairo_status_t
-i915_blt (i915_surface_t *src,
-	  i915_surface_t *dst,
-	  int src_x, int src_y,
-	  int width, int height,
-	  int dst_x, int dst_y,
-	  cairo_bool_t flush)
-{
-    i915_device_t *device;
-    intel_bo_t *bo_array[2];
-    cairo_status_t status;
-    int br13, cmd;
-
-    bo_array[0] = to_intel_bo (dst->intel.drm.bo);
-    bo_array[1] = to_intel_bo (src->intel.drm.bo);
-
-    status = i915_surface_fallback_flush (src);
-    if (unlikely (status))
-	return status;
-
-    device = i915_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	return status;
-
-    if (! i915_check_aperture_and_fences (device, bo_array, 2) ||
-	i915_batch_space (device) < 9)
-    {
-	status = i915_batch_flush (device);
-	if (unlikely (status))
-	    goto CLEANUP;
-    }
-
-    cmd = XY_SRC_COPY_BLT_CMD;
-    br13 = (0xCC << 16) | dst->intel.drm.stride;
-    switch (dst->intel.drm.format) {
-    default:
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-	ASSERT_NOT_REACHED;
-    case CAIRO_FORMAT_A8:
-	break;
-    case CAIRO_FORMAT_RGB16_565:
-	br13 |= BR13_565;
-	break;
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_ARGB32:
-	br13 |= BR13_8888;
-	cmd |= XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
-	break;
-    }
-
-    OUT_DWORD (cmd);
-    OUT_DWORD (br13);
-    OUT_DWORD ((dst_y << 16) | dst_x);
-    OUT_DWORD (((dst_y + height - 1) << 16) | (dst_x + width - 1));
-    OUT_RELOC_FENCED (dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-    OUT_DWORD ((src_y << 16) | src_x);
-    OUT_DWORD (src->intel.drm.stride);
-    OUT_RELOC_FENCED (src, I915_GEM_DOMAIN_RENDER, 0);
-    /* require explicit RenderCache flush for 2D -> 3D sampler? */
-    if (flush)
-	OUT_DWORD (MI_FLUSH);
-
-CLEANUP:
-    cairo_device_release (&device->intel.base.base);
-    return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
-i915_surface_copy_subimage (i915_device_t *device,
-			    i915_surface_t *src,
-			    const cairo_rectangle_int_t *extents,
-			    cairo_bool_t flush,
-			    i915_surface_t **clone_out)
-{
-    i915_surface_t *clone;
-    cairo_status_t status;
-
-    clone = (i915_surface_t *)
-	i915_surface_create_internal (&device->intel.base,
-				      src->intel.drm.format,
-				      extents->width,
-				      extents->height,
-				      I915_TILING_X, TRUE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    status = i915_blt (src, clone,
-		       extents->x, extents->y,
-		       extents->width, extents->height,
-		       0, 0,
-		       flush);
-
-    if (unlikely (status)) {
-	cairo_surface_destroy (&clone->intel.drm.base);
-	return status;
-    }
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i915_clear_boxes (i915_surface_t *dst,
-		  const cairo_boxes_t *boxes)
-{
-    i915_device_t *device = i915_device (dst);
-    const struct _cairo_boxes_chunk *chunk;
-    cairo_status_t status;
-    intel_bo_t *bo_array[1] = { to_intel_bo (dst->intel.drm.bo) };
-    int cmd, br13, clear = 0, i;
-
-    cmd = XY_COLOR_BLT_CMD;
-    br13 = (0xCC << 16) | dst->intel.drm.stride;
-    switch (dst->intel.drm.format) {
-    default:
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-	ASSERT_NOT_REACHED;
-    case CAIRO_FORMAT_A8:
-	break;
-    case CAIRO_FORMAT_RGB16_565:
-	br13 |= BR13_565;
-	break;
-    case CAIRO_FORMAT_RGB24:
-	clear = 0xff000000;
-    case CAIRO_FORMAT_ARGB32:
-	br13 |= BR13_8888;
-	cmd |= XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
-	break;
-    }
-
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	return status;
-
-    if (! i915_check_aperture_and_fences (device, bo_array, 1) ||
-	i915_batch_space (device) < 6 * boxes->num_boxes)
-    {
-	status = i915_batch_flush (device);
-	if (unlikely (status))
-	    goto RELEASE;
-    }
-
-    if (device->vertex_count)
-	i915_vbo_flush (device);
-
-    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	const cairo_box_t *box = chunk->base;
-	for (i = 0; i < chunk->count; i++) {
-	    int x1 = _cairo_fixed_integer_round (box[i].p1.x);
-	    int x2 = _cairo_fixed_integer_round (box[i].p2.x);
-	    int y1 = _cairo_fixed_integer_round (box[i].p1.y);
-	    int y2 = _cairo_fixed_integer_round (box[i].p2.y);
-
-	    if (x2 <= x1 || y2 <= y1)
-		continue;
-
-	    OUT_DWORD (cmd);
-	    OUT_DWORD (br13);
-	    OUT_DWORD ((y1 << 16) | x1);
-	    OUT_DWORD (((y2 - 1) << 16) | (x2 - 1));
-	    OUT_RELOC_FENCED (dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-	    OUT_DWORD (clear);
-	}
-    }
-
-RELEASE:
-    cairo_device_release (&device->intel.base.base);
-    return status;
-}
-
-static cairo_status_t
-i915_surface_extract_X_from_Y (i915_device_t *device,
-			       i915_surface_t *src,
-			       const cairo_rectangle_int_t *extents,
-			       i915_surface_t **clone_out)
-{
-    i915_surface_t *clone;
-    i915_shader_t shader;
-    cairo_surface_pattern_t pattern;
-    cairo_rectangle_int_t rect;
-    cairo_status_t status;
-
-    status = i915_surface_fallback_flush (src);
-    if (unlikely (status))
-	return status;
-
-    clone = (i915_surface_t *)
-	i915_surface_create_internal (&device->intel.base,
-				      src->intel.drm.format,
-				      extents->width,
-				      extents->height,
-				      I915_TILING_X, TRUE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    i915_shader_init (&shader, clone, CAIRO_OPERATOR_SOURCE, 1.);
-
-    _cairo_pattern_init_for_surface (&pattern, &src->intel.drm.base);
-    pattern.base.filter = CAIRO_FILTER_NEAREST;
-    cairo_matrix_init_translate (&pattern.base.matrix, extents->x, extents->y);
-
-    rect.x = rect.y = 0;
-    rect.width = extents->width;
-    rect.height = extents->height;
-    status = i915_shader_acquire_pattern (&shader, &shader.source, &pattern.base, &rect);
-    _cairo_pattern_fini (&pattern.base);
-
-    if (unlikely (status))
-	goto err_shader;
-
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto err_shader;
-
-    status = i915_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto err_device;
-
-    shader.add_rectangle (&shader, 0, 0, extents->width, extents->height);
-
-    cairo_device_release (&device->intel.base.base);
-    i915_shader_fini (&shader);
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-
-err_device:
-    cairo_device_release (&device->intel.base.base);
-err_shader:
-    i915_shader_fini (&shader);
-    cairo_surface_destroy (&clone->intel.drm.base);
-    return status;
-}
-
-static cairo_status_t
-i915_blt_boxes (i915_surface_t *dst,
-		const cairo_pattern_t *pattern,
-		const cairo_rectangle_int_t *extents,
-		const cairo_boxes_t *boxes)
-{
-    const cairo_surface_pattern_t *spattern;
-    i915_device_t *device;
-    i915_surface_t *src;
-    cairo_surface_t *free_me = NULL;
-    const struct _cairo_boxes_chunk *chunk;
-    cairo_status_t status;
-    int br13, cmd, tx, ty;
-    intel_bo_t *bo_array[2];
-    int i;
-
-    if (! i915_can_blt (dst, pattern))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    spattern = (const cairo_surface_pattern_t *) pattern;
-    src = (i915_surface_t *) spattern->surface;
-
-    if (src->intel.drm.base.is_clear)
-	return i915_clear_boxes (dst, boxes);
-
-    if (pattern->extend != CAIRO_EXTEND_NONE &&
-	(extents->x + tx < 0 ||
-	 extents->y + ty < 0 ||
-	 extents->x + tx + extents->width  > src->intel.drm.width ||
-	 extents->y + ty + extents->height > src->intel.drm.height))
-    {
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    status = i915_surface_fallback_flush (src);
-    if (unlikely (status))
-	return status;
-
-    tx = _cairo_lround (pattern->matrix.x0);
-    ty = _cairo_lround (pattern->matrix.y0);
-
-    device = i915_device (dst);
-    if (to_intel_bo (src->intel.drm.bo)->tiling == I915_TILING_Y) {
-	cairo_rectangle_int_t extents;
-
-	_cairo_boxes_extents (boxes, &extents);
-	extents.x += tx;
-	extents.y += ty;
-
-	status = i915_surface_extract_X_from_Y (device, src, &extents, &src);
-	if (unlikely (status))
-	    return status;
-
-	free_me = &src->intel.drm.base;
-	tx = -extents.x;
-	ty = -extents.y;
-    }
-
-    bo_array[0] = to_intel_bo (dst->intel.drm.bo);
-    bo_array[1] = to_intel_bo (src->intel.drm.bo);
-
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto CLEANUP_SURFACE;
-
-    if (! i915_check_aperture_and_fences (device, bo_array, 2) ||
-	i915_batch_space (device) < 8 * boxes->num_boxes)
-    {
-	status = i915_batch_flush (device);
-	if (unlikely (status))
-	    goto CLEANUP_DEVICE;
-    }
-
-    cmd = XY_SRC_COPY_BLT_CMD;
-    br13 = (0xCC << 16) | dst->intel.drm.stride;
-    switch (dst->intel.drm.format) {
-    default:
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-	ASSERT_NOT_REACHED;
-    case CAIRO_FORMAT_A8:
-	break;
-    case CAIRO_FORMAT_RGB16_565:
-	br13 |= BR13_565;
-	break;
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_ARGB32:
-	br13 |= BR13_8888;
-	cmd |= XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
-	break;
-    }
-
-    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	const cairo_box_t *box = chunk->base;
-	for (i = 0; i < chunk->count; i++) {
-	    int x1 = _cairo_fixed_integer_round (box[i].p1.x);
-	    int x2 = _cairo_fixed_integer_round (box[i].p2.x);
-	    int y1 = _cairo_fixed_integer_round (box[i].p1.y);
-	    int y2 = _cairo_fixed_integer_round (box[i].p2.y);
-
-	    if (x1 + tx < 0)
-		x1 = -tx;
-	    if (x2 + tx > src->intel.drm.width)
-		x2 = src->intel.drm.width - tx;
-
-	    if (y1 + ty < 0)
-		y1 = -ty;
-	    if (y2 + ty > src->intel.drm.height)
-		y2 = src->intel.drm.height - ty;
-
-	    if (x2 <= x1 || y2 <= y1)
-		continue;
-	    if (x2 < 0 || y2 < 0)
-		continue;
-	    if (x1 >= dst->intel.drm.width || y2 >= dst->intel.drm.height)
-		continue;
-
-	    OUT_DWORD (cmd);
-	    OUT_DWORD (br13);
-	    OUT_DWORD ((y1 << 16) | x1);
-	    OUT_DWORD (((y2 - 1) << 16) | (x2 - 1));
-	    OUT_RELOC_FENCED (dst, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-	    OUT_DWORD (((y1 + ty) << 16) | (x1 + tx));
-	    OUT_DWORD (src->intel.drm.stride);
-	    OUT_RELOC_FENCED (src, I915_GEM_DOMAIN_RENDER, 0);
-	}
-    }
-
-    /* XXX fixup blank portions */
-
-CLEANUP_DEVICE:
-    cairo_device_release (&device->intel.base.base);
-CLEANUP_SURFACE:
-    cairo_surface_destroy (free_me);
-    return status;
-}
-
-static cairo_status_t
-_upload_image_inplace (i915_surface_t *surface,
-		       const cairo_pattern_t *source,
-		       const cairo_rectangle_int_t *extents,
-		       const cairo_boxes_t *boxes)
-{
-    i915_device_t *device;
-    const cairo_surface_pattern_t *pattern;
-    cairo_image_surface_t *image;
-    const struct _cairo_boxes_chunk *chunk;
-    intel_bo_t *bo;
-    int tx, ty, i;
-
-    if (source->type != CAIRO_PATTERN_TYPE_SURFACE)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    pattern = (const cairo_surface_pattern_t *) source;
-    if (pattern->surface->type != CAIRO_SURFACE_TYPE_IMAGE)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    if (! _cairo_matrix_is_integer_translation (&source->matrix, &tx, &ty))
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    image = (cairo_image_surface_t *) pattern->surface;
-    if (source->extend != CAIRO_EXTEND_NONE &&
-	(extents->x + tx < 0 ||
-	 extents->y + ty < 0 ||
-	 extents->x + tx + extents->width  > image->width ||
-	 extents->y + ty + extents->height > image->height))
-    {
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    device = i915_device (surface);
-    bo = to_intel_bo (surface->intel.drm.bo);
-    if (bo->exec != NULL || ! intel_bo_is_inactive (&device->intel, bo)) {
-	intel_bo_t *new_bo;
-	cairo_bool_t need_clear = FALSE;
-
-	if (boxes->num_boxes != 1 ||
-	    extents->width < surface->intel.drm.width ||
-	    extents->height < surface->intel.drm.height)
-	{
-	    if (! surface->intel.drm.base.is_clear)
-		return CAIRO_INT_STATUS_UNSUPPORTED;
-
-	    need_clear = TRUE;
-	}
-
-	new_bo = intel_bo_create (&device->intel,
-				  bo->full_size, bo->base.size,
-				  FALSE, bo->tiling, bo->stride);
-	if (unlikely (new_bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	intel_bo_in_flight_add (&device->intel, bo);
-	intel_bo_destroy (&device->intel, bo);
-
-	bo = new_bo;
-	surface->intel.drm.bo = &bo->base;
-
-	if (need_clear) {
-	    memset (intel_bo_map (&device->intel, bo), 0,
-		    bo->stride * surface->intel.drm.height);
-	}
-    }
-
-    if (image->format == surface->intel.drm.format) {
-	for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	    cairo_box_t *box = chunk->base;
-	    for (i = 0; i < chunk->count; i++) {
-		int x1 = _cairo_fixed_integer_round (box[i].p1.x);
-		int x2 = _cairo_fixed_integer_round (box[i].p2.x);
-		int y1 = _cairo_fixed_integer_round (box[i].p1.y);
-		int y2 = _cairo_fixed_integer_round (box[i].p2.y);
-		cairo_status_t status;
-
-		if (x1 + tx < 0)
-		    x1 = -tx;
-		if (x2 + tx > image->width)
-		    x2 = image->width - tx;
-
-		if (y1 + ty < 0)
-		    y1 = -ty;
-		if (y2 + ty > image->height)
-		    y2 = image->height - ty;
-
-		if (x2 <= x1 || y2 <= y1)
-		    continue;
-		if (x2 < 0 || y2 < 0)
-		    continue;
-		if (x1 >= surface->intel.drm.width || y2 >= surface->intel.drm.height)
-		    continue;
-
-		status = intel_bo_put_image (&device->intel,
-					     bo,
-					     image,
-					     x1 + tx, y1 + ty,
-					     x2 - x1, y2 - y1,
-					     x1, y1);
-		if (unlikely (status))
-		    return status;
-	    }
-	}
-    } else {
-	pixman_image_t *dst;
-	void *ptr;
-
-	ptr = intel_bo_map (&device->intel, bo);
-	if (unlikely (ptr == NULL))
-	    return _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
-
-	dst = pixman_image_create_bits (_cairo_format_to_pixman_format_code (surface->intel.drm.format),
-					surface->intel.drm.width,
-					surface->intel.drm.height,
-					ptr,
-					surface->intel.drm.stride);
-	if (unlikely (dst == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	    cairo_box_t *box = chunk->base;
-	    for (i = 0; i < chunk->count; i++) {
-		int x1 = _cairo_fixed_integer_round (box[i].p1.x);
-		int x2 = _cairo_fixed_integer_round (box[i].p2.x);
-		int y1 = _cairo_fixed_integer_round (box[i].p1.y);
-		int y2 = _cairo_fixed_integer_round (box[i].p2.y);
-
-		if (x1 + tx < 0)
-		    x1 = -tx;
-		if (x2 + tx > image->width)
-		    x2 = image->width - tx;
-
-		if (y1 + ty < 0)
-		    y1 = -ty;
-		if (y2 + ty > image->height)
-		    y2 = image->height - ty;
-
-		if (x2 <= x1 || y2 <= y1)
-		    continue;
-		if (x2 < 0 || y2 < 0)
-		    continue;
-		if (x1 >= surface->intel.drm.width || y2 >= surface->intel.drm.height)
-		    continue;
-
-		pixman_image_composite32 (PIXMAN_OP_SRC,
-					  image->pixman_image, NULL, dst,
-					  x1 + tx, y1 + ty,
-					  0, 0,
-					  x1, y1,
-					  x2 - x1, y2 - y1);
-	    }
-	}
-
-	pixman_image_unref (dst);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-_composite_boxes (i915_surface_t *dst,
-		  cairo_operator_t op,
-		  const cairo_pattern_t *pattern,
-		  cairo_boxes_t *boxes,
-		  cairo_antialias_t antialias,
-		  cairo_clip_t *clip,
-		  double opacity,
-		  const cairo_composite_rectangles_t *extents)
-{
-    cairo_bool_t need_clip_surface = FALSE;
-    cairo_region_t *clip_region = NULL;
-    const struct _cairo_boxes_chunk *chunk;
-    cairo_status_t status;
-    i915_shader_t shader;
-    i915_device_t *device;
-    int i;
-
-    /* If the boxes are not pixel-aligned, we will need to compute a real mask */
-    if (antialias != CAIRO_ANTIALIAS_NONE) {
-	if (! boxes->is_pixel_aligned)
-	    return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    if (clip == NULL && op == CAIRO_OPERATOR_SOURCE && opacity == 1.) {
-	if (pattern->type == CAIRO_PATTERN_TYPE_SURFACE) {
-	    status = i915_blt_boxes (dst, pattern, &extents->bounded, boxes);
-	    if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
-		status = _upload_image_inplace (dst, pattern,
-						&extents->bounded, boxes);
-	    }
-	    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-		return status;
-	}
-    }
-
-    if (i915_surface_needs_tiling (dst)) {
-	ASSERT_NOT_REACHED;
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    i915_shader_init (&shader, dst, op, opacity);
-
-    status = i915_shader_acquire_pattern (&shader,
-					  &shader.source,
-					  pattern,
-					  &extents->bounded);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-	need_clip_surface = status == CAIRO_INT_STATUS_UNSUPPORTED;
-	if (need_clip_surface)
-	    i915_shader_set_clip (&shader, clip);
-    }
-
-    device = i915_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto err_shader;
-
-    status = i915_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto err_device;
-
-    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	cairo_box_t *box = chunk->base;
-	for (i = 0; i < chunk->count; i++) {
-	    int x1 = _cairo_fixed_integer_round (box[i].p1.x);
-	    int y1 = _cairo_fixed_integer_round (box[i].p1.y);
-	    int x2 = _cairo_fixed_integer_round (box[i].p2.x);
-	    int y2 = _cairo_fixed_integer_round (box[i].p2.y);
-
-	    if (x2 > x1 && y2 > y1)
-		shader.add_rectangle (&shader, x1, y1, x2 - x1, y2 - y1);
-	}
-    }
-
-    if (! extents->is_bounded)
-	status = i915_fixup_unbounded_boxes (dst, extents, clip, boxes);
-
-  err_device:
-    cairo_device_release (&device->intel.base.base);
-  err_shader:
-    i915_shader_fini (&shader);
-
-    return status;
-}
-
-cairo_status_t
-i915_surface_clear (i915_surface_t *dst)
-{
-    i915_device_t *device;
-    cairo_status_t status;
-    intel_bo_t *bo_array[1] = { to_intel_bo (dst->intel.drm.bo) };
-
-    device = i915_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	return status;
-
-    if (i915_surface_needs_tiling (dst)) {
-	int cmd, br13, clear = 0;
-
-	if (! i915_check_aperture_and_fences (device, bo_array, 1) ||
-	    i915_batch_space (device) < 6)
-	{
-	    status = i915_batch_flush (device);
-	    if (unlikely (status)) {
-		cairo_device_release (&device->intel.base.base);
-		return status;
-	    }
-	}
-
-	if (device->vertex_count)
-	    i915_vbo_flush (device);
-
-	cmd = XY_COLOR_BLT_CMD;
-	br13 = (0xCC << 16) | dst->intel.drm.stride;
-	switch (dst->intel.drm.format) {
-	default:
-	case CAIRO_FORMAT_INVALID:
-	case CAIRO_FORMAT_A1:
-	    ASSERT_NOT_REACHED;
-	case CAIRO_FORMAT_A8:
-	    break;
-	case CAIRO_FORMAT_RGB16_565:
-	    br13 |= BR13_565;
-	    break;
-	case CAIRO_FORMAT_RGB24:
-	    clear = 0xff000000;
-	case CAIRO_FORMAT_ARGB32:
-	    br13 |= BR13_8888;
-	    cmd |= XY_BLT_WRITE_ALPHA | XY_BLT_WRITE_RGB;
-	    break;
-	}
-
-	OUT_DWORD (cmd);
-	OUT_DWORD (br13);
-	OUT_DWORD (0);
-	OUT_DWORD (((dst->intel.drm.height - 1) << 16) |
-		   (dst->intel.drm.width - 1));
-	OUT_RELOC_FENCED (dst,
-			  I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
-	OUT_DWORD (clear);
-    } else {
-	if (! i915_check_aperture (device, bo_array, 1) ||
-	    i915_batch_space (device) < 24)
-	{
-	    status = i915_batch_flush (device);
-	    if (unlikely (status)) {
-		cairo_device_release (&device->intel.base.base);
-		return status;
-	    }
-	}
-
-	if (device->vertex_count)
-	    i915_vbo_flush (device);
-
-	i915_set_dst (device, dst);
-
-	/* set clear parameters */
-	if (device->clear_alpha != (dst->intel.drm.base.content & CAIRO_CONTENT_ALPHA)) {
-	    device->clear_alpha = dst->intel.drm.base.content & CAIRO_CONTENT_ALPHA;
-	    OUT_DWORD (_3DSTATE_CLEAR_PARAMETERS);
-	    OUT_DWORD (CLEARPARAM_CLEAR_RECT | CLEARPARAM_WRITE_COLOR);
-	    /* ZONE_INIT color */
-	    if (device->clear_alpha) /* XXX depends on pixel format, 16bit needs replication, 8bit? */
-		OUT_DWORD (0x00000000);
-	    else
-		OUT_DWORD (0xff000000);
-	    OUT_DWORD (0); /* ZONE_INIT depth */
-	    /* CLEAR_RECT color */
-	    if (device->clear_alpha)
-		OUT_DWORD (0x00000000);
-	    else
-		OUT_DWORD (0xff000000);
-	    OUT_DWORD (0); /* CLEAR_RECT depth */
-	    OUT_DWORD (0); /* CLEAR_RECT stencil */
-	}
-
-	OUT_DWORD (PRIM3D_CLEAR_RECT | 5);
-	OUT_DWORD (pack_float (dst->intel.drm.width));
-	OUT_DWORD (pack_float (dst->intel.drm.height));
-	OUT_DWORD (0);
-	OUT_DWORD (pack_float (dst->intel.drm.height));
-	OUT_DWORD (0);
-	OUT_DWORD (0);
-    }
-
-    cairo_device_release (&device->intel.base.base);
-
-    dst->deferred_clear = FALSE;
-    return status;
-}
-
-static cairo_status_t
-_clip_and_composite_boxes (i915_surface_t *dst,
-			   cairo_operator_t op,
-			   const cairo_pattern_t *src,
-			   cairo_boxes_t *boxes,
-			   cairo_antialias_t antialias,
-			   const cairo_composite_rectangles_t *extents,
-			   cairo_clip_t *clip,
-			   double opacity)
-{
-    cairo_status_t status;
-
-    if (boxes->num_boxes == 0) {
-	if (extents->is_bounded)
-	    return CAIRO_STATUS_SUCCESS;
-
-	return i915_fixup_unbounded (dst, extents, clip);
-    }
-
-    if (clip == NULL &&
-	(op == CAIRO_OPERATOR_SOURCE || (op == CAIRO_OPERATOR_OVER && dst->intel.drm.base.is_clear)) &&
-	opacity == 1. &&
-	boxes->num_boxes == 1 &&
-	extents->bounded.width  == dst->intel.drm.width &&
-	extents->bounded.height == dst->intel.drm.height)
-    {
-	op = CAIRO_OPERATOR_SOURCE;
-	dst->deferred_clear = FALSE;
-
-	status = _upload_image_inplace (dst, src,
-					&extents->bounded, boxes);
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    return status;
-    }
-
-    if (dst->deferred_clear) {
-	status = i915_surface_clear (dst);
-	if (unlikely (status))
-	    return status;
-    }
-
-    /* Use a fast path if the boxes are pixel aligned */
-    status = _composite_boxes (dst, op, src, boxes, antialias, clip, opacity, extents);
-    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	return status;
-
-    /* Otherwise render the boxes via an implicit mask and composite in the usual
-     * fashion.
-     */
-    return i915_clip_and_composite_spans (dst, op, src, antialias,
-					  _composite_boxes_spans, boxes,
-					  extents, clip, opacity);
-}
-
-static cairo_clip_path_t *
-_clip_get_solitary_path (cairo_clip_t *clip)
-{
-    cairo_clip_path_t *iter = clip->path;
-    cairo_clip_path_t *path = NULL;
-
-    do {
-	if ((iter->flags & CAIRO_CLIP_PATH_IS_BOX) == 0) {
-	    if (path != NULL)
-		return FALSE;
-
-	    path = iter;
-	}
-	iter = iter->prev;
-    } while (iter != NULL);
-
-    return path;
-}
-
-typedef struct {
-    cairo_polygon_t		polygon;
-    cairo_fill_rule_t		 fill_rule;
-    cairo_antialias_t		 antialias;
-} composite_polygon_info_t;
-
-static cairo_status_t
-_composite_polygon_spans (void                          *closure,
-			  cairo_span_renderer_t		*renderer,
-			  const cairo_rectangle_int_t   *extents)
-{
-    composite_polygon_info_t *info = closure;
-    cairo_botor_scan_converter_t converter;
-    cairo_status_t status;
-    cairo_box_t box;
-
-    box.p1.x = _cairo_fixed_from_int (extents->x);
-    box.p1.y = _cairo_fixed_from_int (extents->y);
-    box.p2.x = _cairo_fixed_from_int (extents->x + extents->width);
-    box.p2.y = _cairo_fixed_from_int (extents->y + extents->height);
-
-    _cairo_botor_scan_converter_init (&converter, &box, info->fill_rule);
-
-    status = converter.base.add_polygon (&converter.base, &info->polygon);
-    if (likely (status == CAIRO_STATUS_SUCCESS))
-	status = converter.base.generate (&converter.base, renderer);
-
-    converter.base.destroy (&converter.base);
-
-    return status;
-}
-
-static cairo_int_status_t
-i915_surface_fill_with_alpha (void			*abstract_dst,
-			      cairo_operator_t		 op,
-			      const cairo_pattern_t	*source,
-			      cairo_path_fixed_t	*path,
-			      cairo_fill_rule_t		 fill_rule,
-			      double			 tolerance,
-			      cairo_antialias_t		 antialias,
-			      cairo_clip_t		*clip,
-			      double			 opacity)
-{
-    i915_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    composite_polygon_info_t info;
-    cairo_box_t boxes_stack[32], *clip_boxes = boxes_stack;
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    int num_boxes = ARRAY_LENGTH (boxes_stack);
-    cairo_status_t status;
-
-    status = _cairo_composite_rectangles_init_for_fill (&extents,
-							dst->intel.drm.width,
-							dst->intel.drm.height,
-							op, source, path,
-							clip);
-    if (unlikely (status))
-	return status;
-
-    if (_cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (extents.is_bounded && clip != NULL) {
-	cairo_clip_path_t *clip_path;
-
-	if (((clip_path = _clip_get_solitary_path (clip)) != NULL) &&
-	    _cairo_path_fixed_equal (&clip_path->path, path))
-	{
-	    clip = NULL;
-	}
-    }
-
-    if (clip != NULL) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	have_clip = TRUE;
-    }
-
-    status = _cairo_clip_to_boxes (&clip, &extents, &clip_boxes, &num_boxes);
-    if (unlikely (status)) {
-	if (have_clip)
-	    _cairo_clip_fini (&local_clip);
-
-	return status;
-    }
-
-    assert (! _cairo_path_fixed_fill_is_empty (path));
-
-    if (_cairo_path_fixed_fill_is_rectilinear (path)) {
-	cairo_boxes_t boxes;
-
-	_cairo_boxes_init (&boxes);
-	_cairo_boxes_limit (&boxes, clip_boxes, num_boxes);
-	status = _cairo_path_fixed_fill_rectilinear_to_boxes (path,
-							      fill_rule,
-							      &boxes);
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = _clip_and_composite_boxes (dst, op, source,
-						&boxes, antialias,
-						&extents, clip,
-						opacity);
-	}
-
-	_cairo_boxes_fini (&boxes);
-
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    goto CLEANUP_BOXES;
-    }
-
-    _cairo_polygon_init (&info.polygon, clip_boxes, num_boxes);
-
-    status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &info.polygon);
-    if (unlikely (status))
-	goto CLEANUP_POLYGON;
-
-    if (extents.is_bounded) {
-	cairo_rectangle_int_t rect;
-
-	_cairo_box_round_to_rectangle (&info.polygon.extents, &rect);
-	if (! _cairo_rectangle_intersect (&extents.bounded, &rect))
-	    goto CLEANUP_POLYGON;
-    }
-
-    if (info.polygon.num_edges == 0) {
-	if (! extents.is_bounded)
-	    status = i915_fixup_unbounded (dst, &extents, clip);
-
-	goto CLEANUP_POLYGON;
-    }
-
-    info.fill_rule = fill_rule;
-    info.antialias = antialias;
-    status = i915_clip_and_composite_spans (dst, op, source, antialias,
-					    _composite_polygon_spans, &info,
-					    &extents, clip, opacity);
-
-CLEANUP_POLYGON:
-    _cairo_polygon_fini (&info.polygon);
-
-CLEANUP_BOXES:
-    if (clip_boxes != boxes_stack)
-	free (clip_boxes);
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static cairo_int_status_t
-i915_surface_paint_with_alpha (void			*abstract_dst,
-			       cairo_operator_t		 op,
-			       const cairo_pattern_t	*source,
-			       cairo_clip_t		*clip,
-			       double			 opacity)
-{
-    i915_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    cairo_clip_path_t *clip_path;
-    cairo_boxes_t boxes;
-    int num_boxes = ARRAY_LENGTH (boxes.boxes_embedded);
-    cairo_box_t *clip_boxes = boxes.boxes_embedded;
-    cairo_status_t status;
-
-    status = _cairo_composite_rectangles_init_for_paint (&extents,
-							 dst->intel.drm.width,
-							 dst->intel.drm.height,
-							 op, source,
-							 clip);
-    if (unlikely (status))
-	return status;
-
-    if (_cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	have_clip = TRUE;
-    }
-
-    status = _cairo_clip_to_boxes (&clip, &extents, &clip_boxes, &num_boxes);
-    if (unlikely (status)) {
-	if (have_clip)
-	    _cairo_clip_fini (&local_clip);
-
-	return status;
-    }
-
-    /* If the clip cannot be reduced to a set of boxes, we will need to
-     * use a clipmask. Paint is special as it is the only operation that
-     * does not implicitly use a mask, so we may be able to reduce this
-     * operation to a fill...
-     */
-    if (clip != NULL &&
-	extents.is_bounded &&
-	(clip_path = _clip_get_solitary_path (clip)) != NULL)
-    {
-	status = i915_surface_fill_with_alpha (dst, op, source,
-					       &clip_path->path,
-					       clip_path->fill_rule,
-					       clip_path->tolerance,
-					       clip_path->antialias,
-					       NULL, opacity);
-    }
-    else
-    {
-	_cairo_boxes_init_for_array (&boxes, clip_boxes, num_boxes);
-	status = _clip_and_composite_boxes (dst, op, source,
-					    &boxes, CAIRO_ANTIALIAS_DEFAULT,
-					    &extents, clip, opacity);
-    }
-    if (clip_boxes != boxes.boxes_embedded)
-	free (clip_boxes);
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static cairo_int_status_t
-i915_surface_paint (void			*abstract_dst,
-		    cairo_operator_t		 op,
-		    const cairo_pattern_t	*source,
-		    cairo_clip_t		*clip)
-{
-    i915_surface_t *dst = abstract_dst;
-
-    /* XXX unsupported operators? use pixel shader blending, eventually */
-
-    if (op == CAIRO_OPERATOR_CLEAR && clip == NULL) {
-	dst->deferred_clear = TRUE;
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    return i915_surface_paint_with_alpha (dst, op, source, clip, 1.);
-}
-
-static cairo_int_status_t
-i915_surface_mask (void				*abstract_dst,
-		   cairo_operator_t		 op,
-		   const cairo_pattern_t	*source,
-		   const cairo_pattern_t	*mask,
-		   cairo_clip_t			*clip)
-{
-    i915_surface_t *dst = abstract_dst;
-    i915_device_t *device;
-    cairo_composite_rectangles_t extents;
-    i915_shader_t shader;
-    cairo_clip_t local_clip;
-    cairo_region_t *clip_region = NULL;
-    cairo_bool_t need_clip_surface = FALSE;
-    cairo_bool_t have_clip = FALSE;
-    cairo_status_t status;
-
-    if (mask->type == CAIRO_PATTERN_TYPE_SOLID) {
-	const cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) mask;
-	return i915_surface_paint_with_alpha (dst, op, source, clip, solid->color.alpha);
-    }
-
-    status = _cairo_composite_rectangles_init_for_mask (&extents,
-							dst->intel.drm.width,
-							dst->intel.drm.height,
-							op, source, mask, clip);
-    if (unlikely (status))
-	return status;
-
-    if (_cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL && extents.is_bounded) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	status = _cairo_clip_rectangle (clip, &extents.bounded);
-	if (unlikely (status)) {
-	    _cairo_clip_fini (&local_clip);
-	    return status;
-	}
-
-	have_clip = TRUE;
-    }
-
-    i915_shader_init (&shader, dst, op, 1.);
-
-    status = i915_shader_acquire_pattern (&shader,
-					  &shader.source,
-					  source,
-					  &extents.bounded);
-    if (unlikely (status))
-	goto err_shader;
-
-    status = i915_shader_acquire_pattern (&shader,
-					  &shader.mask,
-					  mask,
-					  &extents.bounded);
-    if (unlikely (status))
-	goto err_shader;
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	if (unlikely (_cairo_status_is_error (status) ||
-		      status == CAIRO_INT_STATUS_NOTHING_TO_DO))
-	{
-	    goto err_shader;
-	}
-
-	need_clip_surface = status == CAIRO_INT_STATUS_UNSUPPORTED;
-	if (need_clip_surface)
-	    i915_shader_set_clip (&shader, clip);
-
-	if (clip_region != NULL) {
-	    cairo_rectangle_int_t rect;
-	    cairo_bool_t is_empty;
-
-	    status = CAIRO_STATUS_SUCCESS;
-	    cairo_region_get_extents (clip_region, &rect);
-	    is_empty = ! _cairo_rectangle_intersect (&extents.unbounded, &rect);
-	    if (unlikely (is_empty))
-		goto err_shader;
-
-	    is_empty = ! _cairo_rectangle_intersect (&extents.bounded, &rect);
-	    if (unlikely (is_empty && extents.is_bounded))
-		goto err_shader;
-
-	    if (cairo_region_num_rectangles (clip_region) == 1)
-		clip_region = NULL;
-	}
-    }
-
-    if (i915_surface_needs_tiling (dst)) {
-	ASSERT_NOT_REACHED;
-	return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    device = i915_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto err_shader;
-
-    if (dst->deferred_clear) {
-	status = i915_surface_clear (dst);
-	if (unlikely (status))
-	    goto err_shader;
-    }
-
-    status = i915_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto err_device;
-
-    if (clip_region != NULL) {
-	unsigned int n, num_rectangles;
-
-	num_rectangles = cairo_region_num_rectangles (clip_region);
-	for (n = 0; n < num_rectangles; n++) {
-	    cairo_rectangle_int_t rect;
-
-	    cairo_region_get_rectangle (clip_region, n, &rect);
-
-	    shader.add_rectangle (&shader,
-				  rect.x, rect.y,
-				  rect.x + rect.width, rect.y + rect.height);
-	}
-    } else {
-	shader.add_rectangle (&shader,
-			      extents.bounded.x, extents.bounded.y,
-			      extents.bounded.x + extents.bounded.width,
-			      extents.bounded.y + extents.bounded.height);
-    }
-
-    if (! extents.is_bounded)
-	status = i915_fixup_unbounded (dst, &extents, clip);
-
-  err_device:
-    cairo_device_release (&device->intel.base.base);
-  err_shader:
-    i915_shader_fini (&shader);
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static cairo_int_status_t
-i915_surface_stroke (void			*abstract_dst,
-		     cairo_operator_t		 op,
-		     const cairo_pattern_t	*source,
-		     cairo_path_fixed_t		*path,
-		     const cairo_stroke_style_t	*stroke_style,
-		     const cairo_matrix_t	*ctm,
-		     const cairo_matrix_t	*ctm_inverse,
-		     double			 tolerance,
-		     cairo_antialias_t		 antialias,
-		     cairo_clip_t		*clip)
-{
-    i915_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    composite_polygon_info_t info;
-    cairo_box_t boxes_stack[32], *clip_boxes = boxes_stack;
-    int num_boxes = ARRAY_LENGTH (boxes_stack);
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    cairo_status_t status;
-
-    status = _cairo_composite_rectangles_init_for_stroke (&extents,
-							  dst->intel.drm.width,
-							  dst->intel.drm.height,
-							  op, source,
-							  path, stroke_style, ctm,
-							  clip);
-    if (unlikely (status))
-	return status;
-
-    if (_cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	have_clip = TRUE;
-    }
-
-    status = _cairo_clip_to_boxes (&clip, &extents, &clip_boxes, &num_boxes);
-    if (unlikely (status)) {
-	if (have_clip)
-	    _cairo_clip_fini (&local_clip);
-
-	return status;
-    }
-
-    if (_cairo_path_fixed_stroke_is_rectilinear (path)) {
-	cairo_boxes_t boxes;
-
-	_cairo_boxes_init (&boxes);
-	_cairo_boxes_limit (&boxes, clip_boxes, num_boxes);
-	status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path,
-								stroke_style,
-								ctm,
-								&boxes);
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = _clip_and_composite_boxes (dst, op, source,
-						&boxes, antialias,
-						&extents, clip, 1.);
-	}
-
-	_cairo_boxes_fini (&boxes);
-
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    goto CLEANUP_BOXES;
-    }
-
-    _cairo_polygon_init (&info.polygon, clip_boxes, num_boxes);
-
-    status = _cairo_path_fixed_stroke_to_polygon (path,
-						  stroke_style,
-						  ctm, ctm_inverse,
-						  tolerance,
-						  &info.polygon);
-    if (unlikely (status))
-	goto CLEANUP_POLYGON;
-
-    if (extents.is_bounded) {
-	cairo_rectangle_int_t rect;
-
-	_cairo_box_round_to_rectangle (&info.polygon.extents, &rect);
-	if (! _cairo_rectangle_intersect (&extents.bounded, &rect))
-	    goto CLEANUP_POLYGON;
-    }
-
-    if (info.polygon.num_edges == 0) {
-	if (! extents.is_bounded)
-	    status = i915_fixup_unbounded (dst, &extents, clip);
-
-	goto CLEANUP_POLYGON;
-    }
-
-    info.fill_rule = CAIRO_FILL_RULE_WINDING;
-    info.antialias = antialias;
-    status = i915_clip_and_composite_spans (dst, op, source, antialias,
-					    _composite_polygon_spans, &info,
-					    &extents, clip, 1.);
-
-CLEANUP_POLYGON:
-    _cairo_polygon_fini (&info.polygon);
-
-CLEANUP_BOXES:
-    if (clip_boxes != boxes_stack)
-	free (clip_boxes);
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static cairo_int_status_t
-i915_surface_fill (void			*abstract_dst,
-		   cairo_operator_t	 op,
-		   const cairo_pattern_t*source,
-		   cairo_path_fixed_t	*path,
-		   cairo_fill_rule_t	 fill_rule,
-		   double		 tolerance,
-		   cairo_antialias_t	 antialias,
-		   cairo_clip_t		*clip)
-{
-    return i915_surface_fill_with_alpha (abstract_dst, op, source, path, fill_rule, tolerance, antialias, clip, 1.);
-}
-
-static const cairo_surface_backend_t i915_surface_backend = {
-    CAIRO_SURFACE_TYPE_DRM,
-    _cairo_default_context_create,
-
-    i915_surface_create_similar,
-    i915_surface_finish,
-
-    NULL,
-    intel_surface_acquire_source_image,
-    intel_surface_release_source_image,
-
-    NULL, NULL, NULL,
-    NULL, /* composite */
-    NULL, /* fill */
-    NULL, /* trapezoids */
-    NULL, /* span */
-    NULL, /* check-span */
-
-    NULL, /* copy_page */
-    NULL, /* show_page */
-    _cairo_drm_surface_get_extents,
-    NULL, /* old-glyphs */
-    _cairo_drm_surface_get_font_options,
-
-    i915_surface_flush,
-    NULL, /* mark_dirty */
-    intel_scaled_font_fini,
-    intel_scaled_glyph_fini,
-
-    i915_surface_paint,
-    i915_surface_mask,
-    i915_surface_stroke,
-    i915_surface_fill,
-    i915_surface_glyphs,
-};
-
-static void
-i915_surface_init (i915_surface_t *surface,
-		   cairo_drm_device_t *device,
-		   cairo_format_t format,
-		   int width, int height)
-{
-    intel_surface_init (&surface->intel, &i915_surface_backend, device,
-			format, width, height);
-
-    switch (format) {
-    default:
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-	ASSERT_NOT_REACHED;
-    case CAIRO_FORMAT_ARGB32:
-	surface->map0 = MAPSURF_32BIT | MT_32BIT_ARGB8888;
-	surface->colorbuf = COLR_BUF_ARGB8888 | DEPTH_FRMT_24_FIXED_8_OTHER;
-	break;
-    case CAIRO_FORMAT_RGB24:
-	surface->map0 = MAPSURF_32BIT | MT_32BIT_XRGB8888;
-	surface->colorbuf = COLR_BUF_ARGB8888 | DEPTH_FRMT_24_FIXED_8_OTHER;
-	break;
-    case CAIRO_FORMAT_RGB16_565:
-	surface->map0 = MAPSURF_16BIT | MT_16BIT_RGB565;
-	surface->colorbuf = COLR_BUF_RGB565;
-	break;
-    case CAIRO_FORMAT_A8:
-	surface->map0 = MAPSURF_8BIT | MT_8BIT_A8;
-	surface->colorbuf = COLR_BUF_8BIT | DEPTH_FRMT_24_FIXED_8_OTHER;
-	break;
-    }
-    surface->colorbuf |= DSTORG_HORT_BIAS (0x8) | DSTORG_VERT_BIAS (0x8);
-    surface->map0 |= ((height - 1) << MS3_HEIGHT_SHIFT) |
-		     ((width  - 1) << MS3_WIDTH_SHIFT);
-    surface->map1 = 0;
-
-    surface->is_current_texture = 0;
-    surface->deferred_clear = FALSE;
-
-    surface->offset = 0;
-
-    surface->stencil  = NULL;
-    surface->cache = NULL;
-}
-
-cairo_surface_t *
-i915_surface_create_internal (cairo_drm_device_t *base_dev,
-		              cairo_format_t format,
-			      int width, int height,
-			      uint32_t tiling,
-			      cairo_bool_t gpu_target)
-{
-    i915_surface_t *surface;
-    cairo_status_t status_ignored;
-
-    surface = _cairo_malloc (sizeof (i915_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    i915_surface_init (surface, base_dev, format, width, height);
-
-    if (width && height) {
-	uint32_t size, stride;
-	intel_bo_t *bo;
-
-	width = (width + 3) & -4;
-	stride = cairo_format_stride_for_width (surface->intel.drm.format, width);
-	/* check for tiny surfaces for which tiling is irrelevant */
-	if (height * stride <= 4096)
-	    tiling = I915_TILING_NONE;
-	if (tiling != I915_TILING_NONE && stride <= 512)
-	    tiling = I915_TILING_NONE;
-	if (tiling != I915_TILING_NONE) {
-	    if (height <= 8)
-		tiling = I915_TILING_NONE;
-	    else if (height <= 16)
-		tiling = I915_TILING_X;
-	}
-	/* large surfaces we need to blt, so force TILING_X */
-	if (height > 2048)
-	    tiling = I915_TILING_X;
-	/* but there is a maximum limit to the tiling pitch */
-	if (tiling != I915_TILING_NONE && stride > 8192)
-	    tiling = I915_TILING_NONE;
-
-	stride = i915_tiling_stride (tiling, stride);
-	assert (stride >= (uint32_t) cairo_format_stride_for_width (surface->intel.drm.format, width));
-	assert (tiling == I915_TILING_NONE || stride <= 8192);
-	height = i915_tiling_height (tiling, height);
-	if (height > 64*1024) {
-	    free (surface);
-	    cairo_device_destroy (&base_dev->base);
-	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
-	}
-
-	size = stride * height;
-	bo = intel_bo_create (to_intel_device (&base_dev->base),
-			      i915_tiling_size (tiling, size), size,
-			      gpu_target, tiling, stride);
-	if (bo == NULL) {
-	    status_ignored = _cairo_drm_surface_finish (&surface->intel.drm);
-	    free (surface);
-	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-	}
-	assert (bo->base.size >= size);
-
-	surface->intel.drm.bo = &bo->base;
-	surface->intel.drm.stride = stride;
-
-	surface->map0 |= MS3_tiling (tiling);
-	surface->map1 = (stride/4 - 1) << MS4_PITCH_SHIFT;
-    }
-
-    return &surface->intel.drm.base;
-}
-
-static cairo_surface_t *
-i915_surface_create (cairo_drm_device_t *base_dev,
-		     cairo_format_t format,
-		     int width, int height)
-{
-    switch (format) {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB16_565:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_A8:
-	break;
-    case CAIRO_FORMAT_INVALID:
-    default:
-    case CAIRO_FORMAT_A1:
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-    }
-
-    return i915_surface_create_internal (base_dev, format, width, height,
-	                                 I915_TILING_DEFAULT, TRUE);
-}
-
-static cairo_surface_t *
-i915_surface_create_for_name (cairo_drm_device_t *base_dev,
-			      unsigned int name,
-			      cairo_format_t format,
-			      int width, int height, int stride)
-{
-    i915_surface_t *surface;
-
-    /* Vol I, p134: size restrictions for textures */
-    /* Vol I, p129: destination surface stride must be a multiple of 32 bytes */
-    if (stride < cairo_format_stride_for_width (format, (width + 3) & -4) ||
-	stride & 31)
-    {
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
-    }
-
-    switch (format) {
-    default:
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB16_565:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_A8:
-	break;
-    }
-
-    surface = _cairo_malloc (sizeof (i915_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    i915_surface_init (surface, base_dev, format, width, height);
-
-    if (width && height) {
-	surface->intel.drm.stride = stride;
-	surface->map1 = (surface->intel.drm.stride/4 - 1) << MS4_PITCH_SHIFT;
-
-	surface->intel.drm.bo =
-	    &intel_bo_create_for_name (to_intel_device (&base_dev->base),
-				       name)->base;
-	if (unlikely (surface->intel.drm.bo == NULL)) {
-	    free (surface);
-	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-	}
-	to_intel_bo (surface->intel.drm.bo)->stride = stride;
-
-	surface->map0 |= MS3_tiling (to_intel_bo (surface->intel.drm.bo)->tiling);
-    }
-
-    return &surface->intel.drm.base;
-}
-
-static cairo_status_t
-i915_buffer_cache_init (intel_buffer_cache_t *cache,
-		        i915_device_t *device,
-			cairo_format_t format,
-			int width, int height)
-{
-    const uint32_t tiling = I915_TILING_DEFAULT;
-    uint32_t stride, size;
-
-    assert ((width & 3) == 0);
-    assert ((height & 1) == 0);
-    cache->buffer.width = width;
-    cache->buffer.height = height;
-
-    switch (format) {
-    case CAIRO_FORMAT_INVALID:
-    case CAIRO_FORMAT_A1:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_RGB16_565:
-	ASSERT_NOT_REACHED;
-    case CAIRO_FORMAT_ARGB32:
-	cache->buffer.map0 = MAPSURF_32BIT | MT_32BIT_ARGB8888;
-	stride = width * 4;
-	break;
-    case CAIRO_FORMAT_A8:
-	cache->buffer.map0 = MAPSURF_8BIT | MT_8BIT_I8;
-	stride = width;
-	break;
-    }
-    assert ((stride & 7) == 0);
-    assert (i915_tiling_stride (tiling, stride) == stride);
-    assert (i915_tiling_height (tiling, height) == height);
-
-    size = height * stride;
-    assert (i915_tiling_size (tiling, size) == size);
-    cache->buffer.bo = intel_bo_create (&device->intel, size, size, FALSE, tiling, stride);
-    if (unlikely (cache->buffer.bo == NULL))
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-    cache->buffer.stride = cache->buffer.bo->stride;
-
-    cache->buffer.map0 |= ((height - 1) << MS3_HEIGHT_SHIFT) |
-			  ((width  - 1) << MS3_WIDTH_SHIFT);
-    cache->buffer.map0 |= MS3_tiling (tiling);
-    cache->buffer.map1 = ((stride / 4) - 1) << MS4_PITCH_SHIFT;
-
-    cache->ref_count = 0;
-    cairo_list_init (&cache->link);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-i915_surface_t *
-i915_surface_create_from_cacheable_image_internal (i915_device_t *device,
-						   cairo_image_surface_t *image)
-{
-    i915_surface_t *surface;
-    cairo_status_t status;
-    cairo_list_t *caches;
-    intel_buffer_cache_t *cache;
-    cairo_rtree_node_t *node;
-    cairo_format_t format;
-    int width, height, bpp;
-
-    format = image->format;
-    if (format == CAIRO_FORMAT_A1)
-	format = CAIRO_FORMAT_A8;
-
-    width = image->width;
-    height = image->height;
-    if (width > IMAGE_CACHE_WIDTH/2 || height > IMAGE_CACHE_HEIGHT/2) {
-	surface = (i915_surface_t *)
-	    i915_surface_create_internal (&device->intel.base,
-					  format,
-					  width, height,
-					  I915_TILING_NONE, FALSE);
-	if (unlikely (surface->intel.drm.base.status))
-	    return surface;
-
-	status = intel_bo_put_image (&device->intel,
-				     to_intel_bo (surface->intel.drm.bo),
-				     image,
-				     0, 0,
-				     width, height,
-				     0, 0);
-
-	if (unlikely (status)) {
-	    cairo_surface_destroy (&surface->intel.drm.base);
-	    return (i915_surface_t *) _cairo_surface_create_in_error (status);
-	}
-
-	return surface;
-    }
-
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	return (i915_surface_t *) _cairo_surface_create_in_error (status);
-
-    switch (image->format) {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_RGB16_565:
-	caches = &device->image_caches[0];
-	format = CAIRO_FORMAT_ARGB32;
-	bpp = 4;
-	break;
-    case CAIRO_FORMAT_A8:
-    case CAIRO_FORMAT_A1:
-	caches = &device->image_caches[1];
-	format = CAIRO_FORMAT_A8;
-	bpp = 1;
-	break;
-    case CAIRO_FORMAT_INVALID:
-    default:
-	ASSERT_NOT_REACHED;
-	status = _cairo_error (CAIRO_STATUS_INVALID_FORMAT);
-	goto CLEANUP_DEVICE;
-    }
-
-    node = NULL;
-    cairo_list_foreach_entry (cache, intel_buffer_cache_t, caches, link) {
-	if (! intel_bo_is_inactive (&device->intel, cache->buffer.bo))
-	    continue;
-
-	status = _cairo_rtree_insert (&cache->rtree, width, height, &node);
-	if (unlikely (_cairo_status_is_error (status)))
-	    goto CLEANUP_DEVICE;
-	if (status == CAIRO_STATUS_SUCCESS)
-	    break;
-    }
-    if (node == NULL) {
-	cache = _cairo_malloc (sizeof (intel_buffer_cache_t));
-	if (unlikely (cache == NULL)) {
-	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    goto CLEANUP_DEVICE;
-	}
-
-	status = i915_buffer_cache_init (cache, device, format,
-					 IMAGE_CACHE_WIDTH,
-					 IMAGE_CACHE_HEIGHT);
-	if (unlikely (status)) {
-	    free (cache);
-	    goto CLEANUP_DEVICE;
-	}
-
-	_cairo_rtree_init (&cache->rtree,
-			   IMAGE_CACHE_WIDTH,
-			   IMAGE_CACHE_HEIGHT,
-			   4,
-			   sizeof (i915_image_private_t));
-
-	status = _cairo_rtree_insert (&cache->rtree, width, height, &node);
-	assert (status == CAIRO_STATUS_SUCCESS);
-
-	cairo_list_init (&cache->link);
-    }
-    cairo_list_move (&cache->link, caches);
-    ((i915_image_private_t *) node)->container = cache;
-
-    status = intel_bo_put_image (&device->intel,
-				 cache->buffer.bo,
-				 image,
-				 0, 0,
-				 width, height,
-				 node->x, node->y);
-    if (unlikely (status))
-	goto CLEANUP_CACHE;
-
-    surface = _cairo_malloc (sizeof (i915_surface_t));
-    if (unlikely (surface == NULL)) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto CLEANUP_CACHE;
-    }
-
-    i915_surface_init (surface, &device->intel.base,
-		       format, width, height);
-
-    surface->intel.drm.stride = cache->buffer.stride;
-
-    surface->map0 |= MS3_tiling (cache->buffer.bo->tiling);
-    surface->map1 = (surface->intel.drm.stride/4 - 1) << MS4_PITCH_SHIFT;
-
-    surface->intel.drm.bo = &intel_bo_reference (cache->buffer.bo)->base;
-    surface->offset = node->y * cache->buffer.stride + bpp * node->x;
-
-    surface->cache = (i915_image_private_t *) node;
-    cache->ref_count++;
-
-    cairo_device_release (&device->intel.base.base);
-
-    return surface;
-
-CLEANUP_CACHE:
-    _cairo_rtree_node_destroy (&cache->rtree, node);
-    if (cache->ref_count == 0) {
-	intel_bo_destroy (&device->intel, cache->buffer.bo);
-	_cairo_rtree_fini (&cache->rtree);
-	cairo_list_del (&cache->link);
-	free (cache);
-    }
-CLEANUP_DEVICE:
-    cairo_device_release (&device->intel.base.base);
-    return (i915_surface_t *) _cairo_surface_create_in_error (status);
-}
-
-static cairo_surface_t *
-i915_surface_create_from_cacheable_image (cairo_drm_device_t *device,
-					  cairo_surface_t *source)
-{
-    i915_surface_t *surface;
-    cairo_image_surface_t *image;
-    void *image_extra;
-    cairo_status_t status;
-
-    status = _cairo_surface_acquire_source_image (source, &image, &image_extra);
-    if (unlikely (status))
-	return _cairo_surface_create_in_error (status);
-
-    surface = i915_surface_create_from_cacheable_image_internal ((i915_device_t *) device, image);
-
-    _cairo_surface_release_source_image (source, image, image_extra);
-
-    return &surface->intel.drm.base;
-}
-
-static cairo_status_t
-i915_surface_enable_scan_out (void *abstract_surface)
-{
-    i915_surface_t *surface = abstract_surface;
-    intel_bo_t *bo;
-    cairo_status_t status;
-
-    if (unlikely (surface->intel.drm.bo == NULL))
-	return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
-
-    bo = to_intel_bo (surface->intel.drm.bo);
-    if (bo->tiling == I915_TILING_Y) {
-	status = i915_surface_batch_flush (surface);
-	if (unlikely (status))
-	    return status;
-
-	bo->tiling = I915_TILING_X;
-	surface->map0 &= ~MS3_tiling (I915_TILING_Y);
-	surface->map0 |= MS3_tiling (I915_TILING_X);
-    }
-
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_int_status_t
-i915_device_flush (cairo_drm_device_t *device)
-{
-    cairo_status_t status;
-
-    if (unlikely (device->base.finished))
-	return CAIRO_STATUS_SUCCESS;
-
-    status = cairo_device_acquire (&device->base);
-    if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	status = i915_batch_flush ((i915_device_t *) device);
-	cairo_device_release (&device->base);
-    }
-
-    return status;
-}
-
-static cairo_int_status_t
-i915_device_throttle (cairo_drm_device_t *device)
-{
-    cairo_status_t status;
-
-    status = cairo_device_acquire (&device->base);
-    if (unlikely (status))
-	return status;
-
-    status = i915_batch_flush ((i915_device_t *) device);
-    intel_throttle ((intel_device_t *) device);
-
-    cairo_device_release (&device->base);
-
-    return status;
-}
-
-static void
-i915_device_destroy (void *data)
-{
-    i915_device_t *device = data;
-
-    if (device->last_vbo)
-	intel_bo_destroy (&device->intel, device->last_vbo);
-
-    i915_batch_cleanup (device);
-
-    intel_device_fini (&device->intel);
-    free (device);
-}
-
-COMPILE_TIME_ASSERT (sizeof (i915_batch_setup) == sizeof (((i915_device_t *)0)->batch_header));
-COMPILE_TIME_ASSERT (offsetof (i915_device_t, batch_base) == offsetof (i915_device_t, batch_header) + sizeof (i915_batch_setup));
-
-cairo_drm_device_t *
-_cairo_drm_i915_device_create (int fd, dev_t dev_id, int vendor_id, int chip_id)
-{
-    i915_device_t *device;
-    cairo_status_t status;
-    uint64_t gtt_size;
-    int n;
-
-    if (! intel_info (fd, &gtt_size))
-	return NULL;
-
-    device = _cairo_malloc (sizeof (i915_device_t));
-    if (device == NULL)
-	return (cairo_drm_device_t *) _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
-
-    status = intel_device_init (&device->intel, fd);
-    if (unlikely (status)) {
-	free (device);
-	return (cairo_drm_device_t *) _cairo_device_create_in_error (status);
-    }
-
-    device->debug = 0;
-    if (getenv ("CAIRO_DEBUG_DRM") != NULL)
-	device->debug = I915_DEBUG_SYNC;
-
-    n = intel_get (fd, I915_PARAM_NUM_FENCES_AVAIL);
-    if (n == 0)
-	n = 8;
-    device->batch.fences_avail = n - 2; /* conservative */
-
-    device->batch.gtt_avail_size = device->intel.gtt_avail_size / 4;
-    device->batch.est_gtt_size = I915_BATCH_SIZE;
-    device->batch.total_gtt_size = I915_BATCH_SIZE;
-    device->batch.exec_count = 0;
-    device->batch.reloc_count = 0;
-    device->batch.used = 0;
-    device->batch.fences = 0;
-
-    memcpy (device->batch_header, i915_batch_setup, sizeof (i915_batch_setup));
-    device->vbo = 0;
-    device->vbo_offset = 0;
-    device->vbo_used = 0;
-    device->vertex_index = 0;
-    device->vertex_count = 0;
-    device->last_vbo = NULL;
-
-    for (n = 0; n < ARRAY_LENGTH (device->image_caches); n++)
-	cairo_list_init (&device->image_caches[n]);
-
-    device->intel.base.surface.create = i915_surface_create;
-    device->intel.base.surface.create_for_name = i915_surface_create_for_name;
-    device->intel.base.surface.create_from_cacheable_image = i915_surface_create_from_cacheable_image;
-
-    device->intel.base.surface.flink = _cairo_drm_surface_flink;
-    device->intel.base.surface.enable_scan_out = i915_surface_enable_scan_out;
-    device->intel.base.surface.map_to_image = intel_surface_map_to_image;
-
-    device->intel.base.device.flush = i915_device_flush;
-    device->intel.base.device.throttle = i915_device_throttle;
-    device->intel.base.device.destroy = i915_device_destroy;
-
-    device->floats_per_vertex = 0;
-    device->current_source = NULL;
-    device->current_mask = NULL;
-    device->current_clip = NULL;
-
-    i915_device_reset (device);
-
-    return _cairo_drm_device_init (&device->intel.base,
-				   fd, dev_id, vendor_id, chip_id,
-				   16*1024);
-}
diff --git a/src/drm/cairo-drm-i965-glyphs.c b/src/drm/cairo-drm-i965-glyphs.c
deleted file mode 100644
index 22ace66e3..000000000
--- a/src/drm/cairo-drm-i965-glyphs.c
+++ /dev/null
@@ -1,506 +0,0 @@
-/* -*- Mode: c; tab-width: 8; c-basic-offset: 4; indent-tabs-mode: t; -*- */
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Red Hat, Inc.
- *
- * Contributor(s):
- *	Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-drm-i965-private.h"
-#include "cairo-error-private.h"
-#include "cairo-rtree-private.h"
-
-typedef struct _i965_glyphs i965_glyphs_t;
-
-typedef float *
-(*i965_get_rectangle_func_t) (i965_glyphs_t *glyphs);
-
-struct _i965_glyphs {
-    i965_get_rectangle_func_t get_rectangle;
-    i965_shader_t shader;
-
-    struct i965_vbo head, *tail;
-
-    unsigned int vbo_offset;
-    float *vbo_base;
-};
-
-static float *
-i965_glyphs_emit_rectangle (i965_glyphs_t *glyphs)
-{
-    return i965_add_rectangle (glyphs->shader.device);
-}
-
-static float *
-i965_glyphs_accumulate_rectangle (i965_glyphs_t *glyphs)
-{
-    float *vertices;
-    uint32_t size;
-
-    size = glyphs->shader.device->rectangle_size;
-    if (unlikely (glyphs->vbo_offset + size > I965_VERTEX_SIZE)) {
-	struct i965_vbo *vbo;
-
-	vbo = _cairo_malloc (sizeof (struct i965_vbo));
-	if (unlikely (vbo == NULL)) {
-	    /* throw error! */
-	}
-
-	glyphs->tail->next = vbo;
-	glyphs->tail = vbo;
-
-	vbo->next = NULL;
-	vbo->bo = intel_bo_create (&glyphs->shader.device->intel,
-				   I965_VERTEX_SIZE, I965_VERTEX_SIZE,
-				   FALSE, I915_TILING_NONE, 0);
-	vbo->count = 0;
-
-	glyphs->vbo_offset = 0;
-	glyphs->vbo_base = intel_bo_map (&glyphs->shader.device->intel, vbo->bo);
-    }
-
-    vertices = glyphs->vbo_base + glyphs->vbo_offset;
-    glyphs->vbo_offset += size;
-    glyphs->tail->count += 3;
-
-    return vertices;
-}
-
-static void
-i965_add_glyph_rectangle (i965_glyphs_t *glyphs,
-			  int x1, int y1,
-			  int x2, int y2,
-			  intel_glyph_t *glyph)
-{
-    float *v;
-
-    /* Each vertex is:
-     *   2 vertex coordinates
-     *   1 glyph texture coordinate
-     */
-
-    v = glyphs->get_rectangle (glyphs);
-
-    /* bottom right */
-    *v++ = x2; *v++ = y2;
-    *v++ = glyph->texcoord[0];
-
-    /* bottom left */
-    *v++ = x1; *v++ = y2;
-    *v++ = glyph->texcoord[1];
-
-    /* top left */
-    *v++ = x1; *v++ = y1;
-    *v++ = glyph->texcoord[2];
-}
-
-static cairo_status_t
-i965_surface_mask_internal (i965_surface_t *dst,
-			    cairo_operator_t		 op,
-			    const cairo_pattern_t	*source,
-			    i965_surface_t *mask,
-			    cairo_clip_t		*clip,
-			    const cairo_composite_rectangles_t *extents)
-{
-    i965_device_t *device;
-    i965_shader_t shader;
-    cairo_region_t *clip_region = NULL;
-    cairo_status_t status;
-
-    i965_shader_init (&shader, dst, op);
-
-    status = i965_shader_acquire_pattern (&shader, &shader.source,
-					  source, &extents->bounded);
-    if (unlikely (status))
-	return status;
-
-    shader.mask.type.vertex = VS_NONE;
-    shader.mask.type.fragment = FS_SURFACE;
-    shader.mask.base.content = mask->intel.drm.base.content;
-    shader.mask.base.filter = i965_filter (CAIRO_FILTER_NEAREST);
-    shader.mask.base.extend = i965_extend (CAIRO_EXTEND_NONE);
-
-    cairo_matrix_init_translate (&shader.mask.base.matrix,
-				 -extents->bounded.x,
-				 -extents->bounded.y);
-    cairo_matrix_scale (&shader.mask.base.matrix,
-			1. / mask->intel.drm.width,
-			1. / mask->intel.drm.height);
-
-    shader.mask.base.bo = to_intel_bo (mask->intel.drm.bo);
-    shader.mask.base.format = mask->intel.drm.format;
-    shader.mask.base.width = mask->intel.drm.width;
-    shader.mask.base.height = mask->intel.drm.height;
-    shader.mask.base.stride = mask->intel.drm.stride;
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-
-	if (clip_region != NULL && cairo_region_num_rectangles (clip_region) == 1)
-	    clip_region = NULL;
-
-	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	    i965_shader_set_clip (&shader, clip);
-    }
-
-    status = cairo_device_acquire (dst->intel.drm.base.device);
-    if (unlikely (status))
-	goto CLEANUP_SHADER;
-
-    device = i965_device (dst);
-
-    status = i965_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto CLEANUP_DEVICE;
-
-    if (clip_region != NULL) {
-	unsigned int n, num_rectangles;
-
-	num_rectangles = cairo_region_num_rectangles (clip_region);
-	for (n = 0; n < num_rectangles; n++) {
-	    cairo_rectangle_int_t rect;
-
-	    cairo_region_get_rectangle (clip_region, n, &rect);
-
-	    i965_shader_add_rectangle (&shader,
-				       rect.x, rect.y,
-				       rect.width, rect.height);
-	}
-    } else {
-	i965_shader_add_rectangle (&shader,
-				   extents->bounded.x,
-				   extents->bounded.y,
-				   extents->bounded.width,
-				   extents->bounded.height);
-    }
-
-    if (! extents->is_bounded)
-	status = i965_fixup_unbounded (dst, extents, clip);
-
-  CLEANUP_DEVICE:
-    cairo_device_release (&device->intel.base.base);
-  CLEANUP_SHADER:
-    i965_shader_fini (&shader);
-    return status;
-}
-
-cairo_int_status_t
-i965_surface_glyphs (void			*abstract_surface,
-		     cairo_operator_t		 op,
-		     const cairo_pattern_t	*source,
-		     cairo_glyph_t		*g,
-		     int			 num_glyphs,
-		     cairo_scaled_font_t	*scaled_font,
-		     cairo_clip_t		*clip,
-		     int *num_remaining)
-{
-    i965_surface_t *surface = abstract_surface;
-    i965_surface_t *mask = NULL;
-    i965_device_t *device;
-    i965_glyphs_t glyphs;
-    cairo_composite_rectangles_t extents;
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    cairo_bool_t overlap;
-    cairo_region_t *clip_region = NULL;
-    intel_bo_t *last_bo = NULL;
-    cairo_scaled_glyph_t *glyph_cache[64];
-    cairo_status_t status;
-    int mask_x = 0, mask_y = 0;
-    int i = 0;
-
-    *num_remaining = 0;
-    status = _cairo_composite_rectangles_init_for_glyphs (&extents,
-							  surface->intel.drm.width,
-							  surface->intel.drm.height,
-							  op, source,
-							  scaled_font,
-							  g, num_glyphs,
-							  clip,
-							  &overlap);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL && _cairo_clip_contains_rectangle (clip, &extents.mask))
-	clip = NULL;
-
-    if (clip != NULL && extents.is_bounded) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	status = _cairo_clip_rectangle (clip, &extents.bounded);
-	if (unlikely (status))
-	    return status;
-
-	have_clip = TRUE;
-    }
-
-    if (overlap || ! extents.is_bounded) {
-	cairo_format_t format;
-
-	format = CAIRO_FORMAT_A8;
-	if (scaled_font->options.antialias == CAIRO_ANTIALIAS_SUBPIXEL)
-	    format = CAIRO_FORMAT_ARGB32;
-
-	mask = (i965_surface_t *)
-	    i965_surface_create_internal (&i965_device (surface)->intel.base,
-					  format,
-					  extents.bounded.width,
-					  extents.bounded.height,
-					  I965_TILING_DEFAULT,
-					  TRUE);
-	if (unlikely (mask->intel.drm.base.status))
-	    return mask->intel.drm.base.status;
-
-	status = _cairo_surface_paint (&mask->intel.drm.base,
-				       CAIRO_OPERATOR_CLEAR,
-				       &_cairo_pattern_clear.base,
-				       NULL);
-	if (unlikely (status)) {
-	    cairo_surface_destroy (&mask->intel.drm.base);
-	    return status;
-	}
-
-	i965_shader_init (&glyphs.shader, mask, CAIRO_OPERATOR_ADD);
-
-	status = i965_shader_acquire_pattern (&glyphs.shader, &glyphs.shader.source,
-					      &_cairo_pattern_white.base,
-					      &extents.bounded);
-	if (unlikely (status)) {
-	    cairo_surface_destroy (&mask->intel.drm.base);
-	    return status;
-	}
-
-	mask_x = -extents.bounded.x;
-	mask_y = -extents.bounded.y;
-    } else {
-	i965_shader_init (&glyphs.shader, surface, op);
-
-	status = i965_shader_acquire_pattern (&glyphs.shader, &glyphs.shader.source,
-					      source, &extents.bounded);
-	if (unlikely (status))
-	    return status;
-
-	if (clip != NULL) {
-	    status = _cairo_clip_get_region (clip, &clip_region);
-	    assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-
-	    if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-		i965_shader_set_clip (&glyphs.shader, clip);
-	}
-    }
-
-    glyphs.head.next = NULL;
-    glyphs.head.bo = NULL;
-    glyphs.head.count = 0;
-    glyphs.tail = &glyphs.head;
-
-    device = i965_device (surface);
-    if (mask != NULL || clip_region == NULL) {
-	glyphs.get_rectangle = i965_glyphs_emit_rectangle;
-    } else {
-	glyphs.get_rectangle = i965_glyphs_accumulate_rectangle;
-	glyphs.head.bo = intel_bo_create (&device->intel,
-					  I965_VERTEX_SIZE, I965_VERTEX_SIZE,
-					  FALSE, I915_TILING_NONE, 0);
-	if (unlikely (glyphs.head.bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	glyphs.vbo_base = intel_bo_map (&device->intel, glyphs.head.bo);
-    }
-    glyphs.vbo_offset = 0;
-
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto CLEANUP_GLYPHS;
-
-    _cairo_scaled_font_freeze_cache (scaled_font);
-    //private = _cairo_scaled_font_get_device (scaled_font, device);
-    if (scaled_font->surface_private == NULL) {
-	scaled_font->surface_private = device;
-	scaled_font->surface_backend = surface->intel.drm.base.backend;
-	cairo_list_add (&scaled_font->link, &device->intel.fonts);
-    }
-
-    memset (glyph_cache, 0, sizeof (glyph_cache));
-
-    for (i = 0; i < num_glyphs; i++) {
-	cairo_scaled_glyph_t *scaled_glyph;
-	int x, y, x1, x2, y1, y2;
-	int cache_index = g[i].index % ARRAY_LENGTH (glyph_cache);
-	intel_glyph_t *glyph;
-
-	scaled_glyph = glyph_cache[cache_index];
-	if (scaled_glyph == NULL ||
-	    _cairo_scaled_glyph_index (scaled_glyph) != g[i].index)
-	{
-	    status = _cairo_scaled_glyph_lookup (scaled_font,
-						 g[i].index,
-						 CAIRO_SCALED_GLYPH_INFO_METRICS,
-						 NULL, /* foreground color */
-						 &scaled_glyph);
-	    if (unlikely (status))
-		goto FINISH;
-
-	    glyph_cache[cache_index] = scaled_glyph;
-	}
-
-	if (unlikely (scaled_glyph->metrics.width  == 0 ||
-		      scaled_glyph->metrics.height == 0))
-	{
-	    continue;
-	}
-
-	/* XXX glyph images are snapped to pixel locations */
-	x = _cairo_lround (g[i].x);
-	y = _cairo_lround (g[i].y);
-
-	x1 = x + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.x);
-	y1 = y + _cairo_fixed_integer_floor (scaled_glyph->bbox.p1.y);
-	x2 = x + _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.x);
-	y2 = y + _cairo_fixed_integer_ceil (scaled_glyph->bbox.p2.y);
-
-	if (x2 < extents.bounded.x ||
-	    y2 < extents.bounded.y ||
-	    x1 > extents.bounded.x + extents.bounded.width ||
-	    y1 > extents.bounded.y + extents.bounded.height)
-	{
-	    continue;
-	}
-
-	if (scaled_glyph->surface_private == NULL) {
-	    status = intel_get_glyph (&device->intel, scaled_font, scaled_glyph);
-	    if (unlikely (status == CAIRO_INT_STATUS_NOTHING_TO_DO)) {
-		status = CAIRO_STATUS_SUCCESS;
-		continue;
-	    }
-	    if (unlikely (status))
-		goto FINISH;
-	}
-	glyph = intel_glyph_pin (scaled_glyph->surface_private);
-
-	if (glyph->cache->buffer.bo != last_bo) {
-	    intel_buffer_cache_t *cache = glyph->cache;
-
-	    glyphs.shader.mask.type.vertex   = VS_GLYPHS;
-	    glyphs.shader.mask.type.fragment = FS_GLYPHS;
-	    glyphs.shader.mask.type.pattern  = PATTERN_BASE;
-
-	    glyphs.shader.mask.base.bo = cache->buffer.bo;
-	    glyphs.shader.mask.base.format = cache->buffer.format;
-	    glyphs.shader.mask.base.width  = cache->buffer.width;
-	    glyphs.shader.mask.base.height = cache->buffer.height;
-	    glyphs.shader.mask.base.stride = cache->buffer.stride;
-	    glyphs.shader.mask.base.filter = i965_filter (CAIRO_FILTER_NEAREST);
-	    glyphs.shader.mask.base.extend = i965_extend (CAIRO_EXTEND_NONE);
-	    glyphs.shader.mask.base.content = CAIRO_CONTENT_ALPHA; /* XXX */
-
-	    glyphs.shader.committed = FALSE;
-	    status = i965_shader_commit (&glyphs.shader, device);
-	    if (unlikely (status))
-		goto FINISH;
-
-	    last_bo = cache->buffer.bo;
-	}
-
-	x2 = x1 + glyph->width;
-	y2 = y1 + glyph->height;
-
-	if (mask_x)
-	    x1 += mask_x, x2 += mask_x;
-	if (mask_y)
-	    y1 += mask_y, y2 += mask_y;
-
-	i965_add_glyph_rectangle (&glyphs, x1, y1, x2, y2, glyph);
-    }
-
-    if (mask != NULL && clip_region != NULL)
-	i965_clipped_vertices (device, &glyphs.head, clip_region);
-
-    status = CAIRO_STATUS_SUCCESS;
-  FINISH:
-    _cairo_scaled_font_thaw_cache (scaled_font);
-    cairo_device_release (surface->intel.drm.base.device);
-  CLEANUP_GLYPHS:
-    i965_shader_fini (&glyphs.shader);
-
-    if (glyphs.head.bo != NULL) {
-	struct i965_vbo *vbo, *next;
-
-	intel_bo_destroy (&device->intel, glyphs.head.bo);
-	for (vbo = glyphs.head.next; vbo != NULL; vbo = next) {
-	    next = vbo->next;
-	    intel_bo_destroy (&device->intel, vbo->bo);
-	    free (vbo);
-	}
-    }
-
-    if (unlikely (status == CAIRO_INT_STATUS_UNSUPPORTED)) {
-	cairo_path_fixed_t path;
-
-	_cairo_path_fixed_init (&path);
-	status = _cairo_scaled_font_glyph_path (scaled_font,
-						g + i, num_glyphs - i,
-						&path);
-	if (mask_x | mask_y) {
-	    _cairo_path_fixed_translate (&path,
-					 _cairo_fixed_from_int (mask_x),
-					 _cairo_fixed_from_int (mask_y));
-	}
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = surface->intel.drm.base.backend->fill (glyphs.shader.target,
-							    glyphs.shader.op,
-							    mask != NULL ? &_cairo_pattern_white.base : source,
-							    &path,
-							    CAIRO_FILL_RULE_WINDING,
-							    0,
-							    scaled_font->options.antialias,
-							    clip);
-	}
-	_cairo_path_fixed_fini (&path);
-    }
-
-    if (mask != NULL) {
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = i965_surface_mask_internal (surface, op, source, mask,
-					         clip, &extents);
-	}
-	cairo_surface_finish (&mask->intel.drm.base);
-	cairo_surface_destroy (&mask->intel.drm.base);
-    }
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
diff --git a/src/drm/cairo-drm-i965-private.h b/src/drm/cairo-drm-i965-private.h
deleted file mode 100644
index 79568a63d..000000000
--- a/src/drm/cairo-drm-i965-private.h
+++ /dev/null
@@ -1,737 +0,0 @@
-#ifndef CAIRO_DRM_I965_PRIVATE_H
-#define CAIRO_DRM_I965_PRIVATE_H
-
-#include "cairo-drm-intel-private.h"
-
-#include "cairo-hash-private.h"
-#include "cairo-freelist-private.h"
-
-#include "cairo-drm-intel-brw-defines.h"
-
-#include <setjmp.h>
-
-#define BRW_MI_GLOBAL_SNAPSHOT_RESET   (1 << 3)
-
-/*
- * New regs for broadwater -- we need to split this file up sensibly somehow.
- */
-#define BRW_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
-					   ((Pipeline) << 27) | \
-					   ((Opcode) << 24) | \
-					   ((Subopcode) << 16))
-
-#define BRW_URB_FENCE				BRW_3D(0, 0, 0)
-#define BRW_CS_URB_STATE			BRW_3D(0, 0, 1)
-#define BRW_CONSTANT_BUFFER			BRW_3D(0, 0, 2)
-#define BRW_STATE_PREFETCH			BRW_3D(0, 0, 3)
-
-#define BRW_STATE_BASE_ADDRESS			BRW_3D(0, 1, 1)
-#define BRW_STATE_SIP				BRW_3D(0, 1, 2)
-#define BRW_PIPELINE_SELECT			BRW_3D(0, 1, 4)
-
-#define NEW_PIPELINE_SELECT			BRW_3D(1, 1, 4)
-
-#define BRW_MEDIA_STATE_POINTERS		BRW_3D(2, 0, 0)
-#define BRW_MEDIA_OBJECT			BRW_3D(2, 1, 0)
-
-#define BRW_3DSTATE_PIPELINED_POINTERS		BRW_3D(3, 0, 0)
-#define BRW_3DSTATE_BINDING_TABLE_POINTERS	BRW_3D(3, 0, 1)
-#define BRW_3DSTATE_VERTEX_BUFFERS		BRW_3D(3, 0, 8)
-#define BRW_3DSTATE_VERTEX_ELEMENTS		BRW_3D(3, 0, 9)
-#define BRW_3DSTATE_INDEX_BUFFER		BRW_3D(3, 0, 0xa)
-#define BRW_3DSTATE_VF_STATISTICS		BRW_3D(3, 0, 0xb)
-
-#define BRW_3DSTATE_DRAWING_RECTANGLE		BRW_3D(3, 1, 0)
-#define BRW_3DSTATE_CONSTANT_COLOR		BRW_3D(3, 1, 1)
-#define BRW_3DSTATE_SAMPLER_PALETTE_LOAD	BRW_3D(3, 1, 2)
-#define BRW_3DSTATE_CHROMA_KEY			BRW_3D(3, 1, 4)
-#define BRW_3DSTATE_DEPTH_BUFFER		BRW_3D(3, 1, 5)
-#define BRW_3DSTATE_POLY_STIPPLE_OFFSET		BRW_3D(3, 1, 6)
-#define BRW_3DSTATE_POLY_STIPPLE_PATTERN	BRW_3D(3, 1, 7)
-#define BRW_3DSTATE_LINE_STIPPLE		BRW_3D(3, 1, 8)
-#define BRW_3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP	BRW_3D(3, 1, 9)
-/* These two are BLC and CTG only, not BW or CL */
-#define BRW_3DSTATE_AA_LINE_PARAMS		BRW_3D(3, 1, 0xa)
-#define BRW_3DSTATE_GS_SVB_INDEX		BRW_3D(3, 1, 0xb)
-
-#define BRW_PIPE_CONTROL			BRW_3D(3, 2, 0)
-
-#define BRW_3DPRIMITIVE				BRW_3D(3, 3, 0)
-
-#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 BRW_STATE_BASE_ADDRESS */
-#define BASE_ADDRESS_MODIFY		(1 << 0)
-
-/* for BRW_3DSTATE_PIPELINED_POINTERS */
-#define BRW_GS_DISABLE		       0
-#define BRW_GS_ENABLE		       1
-#define BRW_CLIP_DISABLE	       0
-#define BRW_CLIP_ENABLE		       1
-
-/* for BRW_PIPE_CONTROL */
-#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_WRITE_TIME    (3 << 14)
-#define BRW_PIPE_CONTROL_DEPTH_STALL   (1 << 13)
-#define BRW_PIPE_CONTROL_WC_FLUSH      (1 << 12)
-#define BRW_PIPE_CONTROL_IS_FLUSH      (1 << 11)
-#define BRW_PIPE_CONTROL_NOTIFY_ENABLE (1 << 8)
-#define BRW_PIPE_CONTROL_GLOBAL_GTT    (1 << 2)
-#define BRW_PIPE_CONTROL_LOCAL_PGTT    (0 << 2)
-
-/* 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 BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL (0 << 15)
-#define BRW_3DPRIMITIVE_VERTEX_RANDOM	  (1 << 15)
-/* Primitive types are in brw_defines.h */
-#define BRW_3DPRIMITIVE_TOPOLOGY_SHIFT	  10
-
-#define BRW_SVG_CTL		       0x7400
-
-#define BRW_SVG_CTL_GS_BA	       (0 << 8)
-#define BRW_SVG_CTL_SS_BA	       (1 << 8)
-#define BRW_SVG_CTL_IO_BA	       (2 << 8)
-#define BRW_SVG_CTL_GS_AUB	       (3 << 8)
-#define BRW_SVG_CTL_IO_AUB	       (4 << 8)
-#define BRW_SVG_CTL_SIP		       (5 << 8)
-
-#define BRW_SVG_RDATA		       0x7404
-#define BRW_SVG_WORK_CTL	       0x7408
-
-#define BRW_VF_CTL		       0x7500
-
-#define BRW_VF_CTL_SNAPSHOT_COMPLETE		   (1 << 31)
-#define BRW_VF_CTL_SNAPSHOT_MUX_SELECT_THREADID	   (0 << 8)
-#define BRW_VF_CTL_SNAPSHOT_MUX_SELECT_VF_DEBUG	   (1 << 8)
-#define BRW_VF_CTL_SNAPSHOT_TYPE_VERTEX_SEQUENCE   (0 << 4)
-#define BRW_VF_CTL_SNAPSHOT_TYPE_VERTEX_INDEX	   (1 << 4)
-#define BRW_VF_CTL_SKIP_INITIAL_PRIMITIVES	   (1 << 3)
-#define BRW_VF_CTL_MAX_PRIMITIVES_LIMIT_ENABLE	   (1 << 2)
-#define BRW_VF_CTL_VERTEX_RANGE_LIMIT_ENABLE	   (1 << 1)
-#define BRW_VF_CTL_SNAPSHOT_ENABLE	     	   (1 << 0)
-
-#define BRW_VF_STRG_VAL		       0x7504
-#define BRW_VF_STR_VL_OVR	       0x7508
-#define BRW_VF_VC_OVR		       0x750c
-#define BRW_VF_STR_PSKIP	       0x7510
-#define BRW_VF_MAX_PRIM		       0x7514
-#define BRW_VF_RDATA		       0x7518
-
-#define BRW_VS_CTL		       0x7600
-#define BRW_VS_CTL_SNAPSHOT_COMPLETE		   (1 << 31)
-#define BRW_VS_CTL_SNAPSHOT_MUX_VERTEX_0	   (0 << 8)
-#define BRW_VS_CTL_SNAPSHOT_MUX_VERTEX_1	   (1 << 8)
-#define BRW_VS_CTL_SNAPSHOT_MUX_VALID_COUNT	   (2 << 8)
-#define BRW_VS_CTL_SNAPSHOT_MUX_VS_KERNEL_POINTER  (3 << 8)
-#define BRW_VS_CTL_SNAPSHOT_ALL_THREADS		   (1 << 2)
-#define BRW_VS_CTL_THREAD_SNAPSHOT_ENABLE	   (1 << 1)
-#define BRW_VS_CTL_SNAPSHOT_ENABLE		   (1 << 0)
-
-#define BRW_VS_STRG_VAL		       0x7604
-#define BRW_VS_RDATA		       0x7608
-
-#define BRW_SF_CTL		       0x7b00
-#define BRW_SF_CTL_SNAPSHOT_COMPLETE		   (1 << 31)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_0_FF_ID	   (0 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_0_REL_COUNT (1 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_1_FF_ID	   (2 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_1_REL_COUNT (3 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_2_FF_ID	   (4 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_2_REL_COUNT (5 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_VERTEX_COUNT	   (6 << 8)
-#define BRW_SF_CTL_SNAPSHOT_MUX_SF_KERNEL_POINTER  (7 << 8)
-#define BRW_SF_CTL_MIN_MAX_PRIMITIVE_RANGE_ENABLE  (1 << 4)
-#define BRW_SF_CTL_DEBUG_CLIP_RECTANGLE_ENABLE	   (1 << 3)
-#define BRW_SF_CTL_SNAPSHOT_ALL_THREADS		   (1 << 2)
-#define BRW_SF_CTL_THREAD_SNAPSHOT_ENABLE	   (1 << 1)
-#define BRW_SF_CTL_SNAPSHOT_ENABLE		   (1 << 0)
-
-#define BRW_SF_STRG_VAL		       0x7b04
-#define BRW_SF_RDATA		       0x7b18
-
-#define BRW_WIZ_CTL		       0x7c00
-#define BRW_WIZ_CTL_SNAPSHOT_COMPLETE		   (1 << 31)
-#define BRW_WIZ_CTL_SUBSPAN_INSTANCE_SHIFT	   16
-#define BRW_WIZ_CTL_SNAPSHOT_MUX_WIZ_KERNEL_POINTER   (0 << 8)
-#define BRW_WIZ_CTL_SNAPSHOT_MUX_SUBSPAN_INSTANCE     (1 << 8)
-#define BRW_WIZ_CTL_SNAPSHOT_MUX_PRIMITIVE_SEQUENCE   (2 << 8)
-#define BRW_WIZ_CTL_SINGLE_SUBSPAN_DISPATCH	      (1 << 6)
-#define BRW_WIZ_CTL_IGNORE_COLOR_SCOREBOARD_STALLS    (1 << 5)
-#define BRW_WIZ_CTL_ENABLE_SUBSPAN_INSTANCE_COMPARE   (1 << 4)
-#define BRW_WIZ_CTL_USE_UPSTREAM_SNAPSHOT_FLAG	      (1 << 3)
-#define BRW_WIZ_CTL_SNAPSHOT_ALL_THREADS	      (1 << 2)
-#define BRW_WIZ_CTL_THREAD_SNAPSHOT_ENABLE	      (1 << 1)
-#define BRW_WIZ_CTL_SNAPSHOT_ENABLE		      (1 << 0)
-
-#define BRW_WIZ_STRG_VAL			      0x7c04
-#define BRW_WIZ_RDATA				      0x7c18
-
-#define BRW_TS_CTL		       0x7e00
-#define BRW_TS_CTL_SNAPSHOT_COMPLETE		   (1 << 31)
-#define BRW_TS_CTL_SNAPSHOT_MESSAGE_ERROR	   (0 << 8)
-#define BRW_TS_CTL_SNAPSHOT_INTERFACE_DESCRIPTOR   (3 << 8)
-#define BRW_TS_CTL_SNAPSHOT_ALL_CHILD_THREADS	   (1 << 2)
-#define BRW_TS_CTL_SNAPSHOT_ALL_ROOT_THREADS  	   (1 << 1)
-#define BRW_TS_CTL_SNAPSHOT_ENABLE		   (1 << 0)
-
-#define BRW_TS_STRG_VAL		       0x7e04
-#define BRW_TS_RDATA		       0x7e08
-
-#define BRW_TD_CTL		       0x8000
-#define BRW_TD_CTL_MUX_SHIFT	       8
-#define BRW_TD_CTL_EXTERNAL_HALT_R0_DEBUG_MATCH	   (1 << 7)
-#define BRW_TD_CTL_FORCE_EXTERNAL_HALT		   (1 << 6)
-#define BRW_TD_CTL_EXCEPTION_MASK_OVERRIDE	   (1 << 5)
-#define BRW_TD_CTL_FORCE_THREAD_BREAKPOINT_ENABLE  (1 << 4)
-#define BRW_TD_CTL_BREAKPOINT_ENABLE		   (1 << 2)
-#define BRW_TD_CTL2		       0x8004
-#define BRW_TD_CTL2_ILLEGAL_OPCODE_EXCEPTION_OVERRIDE (1 << 28)
-#define BRW_TD_CTL2_MASKSTACK_EXCEPTION_OVERRIDE      (1 << 26)
-#define BRW_TD_CTL2_SOFTWARE_EXCEPTION_OVERRIDE	      (1 << 25)
-#define BRW_TD_CTL2_ACTIVE_THREAD_LIMIT_SHIFT	      16
-#define BRW_TD_CTL2_ACTIVE_THREAD_LIMIT_ENABLE	      (1 << 8)
-#define BRW_TD_CTL2_THREAD_SPAWNER_EXECUTION_MASK_ENABLE (1 << 7)
-#define BRW_TD_CTL2_WIZ_EXECUTION_MASK_ENABLE	      (1 << 6)
-#define BRW_TD_CTL2_SF_EXECUTION_MASK_ENABLE	      (1 << 5)
-#define BRW_TD_CTL2_CLIPPER_EXECUTION_MASK_ENABLE     (1 << 4)
-#define BRW_TD_CTL2_GS_EXECUTION_MASK_ENABLE	      (1 << 3)
-#define BRW_TD_CTL2_VS_EXECUTION_MASK_ENABLE	      (1 << 0)
-#define BRW_TD_VF_VS_EMSK	       0x8008
-#define BRW_TD_GS_EMSK		       0x800c
-#define BRW_TD_CLIP_EMSK	       0x8010
-#define BRW_TD_SF_EMSK		       0x8014
-#define BRW_TD_WIZ_EMSK		       0x8018
-#define BRW_TD_0_6_EHTRG_VAL	       0x801c
-#define BRW_TD_0_7_EHTRG_VAL	       0x8020
-#define BRW_TD_0_6_EHTRG_MSK           0x8024
-#define BRW_TD_0_7_EHTRG_MSK	       0x8028
-#define BRW_TD_RDATA		       0x802c
-#define BRW_TD_TS_EMSK		       0x8030
-
-#define BRW_EU_CTL		       0x8800
-#define BRW_EU_CTL_SELECT_SHIFT	       16
-#define BRW_EU_CTL_DATA_MUX_SHIFT      8
-#define BRW_EU_ATT_0		       0x8810
-#define BRW_EU_ATT_1		       0x8814
-#define BRW_EU_ATT_DATA_0	       0x8820
-#define BRW_EU_ATT_DATA_1	       0x8824
-#define BRW_EU_ATT_CLR_0	       0x8830
-#define BRW_EU_ATT_CLR_1	       0x8834
-#define BRW_EU_RDATA		       0x8840
-
-typedef struct i965_device i965_device_t;
-typedef struct i965_surface i965_surface_t;
-typedef struct i965_shader i965_shader_t;
-typedef struct i965_stream i965_stream_t;
-
-struct i965_sf_state {
-    cairo_hash_entry_t entry;
-    uint32_t offset;
-};
-
-cairo_private cairo_bool_t
-i965_sf_state_equal (const void *, const void *);
-
-struct i965_cc_state {
-    cairo_hash_entry_t entry;
-    uint32_t offset;
-};
-
-cairo_private cairo_bool_t
-i965_cc_state_equal (const void *, const void *);
-
-struct i965_wm_kernel {
-    cairo_hash_entry_t entry;
-    uint32_t offset;
-};
-
-struct i965_wm_state {
-    cairo_hash_entry_t entry;
-    uint32_t kernel;
-    uint32_t sampler;
-    uint32_t offset;
-};
-
-cairo_private cairo_bool_t
-i965_wm_state_equal (const void *, const void *);
-
-struct i965_wm_binding {
-    cairo_hash_entry_t entry;
-    uint32_t table[4];
-    int size;
-    uint32_t offset;
-};
-
-cairo_private cairo_bool_t
-i965_wm_binding_equal (const void *, const void *);
-
-struct i965_sampler {
-    cairo_hash_entry_t entry;
-    uint32_t offset;
-};
-
-struct i965_vbo {
-    struct i965_vbo *next;
-    intel_bo_t *bo;
-    unsigned int count;
-};
-
-struct i965_surface {
-    intel_surface_t intel;
-
-    uint32_t stream;
-    uint32_t offset;
-};
-
-struct i965_pending_relocation {
-    uint32_t offset;
-    uint32_t read_domains;
-    uint32_t write_domain;
-    uint32_t delta;
-};
-
-struct i965_stream {
-    uint32_t used;
-    uint32_t committed;
-    uint32_t size;
-    uint8_t *data;
-    uint32_t serial;
-
-    int num_pending_relocations;
-    int max_pending_relocations;
-    struct i965_pending_relocation *pending_relocations;
-
-    int num_relocations;
-    int max_relocations;
-    struct drm_i915_gem_relocation_entry *relocations;
-};
-
-#define I965_BATCH_SIZE (16 * 4096)
-#define I965_GENERAL_SIZE (16 * 4096)
-#define I965_SURFACE_SIZE (32 * 4096)
-#define I965_VERTEX_SIZE (128 * 4096)
-
-#define I965_TILING_DEFAULT I915_TILING_Y
-
-
-struct i965_device {
-    intel_device_t intel;
-
-    cairo_bool_t is_g4x;
-
-    i965_shader_t *shader; /* note: only valid during geometry emission */
-
-    /* track state changes */
-    struct i965_sf_state sf_state;
-    struct i965_cc_state cc_state;
-    struct i965_wm_state wm_state;
-    struct i965_wm_binding wm_binding;
-
-    i965_surface_t *target;
-    uint32_t target_offset;
-
-    intel_bo_t *source;
-    uint32_t source_offset;
-
-    intel_bo_t *mask;
-    uint32_t mask_offset;
-
-    intel_bo_t *clip;
-    uint32_t clip_offset;
-
-    uint32_t draw_rectangle;
-
-    uint32_t vs_offset;
-    uint32_t border_color_offset;
-    cairo_hash_table_t *sf_states;
-    cairo_hash_table_t *cc_states;
-    cairo_hash_table_t *wm_kernels;
-    cairo_hash_table_t *wm_states;
-    cairo_hash_table_t *wm_bindings;
-    cairo_hash_table_t *samplers;
-    intel_bo_t *general_state;
-
-    cairo_freelist_t sf_freelist;
-    cairo_freelist_t cc_freelist;
-    cairo_freelist_t wm_kernel_freelist;
-    cairo_freelist_t wm_state_freelist;
-    cairo_freelist_t wm_binding_freelist;
-    cairo_freelist_t sampler_freelist;
-
-    uint32_t vertex_type;
-    uint32_t vertex_size;
-    uint32_t rectangle_size;
-    uint32_t last_vertex_size;
-
-    float *constants; /* 4 x matrix + 2 x source */
-    unsigned constants_size;
-    cairo_bool_t have_urb_fences;
-
-    i965_stream_t batch;
-    uint8_t batch_base[I965_BATCH_SIZE];
-    struct drm_i915_gem_relocation_entry batch_relocations[2048];
-
-    i965_stream_t surface;
-    uint8_t surface_base[I965_SURFACE_SIZE];
-    struct i965_pending_relocation surface_pending_relocations[1];
-    struct drm_i915_gem_relocation_entry surface_relocations[1024];
-
-    i965_stream_t general;
-    uint8_t general_base[I965_GENERAL_SIZE];
-    struct i965_pending_relocation general_pending_relocations[1];
-
-    i965_stream_t vertex;
-    uint8_t vertex_base[I965_VERTEX_SIZE];
-    struct i965_pending_relocation vertex_pending_relocations[512];
-
-    struct {
-	size_t gtt_size;
-
-	intel_bo_t *bo[1024];
-	int count;
-
-	struct drm_i915_gem_exec_object2 exec[1024];
-    } exec;
-    cairo_list_t flush;
-};
-
-typedef enum {
-    VS_NONE = 0,
-    VS_GLYPHS,
-    VS_SPANS,
-} i965_vertex_shader_t;
-
-typedef enum {
-    FS_NONE = 0,
-    FS_CONSTANT,
-    FS_LINEAR,
-    FS_RADIAL,
-    FS_SURFACE,
-    FS_GLYPHS,
-    FS_SPANS,
-} i965_fragment_shader_t;
-
-typedef enum {
-    PATTERN_BASE,
-    PATTERN_SOLID,
-    PATTERN_LINEAR,
-    PATTERN_RADIAL,
-    PATTERN_SURFACE,
-} i965_shader_channel_t;
-#define PATTERN_NONE (i965_shader_channel_t)-1
-
-struct i965_shader {
-    i965_device_t *device;
-    i965_surface_t *target;
-
-    cairo_operator_t op;
-
-    cairo_bool_t committed;
-    cairo_bool_t need_combine;
-
-    float constants[4*8 + 2*8]; /* 4 x matrix + 2 x source */
-    unsigned constants_size;
-
-    union i965_shader_channel {
-	struct {
-	    i965_vertex_shader_t vertex;
-	    i965_fragment_shader_t fragment;
-	    i965_shader_channel_t pattern;
-	} type;
-	struct i965_shader_base {
-	    i965_vertex_shader_t vertex;
-	    i965_fragment_shader_t fragment;
-	    i965_shader_channel_t pattern;
-
-	    uint32_t mode;
-
-	    float constants[8];
-	    unsigned constants_size;
-
-	    intel_bo_t *bo;
-	    cairo_format_t format;
-	    cairo_content_t content;
-	    int width, height, stride;
-	    int filter, extend;
-	    cairo_matrix_t matrix;
-	    cairo_bool_t has_component_alpha;
-	} base;
-	struct i965_shader_solid {
-	    struct i965_shader_base base;
-	} solid;
-	struct i965_shader_linear {
-	    struct i965_shader_base base;
-	} linear;
-	struct i965_shader_radial {
-	    struct i965_shader_base base;
-	} radial;
-	struct i965_shader_surface {
-	    struct i965_shader_base base;
-	    cairo_surface_t *surface;
-	} surface;
-    } source, mask, clip, dst;
-
-    jmp_buf unwind;
-};
-
-enum i965_shader_linear_mode {
-    /* XXX REFLECT */
-    LINEAR_TEXTURE,
-    LINEAR_NONE,
-    LINEAR_REPEAT,
-    LINEAR_PAD,
-};
-
-enum i965_shader_radial_mode {
-    RADIAL_ONE,
-    RADIAL_TWO
-};
-
-typedef cairo_status_t
-(*i965_spans_func_t) (void			*closure,
-		      cairo_span_renderer_t	*renderer,
-		      const cairo_rectangle_int_t	*extents);
-
-static inline i965_device_t *
-i965_device (i965_surface_t *surface)
-{
-    return (i965_device_t *) surface->intel.drm.base.device;
-}
-
-cairo_private void
-i965_emit_relocation (i965_device_t *device,
-		      i965_stream_t *stream,
-		      intel_bo_t *target,
-		      uint32_t target_offset,
-		      uint32_t read_domains,
-		      uint32_t write_domain,
-		      uint32_t offset);
-
-static cairo_always_inline uint32_t
-i965_stream_emit (i965_stream_t *stream, const void *data, size_t size)
-{
-    uint32_t offset;
-
-    offset = stream->used;
-    assert (offset + size <= stream->size);
-    memcpy (stream->data + offset, data, size);
-    stream->used += size;
-
-    return offset;
-}
-
-static cairo_always_inline void
-i965_stream_align (i965_stream_t *stream, uint32_t size)
-{
-    stream->used = (stream->used + size - 1) & -size;
-}
-
-static cairo_always_inline void *
-i965_stream_alloc (i965_stream_t *stream, uint32_t align, uint32_t size)
-{
-    void *ptr;
-
-    if (align)
-	i965_stream_align (stream, align);
-
-    assert (stream->used + size <= stream->size);
-    ptr = stream->data + stream->used;
-    stream->used += size;
-
-    return ptr;
-}
-
-static cairo_always_inline uint32_t
-i965_stream_offsetof (i965_stream_t *stream, const void *ptr)
-{
-    return (char *) ptr - (char *) stream->data;
-}
-
-cairo_private void
-i965_stream_commit (i965_device_t *device,
-		    i965_stream_t *stream);
-
-cairo_private void
-i965_general_state_reset (i965_device_t *device);
-
-static inline void
-i965_batch_emit_dword (i965_device_t *device, uint32_t dword)
-{
-    *(uint32_t *) (device->batch.data + device->batch.used) = dword;
-    device->batch.used += 4;
-}
-
-#define OUT_BATCH(dword) i965_batch_emit_dword(device, dword)
-
-cairo_private void
-i965_clipped_vertices (i965_device_t *device,
-		       struct i965_vbo *vbo,
-		       cairo_region_t *clip_region);
-
-cairo_private void
-i965_flush_vertices (i965_device_t *device);
-
-cairo_private void
-i965_finish_vertices (i965_device_t *device);
-
-static inline float *
-i965_add_rectangle (i965_device_t *device)
-{
-    float *vertices;
-    uint32_t size;
-
-    size = device->rectangle_size;
-    if (unlikely (device->vertex.used + size > device->vertex.size))
-	i965_finish_vertices (device);
-
-    vertices = (float *) (device->vertex.data + device->vertex.used);
-    device->vertex.used += size;
-
-    return vertices;
-}
-
-static inline void
-i965_shader_add_rectangle (const i965_shader_t *shader,
-			   int x, int y,
-			   int w, int h)
-{
-    float *v;
-
-    v= i965_add_rectangle (shader->device);
-
-    /* bottom-right */
-    *v++ = x + w;
-    *v++ = y + h;
-
-    /* bottom-left */
-    *v++ = x;
-    *v++ = y + h;
-
-    /* top-left */
-    *v++ = x;
-    *v++ = y;
-}
-
-cairo_private cairo_surface_t *
-i965_surface_create_internal (cairo_drm_device_t *base_dev,
-			      cairo_format_t format,
-			      int width, int height,
-			      uint32_t tiling,
-			      cairo_bool_t gpu_target);
-
-cairo_private cairo_status_t
-i965_clip_and_composite_spans (i965_surface_t		*dst,
-			       cairo_operator_t		 op,
-			       const cairo_pattern_t	*pattern,
-			       cairo_antialias_t	 antialias,
-			       i965_spans_func_t	 draw_func,
-			       void			*draw_closure,
-			       const cairo_composite_rectangles_t*extents,
-			       cairo_clip_t		*clip);
-
-cairo_private cairo_int_status_t
-i965_surface_glyphs (void			*abstract_surface,
-		     cairo_operator_t		 op,
-		     const cairo_pattern_t	*source,
-		     cairo_glyph_t		*glyphs,
-		     int			 num_glyphs,
-		     cairo_scaled_font_t	*scaled_font,
-		     cairo_clip_t		*clip,
-		     int *num_remaining);
-
-cairo_private void
-i965_shader_init (i965_shader_t *shader,
-		  i965_surface_t *dst,
-		  cairo_operator_t op);
-
-cairo_private cairo_status_t
-i965_shader_acquire_pattern (i965_shader_t *shader,
-			     union i965_shader_channel *src,
-			     const cairo_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents);
-
-cairo_private void
-i965_shader_set_clip (i965_shader_t *shader,
-		      cairo_clip_t *clip);
-
-cairo_private cairo_status_t
-i965_shader_commit (i965_shader_t *shader,
-		    i965_device_t *device);
-
-cairo_private void
-i965_shader_fini (i965_shader_t *shader);
-
-cairo_private cairo_status_t
-i965_device_flush (i965_device_t *device);
-
-cairo_private cairo_status_t
-i965_fixup_unbounded (i965_surface_t *dst,
-		      const cairo_composite_rectangles_t *extents,
-		      cairo_clip_t *clip);
-
-static inline int
-i965_filter (cairo_filter_t filter)
-{
-    switch (filter) {
-    default:
-    case CAIRO_FILTER_FAST:
-    case CAIRO_FILTER_NEAREST:
-	return BRW_MAPFILTER_NEAREST;
-
-    case CAIRO_FILTER_GOOD:
-    case CAIRO_FILTER_BEST:
-    case CAIRO_FILTER_BILINEAR:
-    case CAIRO_FILTER_GAUSSIAN:
-	return BRW_MAPFILTER_LINEAR;
-    }
-}
-
-static inline int
-i965_extend (cairo_extend_t extend)
-{
-    switch (extend) {
-    default:
-    case CAIRO_EXTEND_NONE:
-	return BRW_TEXCOORDMODE_CLAMP_BORDER;
-    case CAIRO_EXTEND_REPEAT:
-	return BRW_TEXCOORDMODE_WRAP;
-    case CAIRO_EXTEND_PAD:
-	return BRW_TEXCOORDMODE_CLAMP;
-    case CAIRO_EXTEND_REFLECT:
-	return BRW_TEXCOORDMODE_MIRROR;
-    }
-}
-
-#endif /* CAIRO_DRM_I965_PRIVATE_H */
diff --git a/src/drm/cairo-drm-i965-shader.c b/src/drm/cairo-drm-i965-shader.c
deleted file mode 100644
index 8fa3b4bd2..000000000
--- a/src/drm/cairo-drm-i965-shader.c
+++ /dev/null
@@ -1,2825 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Kristian Høgsberg
- * Copyright © 2009 Chris Wilson
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * Contributor(s):
- *	Chris Wilson <chris at chris-wilson.co.uk>
- *      Kristian Høgsberg <krh at bitplanet.net>
- */
-
-#include "cairoint.h"
-
-#include "cairo-error-private.h"
-#include "cairo-drm-i965-private.h"
-#include "cairo-surface-subsurface-private.h"
-#include "cairo-surface-snapshot-private.h"
-
-#include "cairo-drm-intel-brw-eu.h"
-
-/* Theory of shaders:
- *
- * 3 types of rectangular inputs:
- *  (a) standard composite: x,y, use source, mask matrices to compute texcoords
- *  (b) spans: x,y, alpha, use source matrix
- *  (c) glyphs: x,y, s,t, use source matrix
- *
- * 5 types of pixel shaders:
- *  (a) Solid colour
- *  (b) Linear gradient (via 1D texture, with precomputed tex)
- *  (c) Radial gradient (per-pixel s computation, 1D texture)
- *  (d) Spans (mask only): apply opacity
- *  (e) Texture (includes glyphs).
- *
- *  Clip masks are limited to 2D textures only.
- */
-
-/* XXX dual source blending for LERP + ComponentAlpha!!! */
-
-#define BRW_GRF_BLOCKS(nreg)    ((nreg + 15) / 16 - 1)
-
-#define SF_KERNEL_NUM_GRF  1
-#define SF_MAX_THREADS	   24
-
-#define PS_MAX_THREADS_CTG 50
-#define PS_MAX_THREADS_BRW 32
-
-#define URB_CS_ENTRY_SIZE     3 /* We need 4 matrices + 2 sources */
-#define URB_CS_ENTRIES	      4 /* 4x sets of CONSTANT_BUFFER */
-
-#define URB_VS_ENTRY_SIZE     1
-#define URB_VS_ENTRIES	      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     1
-#define URB_SF_ENTRIES	      (SF_MAX_THREADS + 1)
-
-static void
-i965_pipelined_flush (i965_device_t *device)
-{
-    intel_bo_t *bo, *next;
-
-    if (device->batch.used == 0)
-	return;
-
-    OUT_BATCH (BRW_PIPE_CONTROL |
-	       BRW_PIPE_CONTROL_NOWRITE |
-	       BRW_PIPE_CONTROL_WC_FLUSH |
-	       2);
-    OUT_BATCH(0);   /* Destination address */ 
-    OUT_BATCH(0);   /* Immediate data low DW */ 
-    OUT_BATCH(0);   /* Immediate data high DW */ 
-
-    cairo_list_foreach_entry_safe (bo, next, intel_bo_t, &device->flush, link) {
-	bo->batch_write_domain = 0;
-	cairo_list_init (&bo->link);
-    }
-    cairo_list_init (&device->flush);
-}
-
-static cairo_status_t
-i965_shader_acquire_solid (i965_shader_t *shader,
-			   union i965_shader_channel *src,
-			   const cairo_solid_pattern_t *solid,
-			   const cairo_rectangle_int_t *extents)
-{
-    src->type.fragment = FS_CONSTANT;
-    src->type.vertex = VS_NONE;
-    src->type.pattern = PATTERN_SOLID;
-
-    src->base.content = _cairo_color_get_content (&solid->color);
-    src->base.constants[0] = solid->color.red   * solid->color.alpha;
-    src->base.constants[1] = solid->color.green * solid->color.alpha;
-    src->base.constants[2] = solid->color.blue  * solid->color.alpha;
-    src->base.constants[3] = solid->color.alpha;
-    src->base.constants_size = 4;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_shader_acquire_linear (i965_shader_t *shader,
-			    union i965_shader_channel *src,
-			    const cairo_linear_pattern_t *linear,
-			    const cairo_rectangle_int_t *extents)
-{
-    intel_buffer_t buffer;
-    cairo_status_t status;
-    double x0, y0, sf;
-    double dx, dy, offset;
-
-    status = intel_gradient_render (&i965_device (shader->target)->intel,
-				    &linear->base, &buffer);
-    if (unlikely (status))
-	return status;
-
-    src->type.vertex = VS_NONE;
-    src->type.pattern = PATTERN_LINEAR;
-    src->type.fragment = FS_LINEAR;
-    src->base.bo = buffer.bo;
-    src->base.content = CAIRO_CONTENT_COLOR_ALPHA;
-    src->base.format = buffer.format;
-    src->base.width  = buffer.width;
-    src->base.height = buffer.height;
-    src->base.stride = buffer.stride;
-    src->base.filter = i965_filter (CAIRO_FILTER_BILINEAR);
-    src->base.extend = i965_extend (linear->base.base.extend);
-
-    dx = linear->pd2.x - linear->pd1.x;
-    dy = linear->pd2.y - linear->pd1.y;
-    sf = 1. / (dx * dx + dy * dy);
-    dx *= sf;
-    dy *= sf;
-
-    x0 = linear->pd1.x;
-    y0 = linear->pd1.y;
-    offset = dx*x0 + dy*y0;
-
-    if (_cairo_matrix_is_identity (&linear->base.base.matrix)) {
-	src->base.matrix.xx = dx;
-	src->base.matrix.xy = dy;
-	src->base.matrix.x0 = -offset;
-    } else {
-	cairo_matrix_t m;
-
-	cairo_matrix_init (&m, dx, 0, dy, 0, -offset, 0);
-	cairo_matrix_multiply (&src->base.matrix, &linear->base.base.matrix, &m);
-    }
-    src->base.matrix.yx = 0.;
-    src->base.matrix.yy = 1.;
-    src->base.matrix.y0 = 0.;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_shader_acquire_radial (i965_shader_t *shader,
-			    union i965_shader_channel *src,
-			    const cairo_radial_pattern_t *radial,
-			    const cairo_rectangle_int_t *extents)
-{
-    intel_buffer_t buffer;
-    cairo_status_t status;
-    double dx, dy, dr, r1;
-
-    status = intel_gradient_render (&i965_device (shader->target)->intel,
-				    &radial->base, &buffer);
-    if (unlikely (status))
-	return status;
-
-    src->type.vertex = VS_NONE;
-    src->type.pattern = PATTERN_RADIAL;
-    src->type.fragment = FS_RADIAL;
-    src->base.bo = buffer.bo;
-    src->base.content = CAIRO_CONTENT_COLOR_ALPHA;
-    src->base.format = buffer.format;
-    src->base.width  = buffer.width;
-    src->base.height = buffer.height;
-    src->base.stride = buffer.stride;
-    src->base.filter = i965_filter (CAIRO_FILTER_BILINEAR);
-    src->base.extend = i965_extend (radial->base.base.extend);
-
-    dx = radial->cd2.center.x - radial->cd1.center.x;
-    dy = radial->cd2.center.y - radial->cd1.center.y;
-    dr = radial->cd2.radius   - radial->cd1.radius;
-
-    r1 = radial->cd1.radius;
-
-    if (FALSE && (radial->cd2.center.x == radial->cd1.center.x &&
-		  radial->cd2.center.y == radial->cd1.center.y))
-    {
-	/* XXX dr == 0, meaningless with anything other than PAD */
-	src->base.constants[0] = radial->cd1.center.x / dr;
-	src->base.constants[1] = radial->cd1.center.y / dr;
-	src->base.constants[2] = 1. / dr;
-	src->base.constants[3] = -r1 / dr;
-
-	src->base.constants_size = 4;
-	src->base.mode = RADIAL_ONE;
-    } else {
-	src->base.constants[0] = -radial->cd1.center.x;
-	src->base.constants[1] = -radial->cd1.center.y;
-	src->base.constants[2] = r1;
-	src->base.constants[3] = -4 * (dx*dx + dy*dy - dr*dr);
-
-	src->base.constants[4] = -2 * dx;
-	src->base.constants[5] = -2 * dy;
-	src->base.constants[6] = -2 * r1 * dr;
-	src->base.constants[7] = 1 / (2 * (dx*dx + dy*dy - dr*dr));
-
-	src->base.constants_size = 8;
-	src->base.mode = RADIAL_TWO;
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_surface_clone (i965_device_t *device,
-		    cairo_image_surface_t *image,
-		    i965_surface_t **clone_out)
-{
-    i965_surface_t *clone;
-    cairo_status_t status;
-
-    clone = (i965_surface_t *)
-	i965_surface_create_internal (&device->intel.base,
-				      image->base.content,
-				      image->width,
-				      image->height,
-				      I965_TILING_DEFAULT,
-				      FALSE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    status = intel_bo_put_image (&device->intel,
-				 to_intel_bo (clone->intel.drm.bo),
-				 image,
-				 0, 0,
-				 image->width, image->height,
-				 0, 0);
-
-    if (unlikely (status)) {
-	cairo_surface_destroy (&clone->intel.drm.base);
-	return status;
-    }
-
-    status = intel_snapshot_cache_insert (&device->intel, &clone->intel);
-    if (unlikely (status)) {
-	cairo_surface_destroy (&clone->intel.drm.base);
-	return status;
-    }
-
-    _cairo_surface_attach_snapshot (&image->base,
-				    &clone->intel.drm.base,
-				    intel_surface_detach_snapshot);
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_surface_clone_subimage (i965_device_t *device,
-			     cairo_image_surface_t *image,
-			     const cairo_rectangle_int_t *extents,
-			     i965_surface_t **clone_out)
-{
-    i965_surface_t *clone;
-    cairo_status_t status;
-
-    clone = (i965_surface_t *)
-	i965_surface_create_internal (&device->intel.base,
-				      image->base.content,
-				      extents->width,
-				      extents->height,
-				      I965_TILING_DEFAULT,
-				      FALSE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    status = intel_bo_put_image (to_intel_device (clone->intel.drm.base.device),
-				 to_intel_bo (clone->intel.drm.bo),
-				 image,
-				 extents->x, extents->y,
-				 extents->width, extents->height,
-				 0, 0);
-    if (unlikely (status))
-	return status;
-
-    *clone_out = clone;
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_shader_acquire_solid_surface (i965_shader_t *shader,
-				   union i965_shader_channel *src,
-				   cairo_surface_t *surface,
-				   const cairo_rectangle_int_t *extents)
-{
-    cairo_image_surface_t *image;
-    void *image_extra;
-    cairo_status_t status;
-    uint32_t argb;
-
-    status = _cairo_surface_acquire_source_image (surface, &image, &image_extra);
-    if (unlikely (status))
-	return status;
-
-    if (image->format != CAIRO_FORMAT_ARGB32) {
-	cairo_surface_t *pixel;
-	cairo_surface_pattern_t pattern;
-
-	/* extract the pixel as argb32 */
-	pixel = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
-	_cairo_pattern_init_for_surface (&pattern, &image->base);
-	cairo_matrix_init_translate (&pattern.base.matrix, extents->x, extents->y);
-	pattern.base.filter = CAIRO_FILTER_NEAREST;
-	status = _cairo_surface_paint (pixel, CAIRO_OPERATOR_SOURCE, &pattern.base, NULL);
-	_cairo_pattern_fini (&pattern.base);
-
-	if (unlikely (status)) {
-	    _cairo_surface_release_source_image (surface, image, image_extra);
-	    cairo_surface_destroy (pixel);
-	    return status;
-	}
-
-	argb = *(uint32_t *) ((cairo_image_surface_t *) pixel)->data;
-	cairo_surface_destroy (pixel);
-    } else {
-	argb = ((uint32_t *) (image->data + extents->y * image->stride))[extents->x];
-    }
-
-    _cairo_surface_release_source_image (surface, image, image_extra);
-
-    if (argb >> 24 == 0)
-	argb = 0;
-
-    src->base.constants[0] = ((argb >> 16) & 0xff) / 255.;
-    src->base.constants[1] = ((argb >>  8) & 0xff) / 255.;
-    src->base.constants[2] = ((argb >>  0) & 0xff) / 255.;
-    src->base.constants[3] = ((argb >> 24) & 0xff) / 255.;
-    src->base.constants_size = 4;
-
-    src->base.content  = CAIRO_CONTENT_COLOR_ALPHA;
-    if (CAIRO_ALPHA_IS_OPAQUE(src->base.constants[3]))
-	src->base.content &= ~CAIRO_CONTENT_ALPHA;
-    src->type.fragment = FS_CONSTANT;
-    src->type.vertex   = VS_NONE;
-    src->type.pattern  = PATTERN_SOLID;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_shader_acquire_surface (i965_shader_t *shader,
-			     union i965_shader_channel *src,
-			     const cairo_surface_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents)
-{
-    cairo_surface_t *surface, *drm;
-    cairo_matrix_t m;
-    cairo_status_t status;
-    int src_x = 0, src_y = 0;
-
-    assert (src->type.fragment == FS_NONE);
-    drm = surface = pattern->surface;
-
-    if (surface->type == CAIRO_SURFACE_TYPE_DRM) {
-	if (surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
-	    drm = ((cairo_surface_subsurface_t *) surface)->target;
-	} else if (surface->backend->type == CAIRO_INTERNAL_SURFACE_TYPE_SNAPSHOT) {
-	    drm = ((cairo_surface_snapshot_t *) surface)->target;
-	}
-    }
-
-    src->type.pattern = PATTERN_SURFACE;
-    src->surface.surface = NULL;
-    if (drm->type == CAIRO_SURFACE_TYPE_DRM) {
-	i965_surface_t *s = (i965_surface_t *) drm;
-
-	if (surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
-	    if (s->intel.drm.base.device == shader->target->intel.drm.base.device) {
-		cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) surface;
-		if (s != shader->target) {
-		    int x;
-
-		    if (s->intel.drm.fallback != NULL) {
-			status = intel_surface_flush (s, 0);
-			if (unlikely (status))
-			    return status;
-		    }
-
-		    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
-			i965_pipelined_flush (i965_device (s));
-
-		    src->type.fragment = FS_SURFACE;
-
-		    src->base.bo = to_intel_bo (s->intel.drm.bo);
-		    src->base.format = s->intel.drm.format;
-		    src->base.content = s->intel.drm.base.content;
-		    src->base.width = sub->extents.width;
-		    src->base.height = sub->extents.height;
-		    src->base.stride = s->intel.drm.stride;
-
-		    x = sub->extents.x;
-		    if (s->intel.drm.format != CAIRO_FORMAT_A8)
-			x *= 4;
-
-		    /* XXX tiling restrictions upon offset? */
-		    //src->base.offset[0] = s->offset + sub->extents.y * s->intel.drm.stride + x;
-		} else {
-		    i965_surface_t *clone;
-		    cairo_surface_pattern_t pattern;
-
-		    clone = (i965_surface_t *)
-			i965_surface_create_internal ((cairo_drm_device_t *) s->intel.drm.base.device,
-						      s->intel.drm.base.content,
-						      sub->extents.width,
-						      sub->extents.height,
-						      I965_TILING_DEFAULT,
-						      TRUE);
-		    if (unlikely (clone->intel.drm.base.status))
-			return clone->intel.drm.base.status;
-
-		    _cairo_pattern_init_for_surface (&pattern, &s->intel.drm.base);
-		    pattern.base.filter = CAIRO_FILTER_NEAREST;
-		    cairo_matrix_init_translate (&pattern.base.matrix,
-						 sub->extents.x, sub->extents.y);
-
-		    status = _cairo_surface_paint (&clone->intel.drm.base,
-						   CAIRO_OPERATOR_SOURCE,
-						   &pattern.base,
-						   NULL);
-
-		    _cairo_pattern_fini (&pattern.base);
-
-		    if (unlikely (status)) {
-			cairo_surface_destroy (&clone->intel.drm.base);
-			return status;
-		    }
-
-		    i965_pipelined_flush (i965_device (s));
-		    src->type.fragment = FS_SURFACE;
-
-		    src->base.bo = to_intel_bo (clone->intel.drm.bo);
-		    src->base.format = clone->intel.drm.format;
-		    src->base.content = clone->intel.drm.base.content;
-		    src->base.width = clone->intel.drm.width;
-		    src->base.height = clone->intel.drm.height;
-		    src->base.stride = clone->intel.drm.stride;
-
-		    src->surface.surface = &clone->intel.drm.base;
-		}
-
-		src_x = sub->extents.x;
-		src_y = sub->extents.y;
-	    }
-	} else {
-	    if (s->intel.drm.base.device == shader->target->intel.drm.base.device) {
-		if (s != shader->target) {
-		    if (s->intel.drm.fallback != NULL) {
-			status = intel_surface_flush (s, 0);
-			if (unlikely (status))
-			    return status;
-		    }
-
-		    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
-			i965_pipelined_flush (i965_device (s));
-
-		    src->type.fragment = FS_SURFACE;
-
-		    src->base.bo = to_intel_bo (s->intel.drm.bo);
-		    src->base.format = s->intel.drm.format;
-		    src->base.content = s->intel.drm.base.content;
-		    src->base.width = s->intel.drm.width;
-		    src->base.height = s->intel.drm.height;
-		    src->base.stride = s->intel.drm.stride;
-		} else {
-		    i965_surface_t *clone;
-		    cairo_surface_pattern_t pattern;
-
-		    clone = (i965_surface_t *)
-			i965_surface_create_internal ((cairo_drm_device_t *) s->intel.drm.base.device,
-						      s->intel.drm.base.content,
-						      s->intel.drm.width,
-						      s->intel.drm.height,
-						      I965_TILING_DEFAULT,
-						      TRUE);
-		    if (unlikely (clone->intel.drm.base.status))
-			return clone->intel.drm.base.status;
-
-		    _cairo_pattern_init_for_surface (&pattern, &s->intel.drm.base);
-		    pattern.base.filter = CAIRO_FILTER_NEAREST;
-		    status = _cairo_surface_paint (&clone->intel.drm.base,
-						   CAIRO_OPERATOR_SOURCE,
-						   &pattern.base,
-						   NULL);
-
-		    _cairo_pattern_fini (&pattern.base);
-
-		    if (unlikely (status)) {
-			cairo_surface_destroy (&clone->intel.drm.base);
-			return status;
-		    }
-
-		    i965_pipelined_flush (i965_device (s));
-		    src->type.fragment = FS_SURFACE;
-
-		    src->base.bo = to_intel_bo (clone->intel.drm.bo);
-		    src->base.format = clone->intel.drm.format;
-		    src->base.content = clone->intel.drm.base.content;
-		    src->base.width = clone->intel.drm.width;
-		    src->base.height = clone->intel.drm.height;
-		    src->base.stride = clone->intel.drm.stride;
-
-		    src->surface.surface = &clone->intel.drm.base;
-		}
-	    }
-	}
-    }
-
-    if (src->type.fragment == FS_NONE) {
-	i965_surface_t *s;
-
-	if (extents->width == 1 && extents->height == 1) {
-	    return i965_shader_acquire_solid_surface (shader, src,
-						      surface, extents);
-	}
-
-	s = (i965_surface_t *)
-	    _cairo_surface_has_snapshot (surface,
-					 shader->target->intel.drm.base.backend);
-	if (s != NULL) {
-	    i965_device_t *device = i965_device (shader->target);
-	    intel_bo_t *bo = to_intel_bo (s->intel.drm.bo);
-
-	    if (bo->purgeable &&
-		! intel_bo_madvise (&device->intel, bo, I915_MADV_WILLNEED))
-	    {
-		_cairo_surface_detach_snapshot (&s->intel.drm.base);
-		s = NULL;
-	    }
-
-	    if (s != NULL)
-		cairo_surface_reference (&s->intel.drm.base);
-	}
-
-	if (s == NULL) {
-	    cairo_image_surface_t *image;
-	    void *image_extra;
-	    cairo_status_t status;
-
-	    status = _cairo_surface_acquire_source_image (surface, &image, &image_extra);
-	    if (unlikely (status))
-		return status;
-
-	    if (image->width < 8192 && image->height < 8192) {
-		status = i965_surface_clone (i965_device (shader->target), image, &s);
-	    } else {
-		status = i965_surface_clone_subimage (i965_device (shader->target),
-						      image, extents, &s);
-		src_x = -extents->x;
-		src_y = -extents->y;
-	    }
-
-	    _cairo_surface_release_source_image (surface, image, image_extra);
-
-	    if (unlikely (status))
-		return status;
-
-	    /* XXX? */
-	    //intel_bo_mark_purgeable (to_intel_bo (s->intel.drm.bo), TRUE);
-	}
-
-	src->type.fragment = FS_SURFACE;
-
-	src->base.bo = to_intel_bo (s->intel.drm.bo);
-	src->base.content = s->intel.drm.base.content;
-	src->base.format = s->intel.drm.format;
-	src->base.width  = s->intel.drm.width;
-	src->base.height = s->intel.drm.height;
-	src->base.stride = s->intel.drm.stride;
-
-	src->surface.surface = &s->intel.drm.base;
-
-	drm = &s->intel.drm.base;
-    }
-
-    /* XXX transform nx1 or 1xn surfaces to 1D? */
-
-    src->type.vertex = VS_NONE;
-
-    src->base.extend = i965_extend (pattern->base.extend);
-    if (pattern->base.extend == CAIRO_EXTEND_NONE &&
-	extents->x >= 0 && extents->y >= 0 &&
-	extents->x + extents->width  <= src->base.width &&
-	extents->y + extents->height <= src->base.height)
-    {
-	/* Convert a wholly contained NONE to a REFLECT as the contiguous sampler
-	 * cannot not handle CLAMP_BORDER textures.
-	 */
-	src->base.extend = i965_extend (CAIRO_EXTEND_REFLECT);
-	/* XXX also need to check |u,v| < 3 */
-    }
-
-    src->base.filter = i965_filter (pattern->base.filter);
-    if (_cairo_matrix_is_pixel_exact (&pattern->base.matrix))
-	src->base.filter = i965_filter (CAIRO_FILTER_NEAREST);
-
-    /* tweak the src matrix to map from dst to texture coordinates */
-    src->base.matrix = pattern->base.matrix;
-    if (src_x | src_y)
-	cairo_matrix_translate (&src->base.matrix, src_x, src_x);
-    cairo_matrix_init_scale (&m, 1. / src->base.width, 1. / src->base.height);
-    cairo_matrix_multiply (&src->base.matrix, &src->base.matrix, &m);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
-i965_shader_acquire_pattern (i965_shader_t *shader,
-			     union i965_shader_channel *src,
-			     const cairo_pattern_t *pattern,
-			     const cairo_rectangle_int_t *extents)
-{
-    switch (pattern->type) {
-    case CAIRO_PATTERN_TYPE_SOLID:
-	return i965_shader_acquire_solid (shader, src,
-					  (cairo_solid_pattern_t *) pattern,
-					  extents);
-
-    case CAIRO_PATTERN_TYPE_LINEAR:
-	return i965_shader_acquire_linear (shader, src,
-					   (cairo_linear_pattern_t *) pattern,
-					   extents);
-
-    case CAIRO_PATTERN_TYPE_RADIAL:
-	return i965_shader_acquire_radial (shader, src,
-					   (cairo_radial_pattern_t *) pattern,
-					   extents);
-
-    case CAIRO_PATTERN_TYPE_SURFACE:
-	return i965_shader_acquire_surface (shader, src,
-					    (cairo_surface_pattern_t *) pattern,
-					    extents);
-
-    default:
-	ASSERT_NOT_REACHED;
-	return CAIRO_STATUS_SUCCESS;
-    }
-}
-
-static void
-i965_shader_channel_init (union i965_shader_channel *channel)
-{
-    channel->type.vertex = VS_NONE;
-    channel->type.fragment = FS_NONE;
-    channel->type.pattern = PATTERN_NONE;
-
-    channel->base.mode = 0;
-    channel->base.bo = NULL;
-    channel->base.filter = i965_extend (CAIRO_FILTER_NEAREST);
-    channel->base.extend = i965_extend (CAIRO_EXTEND_NONE);
-    channel->base.has_component_alpha = 0;
-    channel->base.constants_size = 0;
-}
-
-void
-i965_shader_init (i965_shader_t *shader,
-		  i965_surface_t *dst,
-		  cairo_operator_t op)
-{
-    shader->committed = FALSE;
-    shader->device = i965_device (dst);
-    shader->target = dst;
-    shader->op = op;
-    shader->constants_size = 0;
-
-    shader->need_combine = FALSE;
-
-    i965_shader_channel_init (&shader->source);
-    i965_shader_channel_init (&shader->mask);
-    i965_shader_channel_init (&shader->clip);
-    i965_shader_channel_init (&shader->dst);
-}
-
-void
-i965_shader_fini (i965_shader_t *shader)
-{
-    if (shader->source.type.pattern == PATTERN_SURFACE)
-	cairo_surface_destroy (shader->source.surface.surface);
-    if (shader->mask.type.pattern == PATTERN_SURFACE)
-	cairo_surface_destroy (shader->mask.surface.surface);
-    if (shader->clip.type.pattern == PATTERN_SURFACE)
-	cairo_surface_destroy (shader->clip.surface.surface);
-    if (shader->dst.type.pattern == PATTERN_SURFACE)
-	cairo_surface_destroy (shader->dst.surface.surface);
-}
-
-void
-i965_shader_set_clip (i965_shader_t *shader,
-		      cairo_clip_t *clip)
-{
-    cairo_surface_t *clip_surface;
-    int clip_x, clip_y;
-    union i965_shader_channel *channel;
-    i965_surface_t *s;
-
-    clip_surface = _cairo_clip_get_surface (clip, &shader->target->intel.drm.base, &clip_x, &clip_y);
-    assert (clip_surface->status == CAIRO_STATUS_SUCCESS);
-    assert (clip_surface->type == CAIRO_SURFACE_TYPE_DRM);
-    s = (i965_surface_t *) clip_surface;
-
-    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
-	i965_pipelined_flush (i965_device (s));
-
-    channel = &shader->clip;
-    channel->type.pattern = PATTERN_BASE;
-    channel->type.vertex  = VS_NONE;
-    channel->type.fragment = FS_SURFACE;
-
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
-    channel->base.content = CAIRO_CONTENT_ALPHA;
-    channel->base.format = CAIRO_FORMAT_A8;
-    channel->base.width  = s->intel.drm.width;
-    channel->base.height = s->intel.drm.height;
-    channel->base.stride = s->intel.drm.stride;
-
-    channel->base.extend = i965_extend (CAIRO_EXTEND_NONE);
-    channel->base.filter = i965_filter (CAIRO_FILTER_NEAREST);
-
-    cairo_matrix_init_scale (&shader->clip.base.matrix,
-			     1. / s->intel.drm.width,
-			     1. / s->intel.drm.height);
-
-    cairo_matrix_translate (&shader->clip.base.matrix,
-			    -clip_x, -clip_y);
-}
-
-static cairo_bool_t
-i965_shader_check_aperture (i965_shader_t *shader,
-			    i965_device_t *device)
-{
-    uint32_t size = device->exec.gtt_size;
-
-    if (shader->target != device->target) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
-	if (bo->exec == NULL)
-	    size += bo->base.size;
-    }
-
-    if (shader->source.base.bo != NULL && shader->source.base.bo != device->source) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
-	if (bo->exec == NULL)
-	    size += bo->base.size;
-    }
-
-    if (shader->mask.base.bo != NULL && shader->mask.base.bo != device->mask) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
-	if (bo->exec == NULL)
-	    size += bo->base.size;
-    }
-
-    if (shader->clip.base.bo != NULL && shader->clip.base.bo != device->clip) {
-	const intel_bo_t *bo = to_intel_bo (shader->target->intel.drm.bo);
-	if (bo->exec == NULL)
-	    size += bo->base.size;
-    }
-
-    return size <= device->intel.gtt_avail_size;
-}
-
-static cairo_status_t
-i965_shader_setup_dst (i965_shader_t *shader)
-{
-    union i965_shader_channel *channel;
-    i965_surface_t *s, *clone;
-
-    /* We need to manual blending if we have a clip surface and an unbounded op,
-     * or an extended blend mode.
-     */
-    if (shader->need_combine ||
-	(shader->op < CAIRO_OPERATOR_SATURATE &&
-	 (shader->clip.type.fragment == FS_NONE ||
-	  _cairo_operator_bounded_by_mask (shader->op))))
-    {
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    shader->need_combine = TRUE;
-
-    s = shader->target;
-
-    /* we need to allocate a new render target and use the original as a source */
-    clone = (i965_surface_t *)
-	i965_surface_create_internal ((cairo_drm_device_t *) s->intel.drm.base.device,
-				      s->intel.drm.base.content,
-				      s->intel.drm.width,
-				      s->intel.drm.height,
-				      I965_TILING_DEFAULT,
-				      TRUE);
-    if (unlikely (clone->intel.drm.base.status))
-	return clone->intel.drm.base.status;
-
-    if (to_intel_bo (s->intel.drm.bo)->batch_write_domain)
-	i965_pipelined_flush (i965_device (s));
-
-    channel = &shader->dst;
-
-    channel->type.vertex = VS_NONE;
-    channel->type.fragment = FS_SURFACE;
-    channel->type.pattern = PATTERN_SURFACE;
-
-    /* swap buffer objects */
-    channel->base.bo = to_intel_bo (s->intel.drm.bo);
-    s->intel.drm.bo = ((cairo_drm_surface_t *) clone)->bo;
-    ((cairo_drm_surface_t *) clone)->bo = &channel->base.bo->base;
-
-    channel->base.content = s->intel.drm.base.content;
-    channel->base.format  = s->intel.drm.format;
-    channel->base.width   = s->intel.drm.width;
-    channel->base.height  = s->intel.drm.height;
-    channel->base.stride  = s->intel.drm.stride;
-
-    channel->base.filter = i965_filter (CAIRO_FILTER_NEAREST);
-    channel->base.extend = i965_extend (CAIRO_EXTEND_NONE);
-
-    cairo_matrix_init_scale (&channel->base.matrix,
-			     1. / s->intel.drm.width,
-			     1. / s->intel.drm.height);
-
-    channel->surface.surface = &clone->intel.drm.base;
-
-    s->intel.drm.base.content = clone->intel.drm.base.content;
-    s->intel.drm.format = clone->intel.drm.format;
-    assert (s->intel.drm.width == clone->intel.drm.width);
-    assert (s->intel.drm.height == clone->intel.drm.height);
-    s->intel.drm.stride = clone->intel.drm.stride;
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static inline void
-constant_add_float (i965_shader_t *shader, float v)
-{
-    shader->constants[shader->constants_size++] = v;
-}
-
-static inline void
-i965_shader_copy_channel_constants (i965_shader_t *shader,
-				    const union i965_shader_channel *channel)
-{
-    if (channel->base.constants_size) {
-	assert (shader->constants_size + channel->base.constants_size < ARRAY_LENGTH (shader->constants));
-
-	memcpy (shader->constants + shader->constants_size,
-		channel->base.constants,
-		sizeof (float) * channel->base.constants_size);
-	shader->constants_size += channel->base.constants_size;
-    }
-}
-
-static void
-i965_shader_setup_channel_constants (i965_shader_t *shader,
-				     const union i965_shader_channel *channel)
-{
-    switch (channel->type.fragment) {
-    case FS_NONE:
-    case FS_CONSTANT:
-	/* no plane equations */
-	break;
-
-    case FS_LINEAR:
-	constant_add_float (shader, channel->base.matrix.xx);
-	constant_add_float (shader, channel->base.matrix.xy);
-	constant_add_float (shader, 0);
-	constant_add_float (shader, channel->base.matrix.x0);
-	break;
-
-    case FS_RADIAL:
-    case FS_SURFACE:
-	constant_add_float (shader, channel->base.matrix.xx);
-	constant_add_float (shader, channel->base.matrix.xy);
-	constant_add_float (shader, 0);
-	constant_add_float (shader, channel->base.matrix.x0);
-
-	constant_add_float (shader, channel->base.matrix.yx);
-	constant_add_float (shader, channel->base.matrix.yy);
-	constant_add_float (shader, 0);
-	constant_add_float (shader, channel->base.matrix.y0);
-	break;
-
-    case FS_SPANS:
-    case FS_GLYPHS:
-	/* use pue from SF */
-	break;
-    }
-
-    i965_shader_copy_channel_constants (shader, channel);
-}
-
-static void
-i965_shader_setup_constants (i965_shader_t *shader)
-{
-    i965_shader_setup_channel_constants (shader, &shader->source);
-    i965_shader_setup_channel_constants (shader, &shader->mask);
-    i965_shader_setup_channel_constants (shader, &shader->clip);
-    i965_shader_setup_channel_constants (shader, &shader->dst);
-    assert (shader->constants_size < ARRAY_LENGTH (shader->constants));
-}
-
-/*
- * Highest-valued BLENDFACTOR used in i965_blend_op.
- *
- * This leaves out BRW_BLENDFACTOR_INV_DST_COLOR,
- * BRW_BLENDFACTOR_INV_CONST_{COLOR,ALPHA},
- * BRW_BLENDFACTOR_INV_SRC1_{COLOR,ALPHA}
- */
-#define BRW_BLENDFACTOR_COUNT (BRW_BLENDFACTOR_INV_DST_ALPHA + 1)
-
-static void
-i965_shader_get_blend_cntl (const i965_shader_t *shader,
-			    uint32_t *sblend, uint32_t *dblend)
-{
-    static const struct blendinfo {
-	cairo_bool_t dst_alpha;
-	cairo_bool_t src_alpha;
-	uint32_t src_blend;
-	uint32_t dst_blend;
-    } i965_blend_op[] = {
-	/* CAIRO_OPERATOR_CLEAR treat as SOURCE with transparent */
-	{0, 0, BRW_BLENDFACTOR_ONE,          BRW_BLENDFACTOR_ZERO},
-	/* CAIRO_OPERATOR_SOURCE */
-	{0, 0, BRW_BLENDFACTOR_ONE,           BRW_BLENDFACTOR_ZERO},
-	/* CAIRO_OPERATOR_OVER */
-	{0, 1, BRW_BLENDFACTOR_ONE,           BRW_BLENDFACTOR_INV_SRC_ALPHA},
-	/* CAIRO_OPERATOR_IN */
-	{1, 0, BRW_BLENDFACTOR_DST_ALPHA,     BRW_BLENDFACTOR_ZERO},
-	/* CAIRO_OPERATOR_OUT */
-	{1, 0, BRW_BLENDFACTOR_INV_DST_ALPHA, BRW_BLENDFACTOR_ZERO},
-	/* CAIRO_OPERATOR_ATOP */
-	{1, 1, BRW_BLENDFACTOR_DST_ALPHA,     BRW_BLENDFACTOR_INV_SRC_ALPHA},
-
-	/* CAIRO_OPERATOR_DEST */
-	{0, 0, BRW_BLENDFACTOR_ZERO,          BRW_BLENDFACTOR_ONE},
-	/* CAIRO_OPERATOR_DEST_OVER */
-	{1, 0, BRW_BLENDFACTOR_INV_DST_ALPHA, BRW_BLENDFACTOR_ONE},
-	/* CAIRO_OPERATOR_DEST_IN */
-	{0, 1, BRW_BLENDFACTOR_ZERO,          BRW_BLENDFACTOR_SRC_ALPHA},
-	/* CAIRO_OPERATOR_DEST_OUT */
-	{0, 1, BRW_BLENDFACTOR_ZERO,          BRW_BLENDFACTOR_INV_SRC_ALPHA},
-	/* CAIRO_OPERATOR_DEST_ATOP */
-	{1, 1, BRW_BLENDFACTOR_INV_DST_ALPHA, BRW_BLENDFACTOR_SRC_ALPHA},
-	/* CAIRO_OPERATOR_XOR */
-	{1, 1, BRW_BLENDFACTOR_INV_DST_ALPHA, BRW_BLENDFACTOR_INV_SRC_ALPHA},
-	/* CAIRO_OPERATOR_ADD */
-	{0, 0, BRW_BLENDFACTOR_ONE,           BRW_BLENDFACTOR_ONE},
-    };
-    const struct blendinfo *op = &i965_blend_op[shader->op];
-
-    *sblend = op->src_blend;
-    *dblend = op->dst_blend;
-
-    /* If there's no dst alpha channel, adjust the blend op so that we'll treat
-     * it as always 1.
-     */
-    if (shader->target->intel.drm.base.content == CAIRO_CONTENT_COLOR &&
-	op->dst_alpha)
-    {
-	if (*sblend == BRW_BLENDFACTOR_DST_ALPHA)
-	    *sblend = BRW_BLENDFACTOR_ONE;
-	else if (*sblend == BRW_BLENDFACTOR_INV_DST_ALPHA)
-	    *sblend = BRW_BLENDFACTOR_ZERO;
-    }
-}
-
-static void
-emit_wm_subpans_to_pixels (struct brw_compile *compile,
-			   int tmp)
-{
-    /* Inputs:
-     * R1.5 x/y of upper-left pixel of subspan 3
-     * R1.4 x/y of upper-left pixel of subspan 2
-     * R1.3 x/y of upper-left pixel of subspan 1
-     * R1.2 x/y of upper-left pixel of subspan 0
-     *
-     * Outputs:
-     * M1,2: u
-     * M3,4: v
-     *
-     * upper left, upper right, lower left, lower right.
-     */
-
-    /* compute pixel locations for each subspan */
-    brw_set_compression_control (compile, BRW_COMPRESSION_NONE);
-    brw_ADD (compile,
-	     brw_vec8_grf (tmp),
-	     brw_reg (BRW_GENERAL_REGISTER_FILE, 1, 4,
-		      BRW_REGISTER_TYPE_UW,
-		      BRW_VERTICAL_STRIDE_2,
-		      BRW_WIDTH_4,
-		      BRW_HORIZONTAL_STRIDE_0,
-		      BRW_SWIZZLE_NOOP,
-		      WRITEMASK_XYZW),
-	     brw_imm_vf4 (VF_ZERO, VF_ONE, VF_ZERO, VF_ONE));
-    brw_ADD (compile,
-	     brw_vec8_grf (tmp+1),
-	     brw_reg (BRW_GENERAL_REGISTER_FILE, 1, 8,
-		      BRW_REGISTER_TYPE_UW,
-		      BRW_VERTICAL_STRIDE_2,
-		      BRW_WIDTH_4,
-		      BRW_HORIZONTAL_STRIDE_0,
-		      BRW_SWIZZLE_NOOP,
-		      WRITEMASK_XYZW),
-	     brw_imm_vf4 (VF_ZERO, VF_ONE, VF_ZERO, VF_ONE));
-    brw_ADD (compile,
-	     brw_vec8_grf (tmp+2),
-	     brw_reg (BRW_GENERAL_REGISTER_FILE, 1, 5,
-		      BRW_REGISTER_TYPE_UW,
-		      BRW_VERTICAL_STRIDE_2,
-		      BRW_WIDTH_4,
-		      BRW_HORIZONTAL_STRIDE_0,
-		      BRW_SWIZZLE_NOOP,
-		      WRITEMASK_XYZW),
-	     brw_imm_vf4 (VF_ZERO, VF_ZERO, VF_ONE, VF_ONE));
-    brw_ADD (compile,
-	     brw_vec8_grf (tmp+3),
-	     brw_reg (BRW_GENERAL_REGISTER_FILE, 1, 9,
-		      BRW_REGISTER_TYPE_UW,
-		      BRW_VERTICAL_STRIDE_2,
-		      BRW_WIDTH_4,
-		      BRW_HORIZONTAL_STRIDE_0,
-		      BRW_SWIZZLE_NOOP,
-		      WRITEMASK_XYZW),
-	     brw_imm_vf4 (VF_ZERO, VF_ZERO, VF_ONE, VF_ONE));
-    brw_set_compression_control (compile, BRW_COMPRESSION_COMPRESSED);
-}
-
-static void
-emit_wm_affine (struct brw_compile *compile,
-		int tmp, int reg, int msg)
-{
-    emit_wm_subpans_to_pixels (compile, tmp);
-
-    brw_LINE (compile,
-	      brw_null_reg (),
-	      brw_vec1_grf (reg, 0),
-	      brw_vec8_grf (tmp));
-    brw_MAC (compile,
-	     brw_message_reg (msg + 1),
-	     brw_vec1_grf (reg, 1),
-	     brw_vec8_grf (tmp+2));
-
-    brw_LINE (compile,
-	      brw_null_reg (),
-	      brw_vec1_grf (reg, 4),
-	      brw_vec8_grf (tmp));
-    brw_MAC (compile,
-	     brw_message_reg (msg + 3),
-	     brw_vec1_grf (reg, 5),
-	     brw_vec8_grf (tmp+2));
-}
-
-static void
-emit_wm_glyph (struct brw_compile *compile,
-	       int tmp, int vue, int msg)
-{
-    emit_wm_subpans_to_pixels (compile, tmp);
-
-    brw_MUL (compile,
-	     brw_null_reg (),
-	     brw_vec8_grf (tmp),
-	     brw_imm_f (1./1024));
-    brw_ADD (compile,
-	     brw_message_reg (msg + 1),
-	     brw_acc_reg (),
-	     brw_vec1_grf (vue, 0));
-
-    brw_MUL (compile,
-	     brw_null_reg (),
-	     brw_vec8_grf (tmp + 2),
-	     brw_imm_f (1./1024));
-    brw_ADD (compile,
-	     brw_message_reg (msg + 3),
-	     brw_acc_reg (),
-	     brw_vec1_grf (vue, 1));
-}
-
-static void
-emit_wm_load_constant (struct brw_compile *compile,
-		       int reg,
-		       struct brw_reg *result)
-{
-    int n;
-
-    for (n = 0; n < 4; n++) {
-	result[n] = result[n+4] = brw_reg (BRW_GENERAL_REGISTER_FILE, reg, n,
-					   BRW_REGISTER_TYPE_F,
-					   BRW_VERTICAL_STRIDE_0,
-					   BRW_WIDTH_1,
-					   BRW_HORIZONTAL_STRIDE_0,
-					   BRW_SWIZZLE_XXXX,
-					   WRITEMASK_XYZW);
-    }
-}
-
-static void
-emit_wm_load_opacity (struct brw_compile *compile,
-		      int reg,
-		      struct brw_reg *result)
-{
-    result[0] = result[1] = result[2] = result[3] =
-	result[4] = result[5] = result[6] = result[7] =
-	brw_reg (BRW_GENERAL_REGISTER_FILE, reg, 0,
-		 BRW_REGISTER_TYPE_F,
-		 BRW_VERTICAL_STRIDE_0,
-		 BRW_WIDTH_1,
-		 BRW_HORIZONTAL_STRIDE_1,
-		 BRW_SWIZZLE_XXXX,
-		 WRITEMASK_XYZW);
-}
-
-static void
-emit_wm_load_linear (struct brw_compile *compile,
-		     int tmp, int reg, int msg)
-{
-    emit_wm_subpans_to_pixels (compile, tmp);
-
-    brw_LINE (compile,
-	      brw_null_reg(),
-	      brw_vec1_grf (reg, 0),
-	      brw_vec8_grf (tmp));
-    brw_MAC (compile,
-	     brw_message_reg(msg + 1),
-	     brw_vec1_grf (reg, 1),
-	     brw_vec8_grf (tmp + 2));
-}
-
-static void
-emit_wm_load_radial (struct brw_compile *compile,
-		     int reg, int msg)
-
-{
-    struct brw_reg c1x = brw_vec1_grf (reg, 0);
-    struct brw_reg c1y = brw_vec1_grf (reg, 1);
-    struct brw_reg minus_r_sq = brw_vec1_grf (reg, 3);
-    struct brw_reg cdx = brw_vec1_grf (reg, 4);
-    struct brw_reg cdy = brw_vec1_grf (reg, 5);
-    struct brw_reg neg_4a = brw_vec1_grf (reg + 1, 0);
-    struct brw_reg inv_2a = brw_vec1_grf (reg + 1, 1);
-
-    struct brw_reg tmp_x = brw_uw16_grf (30, 0);
-    struct brw_reg tmp_y = brw_uw16_grf (28, 0);
-    struct brw_reg det = brw_vec8_grf (22);
-    struct brw_reg b = brw_vec8_grf (20);
-    struct brw_reg c = brw_vec8_grf (18);
-    struct brw_reg pdx = brw_vec8_grf (16);
-    struct brw_reg pdy = brw_vec8_grf (14);
-    struct brw_reg t = brw_message_reg (msg + 1);
-
-    /* cdx = (c₂x - c₁x)
-     * cdy = (c₂y - c₁y)
-     *  dr =  r₂-r₁
-     * pdx =  px - c₁x
-     * pdy =  py - c₁y
-     *
-     * A = cdx² + cdy² - dr²
-     * B = -2·(pdx·cdx + pdy·cdy + r₁·dr)
-     * C = pdx² + pdy² - r₁²
-     *
-     * t = (-2·B ± ⎷(B² - 4·A·C)) / 2·A
-     */
-
-    brw_ADD (compile, pdx, vec8 (tmp_x), negate (c1x));
-    brw_ADD (compile, pdy, vec8 (tmp_y), negate (c1y));
-
-    brw_LINE (compile, brw_null_reg (), cdx, pdx);
-    brw_MAC (compile, b, cdy, pdy);
-
-    brw_MUL (compile, brw_null_reg (), pdx, pdx);
-    brw_MAC (compile, c, pdy, pdy);
-    brw_ADD (compile, c, c, minus_r_sq);
-
-    brw_MUL (compile, brw_null_reg (), b, b);
-    brw_MAC (compile, det, neg_4a, c);
-
-    /* XXX use rsqrt like i915?, it's faster and we need to mac anyway */
-    brw_math (compile,
-	      det,
-	      BRW_MATH_FUNCTION_SQRT,
-	      BRW_MATH_SATURATE_NONE,
-	      2,
-	      det,
-	      BRW_MATH_DATA_VECTOR,
-	      BRW_MATH_PRECISION_FULL);
-
-    /* XXX cmp, +- */
-
-    brw_ADD (compile, det, negate (det), negate (b));
-    brw_ADD (compile, det, det, negate (b));
-    brw_MUL (compile, t, det, inv_2a);
-}
-
-static int
-emit_wm_sample (struct brw_compile *compile,
-		union i965_shader_channel *channel,
-		int sampler,
-		int msg_base, int msg_len,
-		int dst,
-		struct brw_reg *result)
-{
-    int response_len, mask;
-
-    if (channel->base.content == CAIRO_CONTENT_ALPHA) {
-	mask = 0x7000;
-	response_len = 2;
-	result[0] = result[1] = result[2] = result[3] = brw_vec8_grf (dst);
-	result[4] = result[5] = result[6] = result[7] = brw_vec8_grf (dst + 1);
-    } else {
-	mask = 0;
-	response_len = 8;
-	result[0] = brw_vec8_grf (dst + 0);
-	result[1] = brw_vec8_grf (dst + 2);
-	result[2] = brw_vec8_grf (dst + 4);
-	result[3] = brw_vec8_grf (dst + 6);
-	result[4] = brw_vec8_grf (dst + 1);
-	result[5] = brw_vec8_grf (dst + 3);
-	result[6] = brw_vec8_grf (dst + 5);
-	result[7] = brw_vec8_grf (dst + 7);
-    }
-
-    brw_set_compression_control (compile, BRW_COMPRESSION_NONE);
-
-    brw_set_mask_control (compile, BRW_MASK_DISABLE);
-    brw_MOV (compile,
-	     get_element_ud (brw_vec8_grf (0), 2),
-	     brw_imm_ud (mask));
-    brw_set_mask_control (compile, BRW_MASK_ENABLE);
-
-    brw_SAMPLE (compile,
-		brw_uw16_grf (dst, 0),
-		msg_base,
-		brw_uw8_grf (0, 0),
-		sampler + 1, /* binding table */
-		sampler,
-		WRITEMASK_XYZW,
-		BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE,
-		response_len,
-		msg_len,
-		0 /* eot */);
-
-    brw_set_compression_control (compile, BRW_COMPRESSION_COMPRESSED);
-
-    return response_len;
-}
-
-#define MAX_MSG_REGISTER 16
-
-static void
-emit_wm_load_channel (struct brw_compile *compile,
-		      union i965_shader_channel *channel,
-		      int *vue,
-		      int *cue,
-		      int *msg,
-		      int *sampler,
-		      int *grf,
-		      struct brw_reg *result)
-{
-    switch (channel->type.fragment) {
-    case FS_NONE:
-	break;
-
-    case FS_CONSTANT:
-	emit_wm_load_constant (compile, *cue, result);
-	*cue += 1;
-	break;
-
-    case FS_RADIAL:
-	emit_wm_load_radial (compile, *cue, *msg);
-	*cue += 2;
-
-	if (*msg + 3 > MAX_MSG_REGISTER)
-	    *msg = 1;
-
-	*grf += emit_wm_sample (compile, channel, *sampler, *msg, 3, *grf, result);
-	*sampler += 1;
-	*msg += 3;
-	break;
-
-    case FS_LINEAR:
-	emit_wm_load_linear (compile, *grf, *cue, *msg);
-	*cue += 1;
-
-	if (*msg + 3 > MAX_MSG_REGISTER)
-	    *msg = 1;
-
-	*grf += emit_wm_sample (compile, channel, *sampler, *msg, 3, *grf, result);
-	*sampler += 1;
-	*msg += 3;
-	break;
-
-    case FS_SURFACE:
-	emit_wm_affine (compile, *grf, *cue, *msg);
-	*cue += 2;
-
-	if (*msg + 5 > MAX_MSG_REGISTER)
-	    *msg = 1;
-
-	*grf += emit_wm_sample (compile, channel, *sampler, *msg, 5, *grf, result);
-	*sampler += 1;
-	*msg += 5;
-	break;
-
-    case FS_SPANS:
-	emit_wm_load_opacity (compile, *vue, result);
-	*vue += 1;
-	break;
-
-    case FS_GLYPHS:
-	emit_wm_glyph (compile, *grf, *vue, *msg);
-	*vue += 1;
-
-	if (*msg + 5 > MAX_MSG_REGISTER)
-	    *msg = 1;
-
-	*grf += emit_wm_sample (compile, channel, *sampler, *msg, 5, *grf, result);
-	*sampler += 1;
-	*msg += 5;
-	break;
-    }
-}
-
-static unsigned long
-i965_wm_kernel_hash (const i965_shader_t *shader)
-{
-    unsigned long hash;
-
-    hash =
-	(shader->source.type.fragment & 0xff) |
-	(shader->mask.type.fragment & 0xff) << 8 |
-	(shader->clip.type.fragment & 0xff) << 16;
-    if (shader->need_combine)
-	hash |= (1u + shader->op) << 24;
-
-    return hash;
-}
-
-static void
-i965_wm_kernel_init (struct i965_wm_kernel *key,
-		     const i965_shader_t *shader)
-{
-    key->entry.hash = i965_wm_kernel_hash (shader);
-}
-
-static uint32_t
-i965_shader_const_urb_length (i965_shader_t *shader)
-{
-    const int lengths[] = { 0, 1, 1, 4, 2, 0, 0 };
-    int count = 0; /* 128-bit/16-byte increments */
-
-    count += lengths[shader->source.type.fragment];
-    count += lengths[shader->mask.type.fragment];
-    count += lengths[shader->clip.type.fragment];
-    count += lengths[shader->dst.type.fragment];
-
-    return (count + 1) / 2; /* 256-bit/32-byte increments */
-}
-
-static uint32_t
-i965_shader_pue_length (i965_shader_t *shader)
-{
-    return 1 + (shader->mask.type.vertex != VS_NONE);
-}
-
-static uint32_t
-create_wm_kernel (i965_device_t *device,
-		  i965_shader_t *shader,
-		  int *num_reg)
-{
-    struct brw_compile compile;
-    struct brw_reg source[8], mask[8], clip[8], dst[8];
-    const uint32_t *program;
-    uint32_t size;
-    int msg, cue, vue, grf, sampler;
-    int i;
-
-    struct i965_wm_kernel key, *cache;
-    cairo_status_t status;
-    uint32_t offset;
-
-    i965_wm_kernel_init (&key, shader);
-    cache = _cairo_hash_table_lookup (device->wm_kernels, &key.entry);
-    if (cache != NULL)
-	return cache->offset;
-
-    brw_compile_init (&compile, device->is_g4x);
-
-    if (key.entry.hash == FS_CONSTANT &&
-	to_intel_bo (shader->target->intel.drm.bo)->tiling)
-    {
-	struct brw_instruction *insn;
-
-	assert (i965_shader_const_urb_length (shader) == 1);
-	brw_MOV (&compile, brw_message4_reg (2), brw_vec4_grf (2, 0));
-	grf = 3;
-
-	brw_push_insn_state (&compile);
-	brw_set_mask_control (&compile, BRW_MASK_DISABLE); /* ? */
-	brw_MOV (&compile,
-		 retype (brw_message_reg (1), BRW_REGISTER_TYPE_UD),
-		 retype (brw_vec8_grf (1), BRW_REGISTER_TYPE_UD));
-	brw_pop_insn_state (&compile);
-
-	insn = brw_next_instruction (&compile, BRW_OPCODE_SEND);
-	insn->header.predicate_control = 0;
-	insn->header.compression_control = BRW_COMPRESSION_NONE;
-	insn->header.destreg__conditonalmod = 0;
-
-	brw_instruction_set_destination (insn,
-					 retype (vec16 (brw_acc_reg ()),
-						 BRW_REGISTER_TYPE_UW));
-
-	brw_instruction_set_source0 (insn,
-				     retype (brw_vec8_grf (0),
-					     BRW_REGISTER_TYPE_UW));
-
-	brw_instruction_set_dp_write_message (insn,
-					      0,
-					      BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED, /* msg_control */
-					      BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE, /* msg_type */
-					      3,
-					      1,	/* pixel scoreboard */
-					      0,
-					      TRUE);
-    }
-    else
-    {
-	msg = 1;
-	cue = 2;
-	vue = cue + i965_shader_const_urb_length (shader);
-	grf = vue + i965_shader_pue_length (shader);
-	sampler = 0;
-
-	brw_set_compression_control (&compile, BRW_COMPRESSION_COMPRESSED);
-	emit_wm_load_channel (&compile, &shader->source,
-			      &vue, &cue, &msg, &sampler, &grf,
-			      source);
-	emit_wm_load_channel (&compile, &shader->mask,
-			      &vue, &cue, &msg, &sampler, &grf,
-			      mask);
-	emit_wm_load_channel (&compile, &shader->clip,
-			      &vue, &cue, &msg, &sampler, &grf,
-			      clip);
-	emit_wm_load_channel (&compile, &shader->dst,
-			      &vue, &cue, &msg, &sampler, &grf,
-			      dst);
-	brw_set_compression_control (&compile, BRW_COMPRESSION_NONE);
-
-	if (shader->need_combine) {
-	    if (shader->mask.type.fragment != FS_NONE &&
-		shader->clip.type.fragment != FS_NONE)
-	    {
-		for (i = 0; i < 8; i++)
-		    brw_MUL (&compile, mask[i], mask[i], clip[i]);
-	    }
-
-	    /* XXX LERP ! */
-	    for (i = 0; i < 8; i++)
-		brw_MOV (&compile, brw_message_reg (2 + i), source[i]);
-	} else {
-	    if (shader->mask.type.fragment != FS_NONE) {
-		if (shader->clip.type.fragment != FS_NONE) {
-		    for (i = 0; i < 8; i++)
-			brw_MUL (&compile, mask[i], mask[i], clip[i]);
-		}
-
-		for (i = 0; i < 8; i++)
-		    brw_MUL (&compile, brw_message_reg (2 + i), source[i], mask[i]);
-	    } else {
-		if (shader->clip.type.fragment != FS_NONE) {
-		    for (i = 0; i < 8; i++)
-			brw_MUL (&compile, brw_message_reg (2 + i), source[i], clip[i]);
-		} else {
-		    for (i = 0; i < 8; i++)
-			brw_MOV (&compile, brw_message_reg (2 + i), source[i]);
-		}
-	    }
-	}
-
-	brw_push_insn_state (&compile);
-	brw_set_mask_control (&compile, BRW_MASK_DISABLE); /* ? */
-	brw_MOV (&compile,
-		 retype (brw_message_reg (1), BRW_REGISTER_TYPE_UD),
-		 retype (brw_vec8_grf (1), BRW_REGISTER_TYPE_UD));
-	brw_pop_insn_state (&compile);
-
-	brw_fb_WRITE (&compile,
-		      retype (vec16 (brw_acc_reg ()), BRW_REGISTER_TYPE_UW),
-		      0,		/* base reg */
-		      retype (brw_vec8_grf (0), BRW_REGISTER_TYPE_UW),
-		      0,		/* binding table index */
-		      2 + 8,	/* msg length */
-		      0,		/* response length */
-		      TRUE);	/* EOT */
-    }
-
-    program = brw_get_program (&compile, &size);
-    *num_reg = grf;
-
-    i965_stream_align (&device->general, 64);
-    offset = i965_stream_emit (&device->general, program, size);
-
-    cache = _cairo_freelist_alloc (&device->wm_kernel_freelist);
-    if (likely (cache != NULL)) {
-	i965_wm_kernel_init (cache, shader);
-	cache->offset = offset;
-	status = _cairo_hash_table_insert (device->wm_kernels, &cache->entry);
-	if (unlikely (status))
-	    _cairo_freelist_free (&device->wm_kernel_freelist, cache);
-    }
-
-    return offset;
-}
-
-static uint32_t
-create_sf_kernel (i965_device_t *device,
-		  i965_shader_t *shader)
-{
-    struct brw_compile compile;
-    const uint32_t *program;
-    uint32_t size;
-    int msg_len;
-
-    brw_compile_init (&compile, device->is_g4x);
-
-    switch (shader->mask.type.vertex) {
-    default:
-    case VS_NONE:
-	/* use curb plane eq in WM */
-	msg_len = 1;
-	break;
-
-    case VS_SPANS:
-	/* just a constant opacity */
-	brw_MOV (&compile,
-		 brw_message4_reg (1),
-		 brw_vec4_grf (3, 0));
-	msg_len = 2;
-	break;
-
-    case VS_GLYPHS:
-	/* an offset+sf into the glyph cache */
-	brw_MOV (&compile,
-		 brw_acc_reg (),
-		 brw_vec2_grf (3, 0));
-	brw_MAC (&compile,
-		 brw_message4_reg (1),
-		 negate (brw_vec2_grf (1, 4)),
-		 brw_imm_f (1./1024));
-	msg_len = 2;
-	break;
-    }
-
-    brw_urb_WRITE (&compile,
-		   brw_null_reg (),
-		   0,
-		   brw_vec8_grf (0), /* r0, will be copied to m0 */
-		   0,	/* allocate */
-		   1,	/* used */
-		   msg_len,
-		   0,	/* response len */
-		   1,	/* eot */
-		   1,	/* writes complete */
-		   0,	/* offset */
-		   BRW_URB_SWIZZLE_NONE);
-
-    program = brw_get_program (&compile, &size);
-
-    i965_stream_align (&device->general, 64);
-    return i965_stream_emit (&device->general, program, size);
-}
-
-static uint32_t
-i965_sf_kernel (const i965_shader_t *shader)
-{
-    return shader->mask.type.vertex;
-}
-
-static void
-i965_sf_state_init (struct i965_sf_state *key,
-		    const i965_shader_t *shader)
-{
-    key->entry.hash = i965_sf_kernel (shader);
-}
-
-cairo_bool_t
-i965_sf_state_equal (const void *A, const void *B)
-{
-    const cairo_hash_entry_t *a = A, *b = B;
-    return a->hash == b->hash;
-}
-
-/*
- * Sets up the SF state pointing at an SF kernel.
- *
- * The SF kernel does coord interp: for each attribute,
- * calculate dA/dx and dA/dy.  Hand these interpolation coefficients
- * back to SF which then hands pixels off to WM.
- */
-static uint32_t
-gen4_create_sf_state (i965_device_t *device,
-		      i965_shader_t *shader)
-{
-    struct brw_sf_unit_state *state;
-    struct i965_sf_state key, *cache;
-    cairo_status_t status;
-    uint32_t offset;
-
-    i965_sf_state_init (&key, shader);
-    if (i965_sf_state_equal (&key, &device->sf_state))
-	return device->sf_state.offset;
-
-    cache = _cairo_hash_table_lookup (device->sf_states, &key.entry);
-    if (cache != NULL) {
-	offset = cache->offset;
-	goto DONE;
-    }
-
-    offset = create_sf_kernel (device, shader);
-
-    state = i965_stream_alloc (&device->general, 32, sizeof (*state));
-    memset (state, 0, sizeof (*state));
-
-    state->thread0.grf_reg_count = BRW_GRF_BLOCKS (3);
-    assert ((offset & 63) == 0);
-    state->thread0.kernel_start_pointer = offset >> 6;
-    state->sf1.single_program_flow = 1;
-    state->thread3.urb_entry_read_length = 1; /* 1 URB per vertex */
-    state->thread3.urb_entry_read_offset = 1;
-    state->thread3.dispatch_grf_start_reg = 3;
-    state->thread4.max_threads = SF_MAX_THREADS - 1;
-    state->thread4.urb_entry_allocation_size = URB_SF_ENTRY_SIZE - 1;
-    state->thread4.nr_urb_entries = URB_SF_ENTRIES;
-    state->sf6.dest_org_vbias = 0x8;
-    state->sf6.dest_org_hbias = 0x8;
-
-    offset = i965_stream_offsetof (&device->general, state);
-
-    cache = _cairo_freelist_alloc (&device->sf_freelist);
-    if (likely (cache != NULL)) {
-	i965_sf_state_init (cache, shader);
-	cache->offset = offset;
-	status = _cairo_hash_table_insert (device->sf_states, &cache->entry);
-	if (unlikely (status))
-	    _cairo_freelist_free (&device->sf_freelist, cache);
-    }
-
-  DONE:
-    i965_sf_state_init (&device->sf_state, shader);
-    device->sf_state.offset = offset;
-
-    return offset;
-}
-
-static unsigned long
-i965_shader_sampler_hash (const i965_shader_t *shader)
-{
-    unsigned long hash = 0;
-    unsigned int offset = 0;
-
-    if (shader->source.base.bo != NULL) {
-	hash |= (shader->source.base.filter << offset) |
-	        (shader->source.base.extend << (offset + 4));
-	offset += 8;
-    }
-
-    if (shader->mask.base.bo != NULL) {
-	hash |= (shader->mask.base.filter << offset) |
-	        (shader->mask.base.extend << (offset + 4));
-	offset += 8;
-    }
-
-    if (shader->clip.base.bo != NULL) {
-	hash |= (shader->clip.base.filter << offset) |
-	        (shader->clip.base.extend << (offset + 4));
-	offset += 8;
-    }
-
-    if (shader->dst.base.bo != NULL) {
-	hash |= (shader->dst.base.filter << offset) |
-	        (shader->dst.base.extend << (offset + 4));
-	offset += 8;
-    }
-
-    return hash;
-}
-
-static void
-i965_sampler_init (struct i965_sampler *key,
-		   const i965_shader_t *shader)
-{
-    key->entry.hash = i965_shader_sampler_hash (shader);
-}
-
-static void
-emit_sampler_channel (i965_device_t *device,
-		      const union i965_shader_channel *channel,
-		      uint32_t border_color)
-{
-    struct brw_sampler_state *state;
-
-    state = i965_stream_alloc (&device->general, 0, sizeof (*state));
-    memset (state, 0, sizeof (*state));
-
-    state->ss0.lod_preclamp = 1; /* GL mode */
-
-    state->ss0.border_color_mode = BRW_BORDER_COLOR_MODE_LEGACY;
-
-    state->ss0.min_filter = channel->base.filter;
-    state->ss0.mag_filter = channel->base.filter;
-
-    state->ss1.r_wrap_mode = channel->base.extend;
-    state->ss1.s_wrap_mode = channel->base.extend;
-    state->ss1.t_wrap_mode = channel->base.extend;
-
-    assert ((border_color & 31) == 0);
-    state->ss2.border_color_pointer = border_color >> 5;
-}
-
-static uint32_t
-emit_sampler_state_table (i965_device_t *device,
-			  i965_shader_t *shader)
-{
-    struct i965_sampler key, *cache;
-    cairo_status_t status;
-    uint32_t offset;
-
-    if (device->border_color_offset == (uint32_t) -1) {
-	struct brw_sampler_legacy_border_color *border_color;
-
-	border_color = i965_stream_alloc (&device->general, 32,
-					  sizeof (*border_color));
-	border_color->color[0] = 0; /* R */
-	border_color->color[1] = 0; /* G */
-	border_color->color[2] = 0; /* B */
-	border_color->color[3] = 0; /* A */
-
-	device->border_color_offset = i965_stream_offsetof (&device->general,
-							    border_color);
-    } else {
-	i965_sampler_init (&key, shader);
-	cache = _cairo_hash_table_lookup (device->samplers, &key.entry);
-	if (cache != NULL)
-	    return cache->offset;
-    }
-
-    i965_stream_align (&device->general, 32);
-    offset = device->general.used;
-    if (shader->source.base.bo != NULL) {
-	emit_sampler_channel (device,
-			      &shader->source,
-			      device->border_color_offset);
-    }
-    if (shader->mask.base.bo != NULL) {
-	emit_sampler_channel (device,
-			      &shader->mask,
-			      device->border_color_offset);
-    }
-    if (shader->clip.base.bo != NULL) {
-	emit_sampler_channel (device,
-			      &shader->clip,
-			      device->border_color_offset);
-    }
-    if (shader->dst.base.bo != NULL) {
-	emit_sampler_channel (device,
-			      &shader->dst,
-			      device->border_color_offset);
-    }
-
-    cache = _cairo_freelist_alloc (&device->sampler_freelist);
-    if (likely (cache != NULL)) {
-	i965_sampler_init (cache, shader);
-	cache->offset = offset;
-	status = _cairo_hash_table_insert (device->samplers, &cache->entry);
-	if (unlikely (status))
-	    _cairo_freelist_free (&device->sampler_freelist, cache);
-    }
-
-    return offset;
-}
-
-static void
-i965_cc_state_init (struct i965_cc_state *key,
-		    const i965_shader_t *shader)
-{
-    uint32_t src_blend, dst_blend;
-
-    if (shader->need_combine)
-	src_blend = dst_blend = 0;
-    else
-	i965_shader_get_blend_cntl (shader, &src_blend, &dst_blend);
-
-    key->entry.hash = src_blend | ((dst_blend & 0xffff) << 16);
-}
-
-cairo_bool_t
-i965_cc_state_equal (const void *A, const void *B)
-{
-    const cairo_hash_entry_t *a = A, *b = B;
-    return a->hash == b->hash;
-}
-
-static uint32_t
-cc_state_emit (i965_device_t *device, i965_shader_t *shader)
-{
-    struct brw_cc_unit_state *state;
-    struct i965_cc_state key, *cache;
-    cairo_status_t status;
-    uint32_t src_blend, dst_blend;
-    uint32_t offset;
-
-    i965_cc_state_init (&key, shader);
-    if (i965_cc_state_equal (&key, &device->cc_state))
-	return device->cc_state.offset;
-
-    cache = _cairo_hash_table_lookup (device->cc_states, &key.entry);
-    if (cache != NULL) {
-	offset = cache->offset;
-	goto DONE;
-    }
-
-    if (shader->need_combine)
-	src_blend = dst_blend = 0;
-    else
-	i965_shader_get_blend_cntl (shader, &src_blend, &dst_blend);
-
-    state = i965_stream_alloc (&device->general, 64, sizeof (*state));
-    memset (state, 0, sizeof (*state));
-
-    /* XXX Note errata, need to flush render cache when blend_enable 0 -> 1 */
-    /* XXX 2 source blend */
-    state->cc3.blend_enable = ! shader->need_combine;
-    state->cc5.ia_blend_function = BRW_BLENDFUNCTION_ADD;
-    state->cc5.ia_src_blend_factor  = src_blend;
-    state->cc5.ia_dest_blend_factor = dst_blend;
-    state->cc6.blend_function = BRW_BLENDFUNCTION_ADD;
-    state->cc6.clamp_post_alpha_blend = 1;
-    state->cc6.clamp_pre_alpha_blend  = 1;
-    state->cc6.src_blend_factor  = src_blend;
-    state->cc6.dest_blend_factor = dst_blend;
-
-    offset = i965_stream_offsetof (&device->general, state);
-
-    cache = _cairo_freelist_alloc (&device->cc_freelist);
-    if (likely (cache != NULL)) {
-	i965_cc_state_init (cache, shader);
-	cache->offset = offset;
-	status = _cairo_hash_table_insert (device->cc_states, &cache->entry);
-	if (unlikely (status))
-	    _cairo_freelist_free (&device->cc_freelist, cache);
-    }
-
-  DONE:
-    i965_cc_state_init (&device->cc_state, shader);
-    device->cc_state.offset = offset;
-
-    return offset;
-}
-
-static void
-i965_wm_state_init (struct i965_wm_state *key,
-		    const i965_shader_t *shader)
-{
-    key->kernel = i965_wm_kernel_hash (shader);
-    key->sampler = i965_shader_sampler_hash (shader);
-
-    key->entry.hash = key->kernel ^ ((key->sampler) << 16 | (key->sampler >> 16));
-}
-
-cairo_bool_t
-i965_wm_state_equal (const void *A, const void *B)
-{
-    const struct i965_wm_state *a = A, *b = B;
-
-    if (a->entry.hash != b->entry.hash)
-	return FALSE;
-
-    return a->kernel == b->kernel && a->sampler == b->sampler;
-}
-
-static int
-i965_shader_binding_table_count (i965_shader_t *shader)
-{
-    int count;
-
-    count = 1;
-    if (shader->source.type.fragment != FS_CONSTANT)
-	count++;
-    switch (shader->mask.type.fragment) {
-    case FS_NONE:
-    case FS_CONSTANT:
-    case FS_SPANS:
-	break;
-    case FS_LINEAR:
-    case FS_RADIAL:
-    case FS_SURFACE:
-    case FS_GLYPHS:
-	count++;
-    }
-    if (shader->clip.type.fragment == FS_SURFACE)
-	count++;
-    if (shader->dst.type.fragment == FS_SURFACE)
-	count++;
-
-    return count;
-}
-
-static uint32_t
-gen4_create_wm_state (i965_device_t *device,
-		      i965_shader_t *shader)
-{
-    struct brw_wm_unit_state *state;
-    uint32_t sampler;
-    uint32_t kernel;
-
-    struct i965_wm_state key, *cache;
-    cairo_status_t status;
-    int num_reg;
-
-    i965_wm_state_init (&key, shader);
-    if (i965_wm_state_equal (&key, &device->wm_state))
-	return device->wm_state.offset;
-
-    cache = _cairo_hash_table_lookup (device->wm_states, &key.entry);
-    if (cache != NULL) {
-	device->wm_state = *cache;
-	return cache->offset;
-    }
-
-    kernel = create_wm_kernel (device, shader, &num_reg);
-    sampler = emit_sampler_state_table (device, shader);
-
-    state = i965_stream_alloc (&device->general, 32, sizeof (*state));
-    memset (state, 0, sizeof (*state));
-    state->thread0.grf_reg_count = BRW_GRF_BLOCKS (num_reg);
-    assert ((kernel & 63) == 0);
-    state->thread0.kernel_start_pointer = kernel >> 6;
-
-    state->thread3.dispatch_grf_start_reg = 2;
-
-    state->wm4.sampler_count = 1; /* 1-4 samplers used */
-    assert ((sampler & 31) == 0);
-    state->wm4.sampler_state_pointer = sampler >> 5;
-    if (device->is_g4x)
-	state->wm5.max_threads = PS_MAX_THREADS_CTG - 1;
-    else
-	state->wm5.max_threads = PS_MAX_THREADS_BRW - 1;
-    state->wm5.thread_dispatch_enable = 1;
-
-    if (device->is_g4x) {
-	/* XXX contiguous 32 pixel dispatch */
-    }
-    state->wm5.enable_16_pix = 1;
-    /* 8 pixel dispatch and friends */
-    //state->wm5.early_depth_test = 1;
-
-    state->thread1.binding_table_entry_count = i965_shader_binding_table_count(shader);
-    state->thread3.urb_entry_read_length = i965_shader_pue_length (shader);
-    state->thread3.const_urb_entry_read_length = i965_shader_const_urb_length (shader);
-
-    key.offset = i965_stream_offsetof (&device->general, state);
-
-    cache = _cairo_freelist_alloc (&device->wm_state_freelist);
-    if (likely (cache != NULL)) {
-	*cache = key;
-	status = _cairo_hash_table_insert (device->wm_states, &cache->entry);
-	if (unlikely (status))
-	    _cairo_freelist_free (&device->wm_state_freelist, cache);
-    }
-
-    device->wm_state = key;
-    return key.offset;
-}
-
-static uint32_t
-vs_unit_state_emit (i965_device_t *device)
-{
-    if (device->vs_offset == (uint32_t) -1) {
-	struct brw_vs_unit_state *state;
-
-	/* Set up the vertex shader to be disabled (passthrough) */
-	state = i965_stream_alloc (&device->general, 32, sizeof (*state));
-	memset (state, 0, sizeof (*state));
-
-	state->thread4.nr_urb_entries = URB_VS_ENTRIES;
-	state->thread4.urb_entry_allocation_size = URB_VS_ENTRY_SIZE - 1;
-	state->vs6.vert_cache_disable = 1;
-
-	device->vs_offset = i965_stream_offsetof (&device->general, state);
-    }
-
-    return device->vs_offset;
-}
-
-static uint32_t
-i965_get_card_format (cairo_format_t format)
-{
-    switch (format) {
-    case CAIRO_FORMAT_ARGB32:
-	return BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
-    case CAIRO_FORMAT_RGB24:
-	return BRW_SURFACEFORMAT_B8G8R8X8_UNORM;
-    case CAIRO_FORMAT_RGB16_565:
-	return BRW_SURFACEFORMAT_B5G6R5_UNORM;
-    case CAIRO_FORMAT_A8:
-	return BRW_SURFACEFORMAT_A8_UNORM;
-    case CAIRO_FORMAT_A1:
-    case CAIRO_FORMAT_INVALID:
-    default:
-	ASSERT_NOT_REACHED;
-	return 0;
-    }
-}
-
-static uint32_t
-i965_get_dest_format (cairo_format_t format)
-{
-    switch (format) {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB24:
-        return BRW_SURFACEFORMAT_B8G8R8A8_UNORM;
-    case CAIRO_FORMAT_RGB16_565:
-        return BRW_SURFACEFORMAT_B5G6R5_UNORM;
-    case CAIRO_FORMAT_A8:
-        return BRW_SURFACEFORMAT_A8_UNORM;
-    case CAIRO_FORMAT_A1:
-    case CAIRO_FORMAT_INVALID:
-    default:
-	ASSERT_NOT_REACHED;
-	return 0;
-    }
-}
-
-/* XXX silly inline due to compiler bug... */
-static inline void
-i965_stream_add_pending_relocation (i965_stream_t *stream,
-				    uint32_t target_offset,
-				    uint32_t read_domains,
-				    uint32_t write_domain,
-				    uint32_t delta)
-{
-    int n;
-
-    n = stream->num_pending_relocations++;
-    assert (n < stream->max_pending_relocations);
-
-    stream->pending_relocations[n].offset = target_offset;
-    stream->pending_relocations[n].read_domains = read_domains;
-    stream->pending_relocations[n].write_domain = write_domain;
-    stream->pending_relocations[n].delta = delta;
-}
-
-static uint32_t
-emit_surface_state (i965_device_t *device,
-		    cairo_bool_t is_target,
-		    intel_bo_t *bo,
-		    cairo_format_t format,
-		    int width, int height, int stride,
-		    int type)
-{
-    struct brw_surface_state *state;
-    uint32_t write_domain, read_domains;
-    uint32_t offset;
-
-    state = i965_stream_alloc (&device->surface, 32, sizeof (*state));
-    memset (state, 0, sizeof (*state));
-
-    state->ss0.surface_type = type;
-    if (is_target)
-	state->ss0.surface_format = i965_get_dest_format (format);
-    else
-	state->ss0.surface_format = i965_get_card_format (format);
-
-    state->ss0.data_return_format = BRW_SURFACERETURNFORMAT_FLOAT32;
-    state->ss0.color_blend = 1;
-    if (is_target && device->is_g4x)
-	state->ss0.render_cache_read_mode = 1;
-
-    state->ss1.base_addr = bo->offset;
-
-    state->ss2.height = height - 1;
-    state->ss2.width  = width  - 1;
-    state->ss3.pitch  = stride - 1;
-    state->ss3.tile_walk = bo->tiling == I915_TILING_Y;
-    state->ss3.tiled_surface = bo->tiling != I915_TILING_NONE;
-
-    if (is_target) {
-	read_domains = I915_GEM_DOMAIN_RENDER;
-	write_domain = I915_GEM_DOMAIN_RENDER;
-    } else {
-	read_domains = I915_GEM_DOMAIN_SAMPLER;
-	write_domain = 0;
-    }
-
-    offset = i965_stream_offsetof (&device->surface, state);
-    i965_emit_relocation (device, &device->surface,
-			  bo, 0,
-			  read_domains, write_domain,
-			  offset + offsetof (struct brw_surface_state, ss1.base_addr));
-    return offset;
-}
-
-static uint32_t
-emit_surface_state_for_shader (i965_device_t *device,
-			       const union i965_shader_channel *channel)
-{
-    int type = BRW_SURFACE_2D;
-
-    assert (channel->type.fragment != FS_NONE);
-    assert (channel->type.fragment != FS_CONSTANT);
-
-    if (channel->type.fragment != FS_SURFACE)
-	type = BRW_SURFACE_1D;
-
-    return emit_surface_state (device, FALSE,
-			       channel->base.bo,
-			       channel->base.format,
-			       channel->base.width,
-			       channel->base.height,
-			       channel->base.stride,
-			       type);
-}
-
-cairo_bool_t
-i965_wm_binding_equal (const void *A,
-		       const void *B)
-{
-    const struct i965_wm_binding *a = A, *b = B;
-
-    if (a->entry.hash != b->entry.hash)
-	return FALSE;
-
-    if (a->size != b->size)
-	return FALSE;
-
-    return memcmp (a->table, b->table, sizeof (uint32_t) * a->size) == 0;
-}
-
-static void
-i965_wm_binding_init (struct i965_wm_binding *state,
-		      const uint32_t *table,
-		      int size)
-{
-    int n;
-
-    state->entry.hash = size;
-    state->size = size;
-
-    for (n = 0; n < size; n++) {
-	state->table[n] = table[n];
-	state->entry.hash ^= (table[n] << (8 * n)) |
-	                     (table[n] >> (32 - (8*n)));
-    }
-}
-
-static uint32_t
-emit_binding_table (i965_device_t *device,
-		    i965_shader_t *shader)
-{
-    intel_bo_t *bo;
-    struct i965_wm_binding key, *cache;
-    uint32_t *table;
-    int n = 0;
-
-    table = i965_stream_alloc (&device->surface, 32, 5 * sizeof (uint32_t));
-    if (shader->target->stream != device->surface.serial) {
-	shader->target->stream = device->surface.serial;
-	shader->target->offset = emit_surface_state (device,
-						     TRUE,
-						     to_intel_bo (shader->target->intel.drm.bo),
-						     shader->target->intel.drm.format,
-						     shader->target->intel.drm.width,
-						     shader->target->intel.drm.height,
-						     shader->target->intel.drm.stride,
-						     BRW_SURFACE_2D);
-    }
-    table[n++] = shader->target->offset;
-
-    bo = shader->source.base.bo;
-    if (bo != NULL) {
-	if (bo->opaque0 != device->surface.serial) {
-	    bo->opaque0 = device->surface.serial;
-	    bo->opaque1 = emit_surface_state_for_shader (device, &shader->source);
-	}
-	table[n++] = bo->opaque1;
-    }
-
-    bo = shader->mask.base.bo;
-    if (bo != NULL) {
-	if (bo->opaque0 != device->surface.serial) {
-	    bo->opaque0 = device->surface.serial;
-	    bo->opaque1 = emit_surface_state_for_shader (device, &shader->mask);
-	}
-	table[n++] = bo->opaque1;
-    }
-
-    bo = shader->clip.base.bo;
-    if (bo != NULL) {
-	if (bo->opaque0 != device->surface.serial) {
-	    bo->opaque0 = device->surface.serial;
-	    bo->opaque1 = emit_surface_state_for_shader (device, &shader->clip);
-	}
-	table[n++] = bo->opaque1;
-    }
-
-    bo = shader->dst.base.bo;
-    if (bo != NULL) {
-	if (bo->opaque0 != device->surface.serial) {
-	    bo->opaque0 = device->surface.serial;
-	    bo->opaque1 = emit_surface_state_for_shader (device, &shader->dst);
-	}
-	table[n++] = bo->opaque1;
-    }
-
-    i965_wm_binding_init (&key, table, n);
-    key.offset = i965_stream_offsetof (&device->surface, table);
-
-    if (i965_wm_binding_equal (&key, &device->wm_binding)) {
-	device->surface.used = key.offset;
-	return device->wm_binding.offset;
-    }
-
-    cache = _cairo_hash_table_lookup (device->wm_bindings, &key.entry);
-    if (cache != NULL) {
-	device->surface.used = key.offset;
-	key.offset = cache->offset;
-    }
-
-    device->wm_binding = key;
-    return key.offset;
-}
-
-static void
-i965_emit_invariants (i965_device_t *device)
-{
-    OUT_BATCH (BRW_CS_URB_STATE | 0);
-    OUT_BATCH (((URB_CS_ENTRY_SIZE-1) << 4) | (URB_CS_ENTRIES << 0));
-}
-
-static void
-i965_emit_urb_fences (i965_device_t *device)
-{
-    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 (device->have_urb_fences)
-	return;
-
-    /* URB fence */
-    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;
-
-    /* erratum: URB_FENCE must not cross a 64-byte cache-line */
-    while ((device->batch.used & 63) > 64-12)
-	OUT_BATCH (MI_NOOP);
-    OUT_BATCH (BRW_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));
-
-    device->have_urb_fences = TRUE;
-    device->constants_size = 0;
-}
-
-static void
-i965_emit_base (i965_device_t *device)
-{
-    OUT_BATCH (BRW_STATE_BASE_ADDRESS | 4);
-    if (likely (device->general.num_pending_relocations == 0)) {
-	i965_stream_add_pending_relocation (&device->general,
-					    device->batch.used,
-					    I915_GEM_DOMAIN_INSTRUCTION, 0,
-					    BASE_ADDRESS_MODIFY);
-    }
-    OUT_BATCH (0); /* pending relocation */
-
-    if (likely (device->surface.num_pending_relocations == 0)) {
-	i965_stream_add_pending_relocation (&device->surface,
-					    device->batch.used,
-					    I915_GEM_DOMAIN_INSTRUCTION, 0,
-					    BASE_ADDRESS_MODIFY);
-    }
-    OUT_BATCH (0); /* pending relocation */
-
-    OUT_BATCH (0 | BASE_ADDRESS_MODIFY);
-    /* general state max addr, disabled */
-    OUT_BATCH (0x10000000 | BASE_ADDRESS_MODIFY);
-    /* media object state max addr, disabled */
-    OUT_BATCH (0x10000000 | BASE_ADDRESS_MODIFY);
-}
-
-static void
-i965_emit_vertex_element (i965_device_t *device,
-			  i965_shader_t *shader)
-{
-    uint32_t offset;
-    uint32_t type;
-    int nelem;
-
-    type = 0;
-    nelem = 1;
-    if (shader->mask.type.vertex == VS_SPANS ||
-	shader->mask.type.vertex == VS_GLYPHS)
-    {
-	type = shader->mask.type.vertex;
-	nelem++;
-    }
-
-    if (type == device->vertex_type)
-	return;
-    device->vertex_type = type;
-
-    offset = 0;
-
-    OUT_BATCH (BRW_3DSTATE_VERTEX_ELEMENTS | ((2 * nelem) - 1));
-    OUT_BATCH ((0 << VE0_VERTEX_BUFFER_INDEX_SHIFT) |
-	       VE0_VALID |
-	       (BRW_SURFACEFORMAT_R32G32_FLOAT	<< VE0_FORMAT_SHIFT) |
-	       (offset				<< VE0_OFFSET_SHIFT));
-    OUT_BATCH ((BRW_VFCOMPONENT_STORE_SRC	<< VE1_VFCOMPONENT_0_SHIFT) |
-	       (BRW_VFCOMPONENT_STORE_SRC	<< VE1_VFCOMPONENT_1_SHIFT) |
-	       (BRW_VFCOMPONENT_STORE_0		<< VE1_VFCOMPONENT_2_SHIFT) |
-	       (BRW_VFCOMPONENT_STORE_1_FLT	<< VE1_VFCOMPONENT_3_SHIFT) |
-	       (4 << VE1_DESTINATION_ELEMENT_OFFSET_SHIFT));
-    offset += 8;
-
-    assert (shader->source.type.vertex == VS_NONE);
-    switch (shader->mask.type.vertex) {
-    default:
-    case VS_NONE:
-	break;
-
-    case VS_SPANS:
-	OUT_BATCH((0 << VE0_VERTEX_BUFFER_INDEX_SHIFT) |
-		  VE0_VALID |
-		  (BRW_SURFACEFORMAT_R32_FLOAT << VE0_FORMAT_SHIFT) |
-		  (offset			<< VE0_OFFSET_SHIFT));
-	OUT_BATCH((BRW_VFCOMPONENT_STORE_SRC	<< VE1_VFCOMPONENT_0_SHIFT) |
-		  (BRW_VFCOMPONENT_NOSTORE	<< VE1_VFCOMPONENT_1_SHIFT) |
-		  (BRW_VFCOMPONENT_NOSTORE	<< VE1_VFCOMPONENT_2_SHIFT) |
-		  (BRW_VFCOMPONENT_NOSTORE	<< VE1_VFCOMPONENT_3_SHIFT) |
-		  (8 << VE1_DESTINATION_ELEMENT_OFFSET_SHIFT));
-
-	offset += 4;
-	break;
-
-    case VS_GLYPHS:
-	OUT_BATCH((0 << VE0_VERTEX_BUFFER_INDEX_SHIFT) |
-		  VE0_VALID |
-		  (BRW_SURFACEFORMAT_R16G16_FLOAT << VE0_FORMAT_SHIFT) |
-		  (offset			<< VE0_OFFSET_SHIFT));
-	OUT_BATCH((BRW_VFCOMPONENT_STORE_SRC	<< VE1_VFCOMPONENT_0_SHIFT) |
-		  (BRW_VFCOMPONENT_STORE_SRC	<< VE1_VFCOMPONENT_1_SHIFT) |
-		  (BRW_VFCOMPONENT_NOSTORE	<< VE1_VFCOMPONENT_2_SHIFT) |
-		  (BRW_VFCOMPONENT_NOSTORE	<< VE1_VFCOMPONENT_3_SHIFT) |
-		  (8 << VE1_DESTINATION_ELEMENT_OFFSET_SHIFT));
-
-	offset += 4;
-	break;
-    }
-    assert (shader->clip.type.vertex == VS_NONE);
-    assert (shader->dst.type.vertex == VS_NONE);
-
-    device->vertex_size = offset;
-    i965_stream_align (&device->vertex, device->vertex_size);
-    device->vertex.committed = device->vertex.used;
-
-    device->rectangle_size = 3 * offset;
-}
-
-static cairo_bool_t
-i965_shader_needs_surface_update (const i965_shader_t *shader,
-				  const i965_device_t *device)
-{
-    return device->target != shader->target || shader->target->stream == 0 ||
-	(shader->source.base.bo != NULL && device->source != shader->source.base.bo) ||
-	(shader->mask.base.bo != NULL && device->mask != shader->mask.base.bo) ||
-	(shader->clip.base.bo != NULL && device->clip != shader->clip.base.bo);
-}
-
-static cairo_bool_t
-i965_shader_needs_constants_update (const i965_shader_t *shader,
-				    const i965_device_t *device)
-{
-    if (shader->constants_size == 0)
-	return FALSE;
-
-    if (device->constants_size != shader->constants_size)
-	return TRUE;
-
-    return memcmp (device->constants,
-		   shader->constants,
-		   sizeof (float) * shader->constants_size);
-}
-
-static cairo_bool_t
-i965_shader_needs_state_update (const i965_shader_t *shader,
-				const i965_device_t *device)
-{
-    union {
-	struct i965_sf_state sf;
-	struct i965_wm_state wm;
-	struct i965_cc_state cc;
-    } state;
-
-    i965_sf_state_init (&state.sf, shader);
-    if (! i965_sf_state_equal (&state.sf, &device->sf_state))
-	return TRUE;
-
-    i965_wm_state_init (&state.wm, shader);
-    if (! i965_wm_state_equal (&state.wm, &device->wm_state))
-	return TRUE;
-
-    i965_cc_state_init (&state.cc, shader);
-    if (! i965_cc_state_equal (&state.cc, &device->cc_state))
-	return TRUE;
-
-    return FALSE;
-}
-
-static void
-i965_emit_composite (i965_device_t *device,
-		     i965_shader_t *shader)
-{
-    uint32_t draw_rectangle;
-
-    if (i965_shader_needs_surface_update (shader, device)) {
-	uint32_t offset;
-
-	offset = emit_binding_table (device, shader);
-
-	/* Only the PS uses the binding table */
-	OUT_BATCH (BRW_3DSTATE_BINDING_TABLE_POINTERS | 4);
-	OUT_BATCH (0); /* vs */
-	OUT_BATCH (0); /* gs */
-	OUT_BATCH (0); /* clip */
-	OUT_BATCH (0); /* sf */
-	OUT_BATCH (offset);
-
-	device->target = shader->target;
-	device->source = shader->source.base.bo;
-	device->mask = shader->mask.base.bo;
-	device->clip = shader->clip.base.bo;
-    }
-
-    /* The drawing rectangle clipping is always on.  Set it to values that
-     * shouldn't do any clipping.
-     */
-    draw_rectangle = DRAW_YMAX (shader->target->intel.drm.height) |
-	             DRAW_XMAX (shader->target->intel.drm.width);
-    if (draw_rectangle != device->draw_rectangle) {
-	OUT_BATCH (BRW_3DSTATE_DRAWING_RECTANGLE | 2);
-	OUT_BATCH (0x00000000);	/* ymin, xmin */
-	OUT_BATCH (draw_rectangle);
-	OUT_BATCH (0x00000000);	/* yorigin, xorigin */
-	device->draw_rectangle = draw_rectangle;
-    }
-
-    /* skip the depth buffer */
-    /* skip the polygon stipple */
-    /* skip the polygon stipple offset */
-    /* skip the line stipple */
-
-    /* Set the pointers to the 3d pipeline state */
-    if (i965_shader_needs_state_update (shader, device)) {
-	OUT_BATCH (BRW_3DSTATE_PIPELINED_POINTERS | 5);
-	OUT_BATCH (vs_unit_state_emit (device));
-	OUT_BATCH (BRW_GS_DISABLE);
-	OUT_BATCH (BRW_CLIP_DISABLE);
-	OUT_BATCH (gen4_create_sf_state (device, shader));
-	OUT_BATCH (gen4_create_wm_state (device, shader));
-	OUT_BATCH (cc_state_emit (device, shader));
-
-	/* Once the units are initialized, we need to setup the fences */
-	i965_emit_urb_fences (device);
-    }
-
-    if (i965_shader_needs_constants_update (shader, device)) {
-	uint32_t size = (sizeof (float) * shader->constants_size + 63) & -64;
-
-	/* XXX reuse clear/black/white
-	 * ht!
-	*/
-
-	/* XXX CONSTANT_BUFFER Address Offset Disable? INSTPM? */
-
-	assert (size <= 64 * URB_CS_ENTRY_SIZE);
-	assert (((sizeof (float) * shader->constants_size + 31) & -32) == 32 * i965_shader_const_urb_length (shader));
-
-	device->constants = i965_stream_alloc (&device->surface, 64, size);
-	memcpy (device->constants, shader->constants, size);
-	device->constants_size = shader->constants_size;
-
-	OUT_BATCH (BRW_CONSTANT_BUFFER | (1 << 8));
-	OUT_BATCH (i965_stream_offsetof (&device->surface, device->constants) + size / 64 - 1);
-    }
-
-    i965_emit_vertex_element (device, shader);
-}
-
-void
-i965_flush_vertices (i965_device_t *device)
-{
-    int vertex_count, vertex_start;
-
-    if (device->vertex.used == device->vertex.committed)
-	return;
-
-    assert (device->vertex.used > device->vertex.committed);
-
-    vertex_start = device->vertex.committed / device->vertex_size;
-    vertex_count =
-	(device->vertex.used - device->vertex.committed) / device->vertex_size;
-
-    assert (vertex_count);
-
-    if (device->vertex_size != device->last_vertex_size) {
-	i965_stream_add_pending_relocation (&device->vertex,
-					    device->batch.used + 8,
-					    I915_GEM_DOMAIN_VERTEX, 0,
-					    0);
-
-	OUT_BATCH (BRW_3DSTATE_VERTEX_BUFFERS | 3);
-	OUT_BATCH ((0 << VB0_BUFFER_INDEX_SHIFT) |
-		   VB0_VERTEXDATA |
-		   (device->vertex_size << VB0_BUFFER_PITCH_SHIFT));
-	OUT_BATCH (0); /* pending relocation */
-	OUT_BATCH (0);
-	OUT_BATCH (0);
-	device->last_vertex_size = device->vertex_size;
-    }
-
-    OUT_BATCH (BRW_3DPRIMITIVE |
-	       BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL |
-	       (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) |
-	       (0 << 9) |
-	       4);
-    OUT_BATCH (vertex_count);  /* vertex count per instance */
-    OUT_BATCH (vertex_start);  /* start vertex offset */
-    OUT_BATCH (1); /* single instance */
-    OUT_BATCH (0);
-    OUT_BATCH (0);
-
-    device->vertex.committed = device->vertex.used;
-}
-
-void
-i965_finish_vertices (i965_device_t *device)
-{
-    cairo_status_t status;
-
-    i965_flush_vertices (device);
-
-    i965_stream_commit (device, &device->vertex);
-
-    if (! i965_shader_check_aperture (device->shader, device)) {
-	status = i965_device_flush (device);
-	if (unlikely (status))
-	    longjmp (device->shader->unwind, status);
-
-	status = i965_shader_commit (device->shader, device);
-	assert (status == CAIRO_STATUS_SUCCESS);
-    }
-
-    device->last_vertex_size = 0;
-}
-
-static cairo_bool_t
-i965_shader_needs_update (const i965_shader_t *shader,
-			  const i965_device_t *device)
-{
-    if (i965_shader_needs_surface_update (shader, device))
-	return TRUE;
-
-    if (i965_shader_needs_constants_update (shader, device))
-	return TRUE;
-
-    return i965_shader_needs_state_update (shader, device);
-}
-
-static void
-i965_shader_reduce (i965_shader_t *shader,
-		    const i965_device_t *device)
-{
-    if (shader->op == CAIRO_OPERATOR_OVER &&
-	(i965_wm_kernel_hash (shader) & ~0xff) == 0 &&
-	(shader->source.base.content & CAIRO_CONTENT_ALPHA) == 0)
-    {
-	shader->op = CAIRO_OPERATOR_SOURCE;
-    }
-}
-
-cairo_status_t
-i965_shader_commit (i965_shader_t *shader,
-		    i965_device_t *device)
-{
-    cairo_status_t status;
-
-    if (! shader->committed) {
-	device->shader = shader;
-
-	status = i965_shader_setup_dst (shader);
-	if (unlikely (status))
-	    return status;
-
-	i965_shader_setup_constants (shader);
-	i965_shader_reduce (shader, device);
-
-	if ((status = setjmp (shader->unwind)))
-	    return status;
-
-	shader->committed = TRUE;
-    }
-
-    if (! i965_shader_needs_update (shader, device))
-	return CAIRO_STATUS_SUCCESS;
-
-    /* XXX too many guestimates about likely maximum sizes */
-recheck:
-    if (device->batch.used + 128 > device->batch.size ||
-	! i965_shader_check_aperture (shader, device))
-    {
-	status = i965_device_flush (device);
-	if (unlikely (status))
-	    longjmp (shader->unwind, status);
-    }
-
-    i965_flush_vertices (device);
-
-    if (unlikely (device->surface.used + 128 > device->surface.size ||
-		  device->surface.num_relocations + 4 > device->surface.max_relocations))
-    {
-	i965_stream_commit (device, &device->surface);
-	goto recheck;
-    }
-
-    if (unlikely (device->general.used + 512 > device->general.size)) {
-	i965_stream_commit (device, &device->general);
-	i965_general_state_reset (device);
-	goto recheck;
-    }
-
-    if (unlikely (device->batch.used == 0))
-	i965_emit_invariants (device);
-
-    if (unlikely (device->surface.num_pending_relocations == 0 ||
-		  device->general.num_pending_relocations == 0))
-    {
-	i965_emit_base (device);
-    }
-
-    i965_emit_composite (device, shader);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-void
-i965_clipped_vertices (i965_device_t *device,
-		       struct i965_vbo *vbo,
-		       cairo_region_t *clip_region)
-{
-    int i, num_rectangles, size;
-    cairo_status_t status;
-
-    if (vbo->count == 0)
-	return;
-
-    num_rectangles = cairo_region_num_rectangles (clip_region);
-    assert (num_rectangles);
-
-    if (vbo->next ||
-	vbo->count * device->vertex_size + device->vertex.used > device->vertex.size)
-    {
-	i965_finish_vertices (device);
-
-	size = device->rectangle_size;
-	do {
-	    for (i = 0; i < num_rectangles; i++) {
-		cairo_rectangle_int_t rect;
-
-		cairo_region_get_rectangle (clip_region, i, &rect);
-
-		if (unlikely (device->vertex.used + size > device->vertex.size ||
-			      device->batch.used + 64 > device->batch.size ||
-			      ! i965_shader_check_aperture (device->shader, device)))
-		{
-		    status = i965_device_flush (device);
-		    if (unlikely (status))
-			longjmp (device->shader->unwind, status);
-
-		    status = i965_shader_commit (device->shader, device);
-		    assert (status == CAIRO_STATUS_SUCCESS);
-		}
-
-		i965_emit_relocation (device, &device->batch,
-				      vbo->bo, 0,
-				      I915_GEM_DOMAIN_VERTEX, 0,
-				      device->batch.used + 8);
-
-		OUT_BATCH (BRW_3DSTATE_VERTEX_BUFFERS | 3);
-		OUT_BATCH ((0 << VB0_BUFFER_INDEX_SHIFT) |
-			   VB0_VERTEXDATA |
-			   (device->vertex_size << VB0_BUFFER_PITCH_SHIFT));
-		OUT_BATCH (vbo->bo->offset);
-		OUT_BATCH (0);
-		OUT_BATCH (0);
-
-		/* XXX scissor? */
-		OUT_BATCH (BRW_3DSTATE_DRAWING_RECTANGLE | 2);
-		OUT_BATCH (DRAW_YMIN (rect.y) | DRAW_XMIN (rect.x));
-		OUT_BATCH (DRAW_YMAX (rect.y + rect.height) |
-			   DRAW_XMAX (rect.x + rect.width));
-		OUT_BATCH (0x00000000);	/* yorigin, xorigin */
-
-		OUT_BATCH (BRW_3DPRIMITIVE |
-			   BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL |
-			   (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) |
-			   (0 << 9) |
-			   4);
-		OUT_BATCH (vbo->count);  /* vertex count per instance */
-		OUT_BATCH (0);  /* start vertex offset */
-		OUT_BATCH (1); /* single instance */
-		OUT_BATCH (0);
-		OUT_BATCH (0);
-	    }
-	} while ((vbo = vbo->next) != NULL);
-	assert (device->last_vertex_size == 0);
-    } else {
-	int vertex_start, vertex_count;
-	void *ptr;
-
-	vertex_start = device->vertex.committed / device->vertex_size;
-	vertex_count = vbo->count;
-
-	size = vertex_count * device->vertex_size;
-	ptr = intel_bo_map (&device->intel, vbo->bo);
-	memcpy (device->vertex.data + device->vertex.used, ptr, size);
-	device->vertex.committed = device->vertex.used += size;
-
-	for (i = 0; i < num_rectangles; i++) {
-	    cairo_rectangle_int_t rect;
-
-	    cairo_region_get_rectangle (clip_region, i, &rect);
-
-	    /* XXX scissor? */
-	    OUT_BATCH (BRW_3DSTATE_DRAWING_RECTANGLE | 2);
-	    OUT_BATCH (DRAW_YMIN (rect.y) | DRAW_XMIN (rect.x));
-	    OUT_BATCH (DRAW_YMAX (rect.y + rect.height) |
-		       DRAW_XMAX (rect.x + rect.width));
-	    OUT_BATCH (0x00000000);	/* yorigin, xorigin */
-
-	    OUT_BATCH (BRW_3DPRIMITIVE |
-		       BRW_3DPRIMITIVE_VERTEX_SEQUENTIAL |
-		       (_3DPRIM_RECTLIST << BRW_3DPRIMITIVE_TOPOLOGY_SHIFT) |
-		       (0 << 9) |
-		       4);
-	    OUT_BATCH (vertex_count);  /* vertex count per instance */
-	    OUT_BATCH (vertex_start);  /* start vertex offset */
-	    OUT_BATCH (1); /* single instance */
-	    OUT_BATCH (0);
-	    OUT_BATCH (0);
-	}
-    }
-
-    device->draw_rectangle = 0;
-}
diff --git a/src/drm/cairo-drm-i965-spans.c b/src/drm/cairo-drm-i965-spans.c
deleted file mode 100644
index 4d1f491fa..000000000
--- a/src/drm/cairo-drm-i965-spans.c
+++ /dev/null
@@ -1,407 +0,0 @@
-/* cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Red Hat, Inc.
- *
- * Contributor(s):
- *	Chris Wilson <chris at chris-wilson.co.uk>
- */
-
-#include "cairoint.h"
-
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-boxes-private.h"
-#include "cairo-error-private.h"
-#include "cairo-drm-i965-private.h"
-
-/* Operates in either immediate or retained mode.
- * When given a clip region we record the sequence of vbo and then
- * replay them for each clip rectangle, otherwise we simply emit
- * the vbo straight into the command stream.
- */
-
-typedef struct _i965_spans i965_spans_t;
-
-typedef float *
-(*i965_get_rectangle_func_t) (i965_spans_t *spans);
-
-struct _i965_spans {
-    cairo_span_renderer_t renderer;
-
-    i965_device_t *device;
-
-    int xmin, xmax;
-    cairo_bool_t is_bounded;
-    const cairo_rectangle_int_t *extents;
-
-    i965_get_rectangle_func_t get_rectangle;
-    i965_shader_t shader;
-
-    cairo_region_t *clip_region;
-
-    struct i965_vbo head, *tail;
-
-    unsigned int vbo_offset;
-    float *vbo_base;
-};
-
-static float *
-i965_spans_emit_rectangle (i965_spans_t *spans)
-{
-    return i965_add_rectangle (spans->device);
-}
-
-static float *
-i965_spans_accumulate_rectangle (i965_spans_t *spans)
-{
-    float *vertices;
-    uint32_t size;
-
-    size = spans->device->rectangle_size;
-    if (unlikely (spans->vbo_offset + size > I965_VERTEX_SIZE)) {
-	struct i965_vbo *vbo;
-
-	vbo = _cairo_malloc (sizeof (struct i965_vbo));
-	if (unlikely (vbo == NULL)) {
-	    /* throw error! */
-	}
-
-	spans->tail->next = vbo;
-	spans->tail = vbo;
-
-	vbo->next = NULL;
-	vbo->bo = intel_bo_create (&spans->device->intel,
-				   I965_VERTEX_SIZE, I965_VERTEX_SIZE,
-				   FALSE, I915_TILING_NONE, 0);
-	vbo->count = 0;
-
-	spans->vbo_offset = 0;
-	spans->vbo_base = intel_bo_map (&spans->device->intel, vbo->bo);
-    }
-
-    vertices = spans->vbo_base + spans->vbo_offset;
-    spans->vbo_offset += size;
-    spans->tail->count += 3;
-
-    return vertices;
-}
-
-static void
-i965_span_rectangle (i965_spans_t *spans,
-		     int x0, int x1, int y0, int y1,
-		     int alpha)
-{
-    float *vertices;
-    float a = alpha / 255.;
-
-    vertices = spans->get_rectangle (spans);
-
-    *vertices++ = x1;
-    *vertices++ = y1;
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y1;
-    *vertices++ = a;
-
-    *vertices++ = x0;
-    *vertices++ = y0;
-    *vertices++ = a;
-}
-
-static cairo_status_t
-i965_bounded_spans_mono (void *abstract_renderer,
-			 int y, int height,
-			 const cairo_half_open_span_t *half,
-			 unsigned num_spans)
-{
-    i965_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    do {
-	if (half[0].coverage >= 128) {
-	    i965_span_rectangle (spans,
-				 half[0].x, half[1].x,
-				 y, y + height,
-				 255);
-	}
-	half++;
-    } while (--num_spans > 1);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_bounded_spans (void *abstract_renderer,
-		    int y, int height,
-		    const cairo_half_open_span_t *half,
-		    unsigned num_spans)
-{
-    i965_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    do {
-	if (half[0].coverage) {
-	    i965_span_rectangle (spans,
-				 half[0].x, half[1].x,
-				 y, y + height,
-				 half[0].coverage);
-	}
-	half++;
-    } while (--num_spans > 1);
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_unbounded_spans (void *abstract_renderer,
-		      int y, int height,
-		      const cairo_half_open_span_t *half,
-		      unsigned num_spans)
-{
-    i965_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0) {
-	i965_span_rectangle (spans,
-			     spans->xmin, spans->xmax,
-			     y, y + height,
-			     0);
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    if (half[0].x != spans->xmin) {
-	i965_span_rectangle (spans,
-			     spans->xmin, half[0].x,
-			     y, y + height,
-			     0);
-    }
-
-    do {
-	i965_span_rectangle (spans,
-			     half[0].x, half[1].x,
-			     y, y + height,
-			     half[0].coverage);
-	half++;
-    } while (--num_spans > 1);
-
-    if (half[0].x != spans->xmax) {
-	i965_span_rectangle (spans,
-			     half[0].x, spans->xmax,
-			     y, y + height,
-			     0);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_unbounded_spans_mono (void *abstract_renderer,
-			   int y, int height,
-			   const cairo_half_open_span_t *half,
-			   unsigned num_spans)
-{
-    i965_spans_t *spans = abstract_renderer;
-
-    if (num_spans == 0) {
-	i965_span_rectangle (spans,
-			     spans->xmin, spans->xmax,
-			     y, y + height,
-			     0);
-	return CAIRO_STATUS_SUCCESS;
-    }
-
-    if (half[0].x != spans->xmin) {
-	i965_span_rectangle (spans,
-			     spans->xmin, half[0].x,
-			     y, y + height,
-			     0);
-    }
-
-    do {
-	int alpha = 0;
-	if (half[0].coverage >= 128)
-	    alpha = 255;
-	i965_span_rectangle (spans,
-			     half[0].x, half[1].x,
-			     y, y + height,
-			     alpha);
-	half++;
-    } while (--num_spans > 1);
-
-    if (half[0].x != spans->xmax) {
-	i965_span_rectangle (spans,
-			     half[0].x, spans->xmax,
-			     y, y + height,
-			     0);
-    }
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_status_t
-i965_spans_init (i965_spans_t *spans,
-		 i965_surface_t *dst,
-		 cairo_operator_t op,
-		 const cairo_pattern_t *pattern,
-		 cairo_antialias_t antialias,
-		 cairo_clip_t *clip,
-		 const cairo_composite_rectangles_t *extents)
-{
-    cairo_status_t status;
-
-    spans->device = i965_device (dst);
-    i965_shader_init (&spans->shader, dst, op);
-
-    spans->is_bounded = extents->is_bounded;
-    if (extents->is_bounded) {
-	if (antialias == CAIRO_ANTIALIAS_NONE)
-	    spans->renderer.render_rows = i965_bounded_spans_mono;
-	else
-	    spans->renderer.render_rows = i965_bounded_spans;
-
-	spans->extents = &extents->bounded;
-    } else {
-	if (antialias == CAIRO_ANTIALIAS_NONE)
-	    spans->renderer.render_rows = i965_unbounded_spans_mono;
-	else
-	    spans->renderer.render_rows = i965_unbounded_spans;
-
-	spans->extents = &extents->unbounded;
-    }
-    spans->xmin = spans->extents->x;
-    spans->xmax = spans->extents->x + spans->extents->width;
-
-    spans->clip_region = NULL;
-    if (clip != NULL) {
-	cairo_region_t *clip_region = NULL;
-
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || status == CAIRO_INT_STATUS_UNSUPPORTED);
-
-	if (clip_region != NULL && cairo_region_num_rectangles (clip_region) == 1)
-	    clip_region = NULL;
-
-	spans->clip_region = clip_region;
-	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	    i965_shader_set_clip (&spans->shader, clip);
-    }
-
-    spans->head.next  = NULL;
-    spans->head.bo    = NULL;
-    spans->head.count = 0;
-    spans->tail = &spans->head;
-
-    if (spans->clip_region == NULL) {
-	spans->get_rectangle = i965_spans_emit_rectangle;
-    } else {
-	spans->get_rectangle = i965_spans_accumulate_rectangle;
-	spans->head.bo = intel_bo_create (&spans->device->intel,
-					  I965_VERTEX_SIZE, I965_VERTEX_SIZE,
-					  FALSE, I915_TILING_NONE, 0);
-	if (unlikely (spans->head.bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	spans->vbo_base = intel_bo_map (&spans->device->intel, spans->head.bo);
-    }
-    spans->vbo_offset = 0;
-
-    return i965_shader_acquire_pattern (&spans->shader,
-					&spans->shader.source,
-					pattern, &extents->bounded);
-}
-
-static void
-i965_spans_fini (i965_spans_t *spans)
-{
-    i965_shader_fini (&spans->shader);
-
-    if (spans->head.bo != NULL) {
-	struct i965_vbo *vbo, *next;
-
-	intel_bo_destroy (&spans->device->intel, spans->head.bo);
-	for (vbo = spans->head.next; vbo != NULL; vbo = next) {
-	    next = vbo->next;
-	    intel_bo_destroy (&spans->device->intel, vbo->bo);
-	    free (vbo);
-	}
-    }
-}
-
-cairo_status_t
-i965_clip_and_composite_spans (i965_surface_t		*dst,
-			       cairo_operator_t		 op,
-			       const cairo_pattern_t	*pattern,
-			       cairo_antialias_t	 antialias,
-			       i965_spans_func_t	 draw_func,
-			       void			*draw_closure,
-			       const cairo_composite_rectangles_t*extents,
-			       cairo_clip_t		*clip)
-{
-    i965_spans_t spans;
-    i965_device_t *device;
-    cairo_status_t status;
-
-    if (op == CAIRO_OPERATOR_CLEAR) {
-	pattern = &_cairo_pattern_white.base;
-	op = CAIRO_OPERATOR_DEST_OUT;
-    }
-
-    status = i965_spans_init (&spans, dst, op, pattern, antialias, clip, extents);
-    if (unlikely (status))
-	return status;
-
-    spans.shader.mask.base.content  = CAIRO_CONTENT_ALPHA;
-    spans.shader.mask.type.fragment = FS_SPANS;
-    spans.shader.mask.type.vertex   = VS_SPANS;
-    spans.shader.mask.type.pattern  = PATTERN_BASE;
-
-    status = cairo_device_acquire (dst->intel.drm.base.device);
-    if (unlikely (status))
-	goto CLEANUP_SPANS;
-
-    device = i965_device (dst);
-    status = i965_shader_commit (&spans.shader, device);
-    if (unlikely (status))
-	goto CLEANUP_DEVICE;
-
-    status = draw_func (draw_closure, &spans.renderer, spans.extents);
-    if (spans.clip_region != NULL && status == CAIRO_STATUS_SUCCESS)
-	i965_clipped_vertices (device, &spans.head, spans.clip_region);
-
-  CLEANUP_DEVICE:
-    cairo_device_release (dst->intel.drm.base.device);
-  CLEANUP_SPANS:
-    i965_spans_fini (&spans);
-
-    return status;
-}
diff --git a/src/drm/cairo-drm-i965-surface.c b/src/drm/cairo-drm-i965-surface.c
deleted file mode 100644
index 9d29e4753..000000000
--- a/src/drm/cairo-drm-i965-surface.c
+++ /dev/null
@@ -1,1926 +0,0 @@
-/* Cairo - a vector graphics library with display and print output
- *
- * Copyright © 2009 Kristian Høgsberg
- * Copyright © 2009 Chris Wilson
- * Copyright © 2009 Intel Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it either under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation
- * (the "LGPL") or, at your option, under the terms of the Mozilla
- * Public License Version 1.1 (the "MPL"). If you do not alter this
- * notice, a recipient may use your version of this file under either
- * the MPL or the LGPL.
- *
- * You should have received a copy of the LGPL along with this library
- * in the file COPYING-LGPL-2.1; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
- * You should have received a copy of the MPL along with this library
- * in the file COPYING-MPL-1.1
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
- * OF ANY KIND, either express or implied. See the LGPL or the MPL for
- * the specific language governing rights and limitations.
- *
- * The Original Code is the cairo graphics library.
- *
- * The Initial Developer of the Original Code is Kristian Høgsberg.
- *
- * Based on the xf86-intel-driver i965 render acceleration code,
- * authored by:
- *    Wang Zhenyu <zhenyu.z.wang at intel.com>
- *    Eric Anholt <eric at anholt.net>
- *    Carl Worth <cworth at redhat.com>
- *    Keith Packard <keithp at keithp.com>
- */
-
-/* XXX
- *
- * FIXME: Use brw_PLN for [DevCTG-B+]
- *
- */
-
-#include "cairoint.h"
-
-#include "cairo-drm-private.h"
-#include "cairo-drm-intel-private.h"
-#include "cairo-drm-intel-command-private.h"
-#include "cairo-drm-intel-ioctl-private.h"
-#include "cairo-drm-i965-private.h"
-
-#include "cairo-boxes-private.h"
-#include "cairo-composite-rectangles-private.h"
-#include "cairo-default-context-private.h"
-#include "cairo-error-private.h"
-#include "cairo-region-private.h"
-#include "cairo-surface-offset-private.h"
-
-#include <sys/ioctl.h>
-#include <errno.h>
-
-#define I965_MAX_SIZE 8192
-
-static const cairo_surface_backend_t i965_surface_backend;
-
-static void
-i965_stream_init (i965_stream_t *stream,
-		  uint8_t *data, uint32_t size,
-		  struct i965_pending_relocation *pending, int max_pending,
-		  struct drm_i915_gem_relocation_entry *relocations, int max_relocations)
-
-{
-    stream->used = stream->committed = 0;
-    stream->data = data;
-    stream->size = size;
-    stream->serial = 1;
-
-    stream->num_pending_relocations = 0;
-    stream->max_pending_relocations = max_pending;
-    stream->pending_relocations = pending;
-
-    stream->num_relocations = 0;
-    stream->max_relocations = max_relocations;
-    stream->relocations = relocations;
-}
-
-static void
-i965_add_relocation (i965_device_t *device,
-		     intel_bo_t *bo,
-		     uint32_t read_domains,
-		     uint32_t write_domain)
-{
-    if (bo->exec == NULL) {
-	int i;
-
-	device->exec.gtt_size += bo->base.size;
-
-	i = device->exec.count++;
-	assert (i < ARRAY_LENGTH (device->exec.exec));
-
-	device->exec.exec[i].handle = bo->base.handle;
-	device->exec.exec[i].relocation_count = 0;
-	device->exec.exec[i].relocs_ptr = 0;
-	device->exec.exec[i].alignment  = 0;
-	device->exec.exec[i].offset = 0;
-	device->exec.exec[i].flags  = 0;
-	device->exec.exec[i].rsvd1  = 0;
-	device->exec.exec[i].rsvd2  = 0;
-
-	device->exec.bo[i] = intel_bo_reference (bo);
-	bo->exec = &device->exec.exec[i];
-    }
-
-    if (cairo_list_is_empty (&bo->link))
-	cairo_list_add_tail (&device->flush, &bo->link);
-
-    assert (write_domain == 0 || bo->batch_write_domain == 0 || bo->batch_write_domain == write_domain);
-    bo->batch_read_domains |= read_domains;
-    bo->batch_write_domain |= write_domain;
-}
-
-void
-i965_emit_relocation (i965_device_t *device,
-		      i965_stream_t *stream,
-		      intel_bo_t *target,
-		      uint32_t target_offset,
-		      uint32_t read_domains,
-		      uint32_t write_domain,
-		      uint32_t offset)
-{
-    int n;
-
-    assert (target_offset < target->base.size);
-
-    i965_add_relocation (device, target, read_domains, write_domain);
-
-    n = stream->num_relocations++;
-    assert (n < stream->max_relocations);
-
-    stream->relocations[n].offset = offset;
-    stream->relocations[n].delta  = target_offset;
-    stream->relocations[n].target_handle   = target->base.handle;
-    stream->relocations[n].read_domains    = read_domains;
-    stream->relocations[n].write_domain    = write_domain;
-    stream->relocations[n].presumed_offset = target->offset;
-}
-
-static void
-i965_stream_reset (i965_stream_t *stream)
-{
-    stream->used = stream->committed = 0;
-    stream->num_relocations = 0;
-    stream->num_pending_relocations = 0;
-    if (++stream->serial == 0)
-	stream->serial = 1;
-}
-
-void
-i965_stream_commit (i965_device_t *device,
-		    i965_stream_t *stream)
-{
-    intel_bo_t *bo;
-    int n;
-
-    assert (stream->used);
-
-    bo = intel_bo_create (&device->intel,
-			  stream->used, stream->used,
-			  FALSE, I915_TILING_NONE, 0);
-
-    /* apply pending relocations */
-    for (n = 0; n < stream->num_pending_relocations; n++) {
-	struct i965_pending_relocation *p = &stream->pending_relocations[n];
-
-	i965_emit_relocation (device, &device->batch, bo,
-			      p->delta,
-			      p->read_domains,
-			      p->write_domain,
-			      p->offset);
-	if (bo->offset)
-	    *(uint32_t *) (device->batch.data + p->offset) = bo->offset + p->delta;
-    }
-
-    intel_bo_write (&device->intel, bo, 0, stream->used, stream->data);
-
-    if (stream->num_relocations) {
-	assert (bo->exec != NULL);
-	bo->exec->relocs_ptr = (uintptr_t) stream->relocations;
-	bo->exec->relocation_count = stream->num_relocations;
-    }
-
-    intel_bo_destroy (&device->intel, bo);
-
-    i965_stream_reset (stream);
-}
-
-static void
-sf_states_pluck (void *entry, void *closure)
-{
-    i965_device_t *device = closure;
-
-    _cairo_hash_table_remove (device->sf_states, entry);
-    _cairo_freelist_free (&device->sf_freelist, entry);
-}
-
-static void
-cc_offsets_pluck (void *entry, void *closure)
-{
-    i965_device_t *device = closure;
-
-    _cairo_hash_table_remove (device->cc_states, entry);
-    _cairo_freelist_free (&device->cc_freelist, entry);
-}
-
-static void
-wm_kernels_pluck (void *entry, void *closure)
-{
-    i965_device_t *device = closure;
-
-    _cairo_hash_table_remove (device->wm_kernels, entry);
-    _cairo_freelist_free (&device->wm_kernel_freelist, entry);
-}
-
-static void
-wm_states_pluck (void *entry, void *closure)
-{
-    i965_device_t *device = closure;
-
-    _cairo_hash_table_remove (device->wm_states, entry);
-    _cairo_freelist_free (&device->wm_state_freelist, entry);
-}
-
-static void
-wm_bindings_pluck (void *entry, void *closure)
-{
-    i965_device_t *device = closure;
-
-    _cairo_hash_table_remove (device->wm_bindings, entry);
-    _cairo_freelist_free (&device->wm_binding_freelist, entry);
-}
-
-static void
-samplers_pluck (void *entry, void *closure)
-{
-    i965_device_t *device = closure;
-
-    _cairo_hash_table_remove (device->samplers, entry);
-    _cairo_freelist_free (&device->sampler_freelist, entry);
-}
-
-void
-i965_general_state_reset (i965_device_t *device)
-{
-    _cairo_hash_table_foreach (device->sf_states,
-			       sf_states_pluck,
-			       device);
-
-    _cairo_hash_table_foreach (device->cc_states,
-			       cc_offsets_pluck,
-			       device);
-
-    _cairo_hash_table_foreach (device->wm_kernels,
-			       wm_kernels_pluck,
-			       device);
-
-    _cairo_hash_table_foreach (device->wm_states,
-			       wm_states_pluck,
-			       device);
-
-    _cairo_hash_table_foreach (device->wm_bindings,
-			       wm_bindings_pluck,
-			       device);
-
-    _cairo_hash_table_foreach (device->samplers,
-			       samplers_pluck,
-			       device);
-
-    device->vs_offset = (uint32_t) -1;
-    device->border_color_offset = (uint32_t) -1;
-
-    if (device->general_state != NULL) {
-	intel_bo_destroy (&device->intel, device->general_state);
-	device->general_state = NULL;
-    }
-}
-
-static void
-i965_device_reset (i965_device_t *device)
-{
-    device->exec.count = 0;
-    device->exec.gtt_size = I965_VERTEX_SIZE +
-	                    I965_SURFACE_SIZE +
-			    I965_GENERAL_SIZE +
-			    I965_BATCH_SIZE;
-
-    device->sf_state.entry.hash = (uint32_t) -1;
-    device->wm_state.entry.hash = (uint32_t) -1;
-    device->wm_binding.entry.hash = (uint32_t) -1;
-    device->cc_state.entry.hash = (uint32_t) -1;
-
-    device->target = NULL;
-    device->source = NULL;
-    device->mask = NULL;
-    device->clip = NULL;
-
-    device->draw_rectangle = (uint32_t) -1;
-
-    device->vertex_type = (uint32_t) -1;
-    device->vertex_size = 0;
-    device->rectangle_size   = 0;
-    device->last_vertex_size = 0;
-
-    device->constants = NULL;
-    device->constants_size = 0;
-
-    device->have_urb_fences = FALSE;
-}
-
-static cairo_status_t
-i965_exec (i965_device_t *device, uint32_t offset)
-{
-    struct drm_i915_gem_execbuffer2 execbuf;
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
-    int ret, i;
-
-    execbuf.buffers_ptr = (uintptr_t) device->exec.exec;
-    execbuf.buffer_count = device->exec.count;
-    execbuf.batch_start_offset = offset;
-    execbuf.batch_len = device->batch.used;
-    execbuf.DR1 = 0;
-    execbuf.DR4 = 0;
-    execbuf.num_cliprects = 0;
-    execbuf.cliprects_ptr = 0;
-    execbuf.flags = I915_GEM_3D_PIPELINE;
-    execbuf.rsvd1 = 0;
-    execbuf.rsvd2 = 0;
-
-#if 0
-    printf ("exec: offset=%d, length=%d, buffers=%d\n",
-	    offset, device->batch.used, device->exec.count);
-    intel_dump_batchbuffer ((uint32_t *) device->batch.data,
-			    device->batch.used,
-			    device->intel.base.chip_id);
-#endif
-
-    ret = 0;
-    do {
-	ret = ioctl (device->intel.base.fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &execbuf);
-    } while (ret != 0 && errno == EINTR);
-    if (unlikely (ret)) {
-	if (errno == ENOMEM)
-	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	else
-	    status = _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
-
-	fprintf (stderr, "Batch submission failed: %d\n", errno);
-	fprintf (stderr, "   gtt size: %zd/%zd\n",
-		 device->exec.gtt_size, device->intel.gtt_avail_size);
-
-	fprintf (stderr, "   %d buffers:\n",
-		 device->exec.count);
-	for (i = 0; i < device->exec.count; i++) {
-	    fprintf (stderr, "     exec[%d] = %d\n",
-		     i, device->exec.bo[i]->base.size);
-	}
-
-	intel_dump_batchbuffer ((uint32_t *) device->batch.data,
-				device->batch.used,
-				device->intel.base.chip_id);
-    }
-
-    /* XXX any write target within the batch should now be in error */
-    for (i = 0; i < device->exec.count; i++) {
-	intel_bo_t *bo = device->exec.bo[i];
-	cairo_bool_t ret;
-
-	bo->offset = device->exec.exec[i].offset;
-	bo->exec = NULL;
-	bo->batch_read_domains = 0;
-	bo->batch_write_domain = 0;
-
-	if (bo->virtual)
-	    intel_bo_unmap (bo);
-	bo->cpu = FALSE;
-
-	if (bo->purgeable)
-	    ret = intel_bo_madvise (&device->intel, bo, I915_MADV_DONTNEED);
-	    /* ignore immediate notification of purging */
-
-	cairo_list_del (&bo->cache_list);
-	cairo_list_init (&bo->link);
-	intel_bo_destroy (&device->intel, bo);
-    }
-    cairo_list_init (&device->flush);
-
-    device->exec.count = 0;
-
-    return status;
-}
-
-static inline uint32_t
-next_bo_size (uint32_t v)
-{
-    v = (v + 8191) / 8192;
-
-    v--;
-    v |= v >> 1;
-    v |= v >> 2;
-    v |= v >> 4;
-    v |= v >> 8;
-    v |= v >> 16;
-    v++;
-
-    return v * 8192;
-}
-
-static void
-_copy_to_bo_and_apply_relocations (i965_device_t *device,
-				   intel_bo_t *bo,
-				   i965_stream_t *stream,
-				   uint32_t offset)
-{
-    int n;
-
-    intel_bo_write (&device->intel, bo,
-		    offset, stream->used,
-		    stream->data);
-
-    for (n = 0; n < stream->num_pending_relocations; n++) {
-	struct i965_pending_relocation *p = &stream->pending_relocations[n];
-
-	i965_emit_relocation (device, &device->batch, bo,
-			      p->delta + offset,
-			      p->read_domains,
-			      p->write_domain,
-			      p->offset);
-
-	if (bo->offset) {
-	    *(uint32_t *) (device->batch.data + p->offset) =
-		bo->offset + p->delta + offset;
-	}
-    }
-}
-
-cairo_status_t
-i965_device_flush (i965_device_t *device)
-{
-    cairo_status_t status;
-    uint32_t aligned, max;
-    intel_bo_t *bo;
-    int n;
-
-    if (device->batch.used == 0)
-	return CAIRO_STATUS_SUCCESS;
-
-    i965_flush_vertices (device);
-
-    OUT_BATCH (MI_BATCH_BUFFER_END);
-    /* Emit a padding dword if we aren't going to be quad-word aligned. */
-    if (device->batch.used & 4)
-	OUT_BATCH (MI_NOOP);
-
-#if 0
-    printf ("device flush: vertex=%d, constant=%d, surface=%d, general=%d, batch=%d\n",
-	    device->vertex.used,
-	    device->constant.used,
-	    device->surface.used,
-	    device->general.used,
-	    device->batch.used);
-#endif
-
-    /* can we pack the surface state into the tail of the general state? */
-    if (device->general.used == device->general.committed) {
-	if (device->general.used) {
-	    assert (device->general.num_pending_relocations == 1);
-	    assert (device->general_state != NULL);
-	    i965_emit_relocation (device, &device->batch,
-				  device->general_state,
-				  device->general.pending_relocations[0].delta,
-				  device->general.pending_relocations[0].read_domains,
-				  device->general.pending_relocations[0].write_domain,
-				  device->general.pending_relocations[0].offset);
-
-	    if (device->general_state->offset) {
-		*(uint32_t *) (device->batch.data +
-			       device->general.pending_relocations[0].offset) =
-		    device->general_state->offset +
-		    device->general.pending_relocations[0].delta;
-	    }
-	}
-    } else {
-	assert (device->general.num_pending_relocations == 1);
-	if (device->general_state != NULL) {
-	    intel_bo_destroy (&device->intel, device->general_state);
-	    device->general_state = NULL;
-	}
-
-	bo = intel_bo_create (&device->intel,
-			      device->general.used,
-			      device->general.used,
-			      FALSE, I915_TILING_NONE, 0);
-	if (unlikely (bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	aligned = (device->general.used + 31) & -32;
-	if (device->surface.used &&
-	    aligned + device->surface.used <= bo->base.size)
-	{
-	    _copy_to_bo_and_apply_relocations (device, bo, &device->general, 0);
-	    _copy_to_bo_and_apply_relocations (device, bo, &device->surface, aligned);
-
-	    if (device->surface.num_relocations) {
-		for (n = 0; n < device->surface.num_relocations; n++)
-		    device->surface.relocations[n].offset += aligned;
-
-		assert (bo->exec != NULL);
-		bo->exec->relocs_ptr = (uintptr_t) device->surface.relocations;
-		bo->exec->relocation_count = device->surface.num_relocations;
-	    }
-
-	    i965_stream_reset (&device->surface);
-	}
-	else
-	{
-	    _copy_to_bo_and_apply_relocations (device, bo, &device->general, 0);
-	}
-
-	/* Note we don't reset the general state, just mark what data we've committed. */
-	device->general.committed = device->general.used;
-	device->general_state = bo;
-    }
-    device->general.num_pending_relocations = 0;
-
-    /* Combine vertex+constant+surface+batch streams? */
-    max = aligned = device->vertex.used;
-    if (device->surface.used) {
-	aligned = (aligned + 63) & -64;
-	aligned += device->surface.used;
-	if (device->surface.used > max)
-	    max = device->surface.used;
-    }
-    aligned = (aligned + 63) & -64;
-    aligned += device->batch.used;
-    if (device->batch.used > max)
-	max = device->batch.used;
-    if (aligned <= next_bo_size (max)) {
-	int batch_num_relocations;
-
-	if (aligned <= 8192)
-	    max = aligned;
-
-	bo = intel_bo_create (&device->intel,
-			      max, max,
-			      FALSE, I915_TILING_NONE, 0);
-	if (unlikely (bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	assert (aligned <= bo->base.size);
-
-	if (device->vertex.used)
-	    _copy_to_bo_and_apply_relocations (device, bo, &device->vertex, 0);
-
-	aligned = device->vertex.used;
-
-	batch_num_relocations = device->batch.num_relocations;
-	if (device->surface.used) {
-	    aligned = (aligned + 63) & -64;
-	    _copy_to_bo_and_apply_relocations (device, bo, &device->surface, aligned);
-
-	    batch_num_relocations = device->batch.num_relocations;
-	    if (device->surface.num_relocations) {
-		assert (device->batch.num_relocations + device->surface.num_relocations < device->batch.max_relocations);
-
-		memcpy (device->batch.relocations + device->batch.num_relocations,
-			device->surface.relocations,
-			sizeof (device->surface.relocations[0]) * device->surface.num_relocations);
-
-		for (n = 0; n < device->surface.num_relocations; n++)
-		    device->batch.relocations[device->batch.num_relocations + n].offset += aligned;
-
-		device->batch.num_relocations += device->surface.num_relocations;
-	    }
-
-	    aligned += device->surface.used;
-	}
-
-	aligned = (aligned + 63) & -64;
-	intel_bo_write (&device->intel, bo,
-			aligned, device->batch.used,
-			device->batch.data);
-
-	for (n = 0; n < batch_num_relocations; n++)
-	    device->batch.relocations[n].offset += aligned;
-
-	if (device->exec.bo[device->exec.count-1] == bo) {
-	    assert (bo->exec == &device->exec.exec[device->exec.count-1]);
-
-	    bo->exec->relocation_count = device->batch.num_relocations;
-	    bo->exec->relocs_ptr = (uintptr_t) device->batch.relocations;
-	    intel_bo_destroy (&device->intel, bo);
-	} else {
-	    assert (bo->exec ==  NULL);
-
-	    n = device->exec.count++;
-	    device->exec.exec[n].handle = bo->base.handle;
-	    device->exec.exec[n].relocation_count = device->batch.num_relocations;
-	    device->exec.exec[n].relocs_ptr = (uintptr_t) device->batch.relocations;
-	    device->exec.exec[n].alignment = 0;
-	    device->exec.exec[n].offset = 0;
-	    device->exec.exec[n].flags = 0;
-	    device->exec.exec[n].rsvd1 = 0;
-	    device->exec.exec[n].rsvd2 = 0;
-
-	    /* transfer ownership to the exec */
-	    device->exec.bo[n] = bo;
-	}
-    } else {
-	i965_stream_commit (device, &device->vertex);
-	if (device->surface.used)
-	    i965_stream_commit (device, &device->surface);
-
-	bo = intel_bo_create (&device->intel,
-			      device->batch.used, device->batch.used,
-			      FALSE, I915_TILING_NONE, 0);
-	if (unlikely (bo == NULL))
-	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-	intel_bo_write (&device->intel, bo,
-			0, device->batch.used,
-			device->batch.data);
-
-	n = device->exec.count++;
-	device->exec.exec[n].handle = bo->base.handle;
-	device->exec.exec[n].relocation_count = device->batch.num_relocations;
-	device->exec.exec[n].relocs_ptr = (uintptr_t) device->batch.relocations;
-	device->exec.exec[n].alignment = 0;
-	device->exec.exec[n].offset = 0;
-	device->exec.exec[n].flags = 0;
-	device->exec.exec[n].rsvd1 = 0;
-	device->exec.exec[n].rsvd2 = 0;
-
-	/* transfer ownership to the exec */
-	device->exec.bo[n] = bo;
-	aligned = 0;
-    }
-
-    status = i965_exec (device, aligned);
-
-    i965_stream_reset (&device->vertex);
-    i965_stream_reset (&device->surface);
-    i965_stream_reset (&device->batch);
-
-    intel_glyph_cache_unpin (&device->intel);
-    intel_snapshot_cache_thaw (&device->intel);
-
-    i965_device_reset (device);
-
-    return status;
-}
-
-static cairo_surface_t *
-i965_surface_create_similar (void *abstract_other,
-			     cairo_content_t content,
-			     int width, int height)
-{
-    i965_surface_t *other;
-    cairo_format_t format;
-
-    if (width > 8192 || height > 8192)
-	return NULL;
-
-    other = abstract_other;
-    if (content == other->intel.drm.base.content)
-	format = other->intel.drm.format;
-    else
-	format = _cairo_format_from_content (content);
-
-    return i965_surface_create_internal ((cairo_drm_device_t *) other->intel.drm.base.device,
-					 format,
-					 width, height,
-					 I965_TILING_DEFAULT, TRUE);
-}
-
-static cairo_status_t
-i965_surface_finish (void *abstract_surface)
-{
-    i965_surface_t *surface = abstract_surface;
-
-    return intel_surface_finish (&surface->intel);
-}
-
-static cairo_status_t
-i965_surface_flush (void *abstract_surface, unsigned flags)
-{
-    i965_surface_t *surface = abstract_surface;
-    cairo_status_t status = CAIRO_STATUS_SUCCESS;
-
-    if (flags)
-	return CAIRO_STATUS_SUCCESS;
-
-    if (surface->intel.drm.fallback != NULL)
-	return intel_surface_flush (abstract_surface);
-
-    /* Forgo flushing on finish as the user cannot access the surface directly. */
-    if (! surface->intel.drm.base.finished &&
-	to_intel_bo (surface->intel.drm.bo)->exec != NULL)
-    {
-	status = cairo_device_acquire (surface->intel.drm.base.device);
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    i965_device_t *device;
-
-	    device = i965_device (surface);
-	    status = i965_device_flush (device);
-	    cairo_device_release (&device->intel.base.base);
-	}
-    }
-
-    return status;
-}
-
-/* rasterisation */
-
-static cairo_status_t
-_composite_boxes_spans (void				*closure,
-			cairo_span_renderer_t		*renderer,
-			const cairo_rectangle_int_t	*extents)
-{
-    cairo_boxes_t *boxes = closure;
-    cairo_rectangular_scan_converter_t converter;
-    struct _cairo_boxes_chunk *chunk;
-    cairo_status_t status;
-
-    _cairo_rectangular_scan_converter_init (&converter, extents);
-    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	cairo_box_t *box = chunk->base;
-	int i;
-
-	for (i = 0; i < chunk->count; i++) {
-	    status = _cairo_rectangular_scan_converter_add_box (&converter, &box[i], 1);
-	    if (unlikely (status))
-		goto CLEANUP;
-	}
-    }
-
-    status = converter.base.generate (&converter.base, renderer);
-
-  CLEANUP:
-    converter.base.destroy (&converter.base);
-    return status;
-}
-
-cairo_status_t
-i965_fixup_unbounded (i965_surface_t *dst,
-		      const cairo_composite_rectangles_t *extents,
-		      cairo_clip_t *clip)
-{
-    i965_shader_t shader;
-    i965_device_t *device;
-    cairo_status_t status;
-
-    i965_shader_init (&shader, dst, CAIRO_OPERATOR_CLEAR);
-
-    if (clip != NULL) {
-	cairo_region_t *clip_region = NULL;
-
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || CAIRO_INT_STATUS_UNSUPPORTED);
-	assert (clip_region == NULL);
-
-	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	    i965_shader_set_clip (&shader, clip);
-    } else {
-	if (extents->bounded.width  == extents->unbounded.width &&
-	    extents->bounded.height == extents->unbounded.height)
-	{
-	    return CAIRO_STATUS_SUCCESS;
-	}
-    }
-
-    status = i965_shader_acquire_pattern (&shader,
-					  &shader.source,
-					  &_cairo_pattern_clear.base,
-					  &extents->unbounded);
-    if (unlikely (status)) {
-	i965_shader_fini (&shader);
-	return status;
-    }
-
-    device = i965_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	return status;
-
-    status = i965_shader_commit (&shader, device);
-    if (unlikely (status)) {
-	goto BAIL;
-    }
-
-    if (extents->bounded.width == 0 || extents->bounded.height == 0) {
-	i965_shader_add_rectangle (&shader,
-				   extents->unbounded.x,
-				   extents->unbounded.y,
-				   extents->unbounded.width,
-				   extents->unbounded.height);
-    } else { /* top */
-	if (extents->bounded.y != extents->unbounded.y) {
-	    cairo_rectangle_int_t rect;
-
-	    rect.x = extents->unbounded.x;
-	    rect.y = extents->unbounded.y;
-	    rect.width  = extents->unbounded.width;
-	    rect.height = extents->bounded.y - rect.y;
-
-	    i965_shader_add_rectangle (&shader,
-				       rect.x, rect.y,
-				       rect.width, rect.height);
-	}
-
-	/* left */
-	if (extents->bounded.x != extents->unbounded.x) {
-	    cairo_rectangle_int_t rect;
-
-	    rect.x = extents->unbounded.x;
-	    rect.y = extents->bounded.y;
-	    rect.width  = extents->bounded.x - extents->unbounded.x;
-	    rect.height = extents->bounded.height;
-
-	    i965_shader_add_rectangle (&shader,
-				       rect.x, rect.y,
-				       rect.width, rect.height);
-	}
-
-	/* right */
-	if (extents->bounded.x + extents->bounded.width != extents->unbounded.x + extents->unbounded.width) {
-	    cairo_rectangle_int_t rect;
-
-	    rect.x = extents->bounded.x + extents->bounded.width;
-	    rect.y = extents->bounded.y;
-	    rect.width  = extents->unbounded.x + extents->unbounded.width - rect.x;
-	    rect.height = extents->bounded.height;
-
-	    i965_shader_add_rectangle (&shader,
-				       rect.x, rect.y,
-				       rect.width, rect.height);
-	}
-
-	/* bottom */
-	if (extents->bounded.y + extents->bounded.height != extents->unbounded.y + extents->unbounded.height) {
-	    cairo_rectangle_int_t rect;
-
-	    rect.x = extents->unbounded.x;
-	    rect.y = extents->bounded.y + extents->bounded.height;
-	    rect.width  = extents->unbounded.width;
-	    rect.height = extents->unbounded.y + extents->unbounded.height - rect.y;
-
-	    i965_shader_add_rectangle (&shader,
-				       rect.x, rect.y,
-				       rect.width, rect.height);
-	}
-    }
-
-    i965_shader_fini (&shader);
-  BAIL:
-    cairo_device_release (&device->intel.base.base);
-    return status;
-}
-
-static cairo_status_t
-i965_fixup_unbounded_boxes (i965_surface_t *dst,
-			    const cairo_composite_rectangles_t *extents,
-			    cairo_clip_t *clip,
-			    cairo_boxes_t *boxes)
-{
-    cairo_boxes_t clear;
-    cairo_box_t box;
-    cairo_region_t *clip_region = NULL;
-    cairo_status_t status;
-    struct _cairo_boxes_chunk *chunk;
-    i965_shader_t shader;
-    int i;
-
-    if (boxes->num_boxes <= 1)
-	return i965_fixup_unbounded (dst, extents, clip);
-
-    i965_shader_init (&shader, dst, CAIRO_OPERATOR_CLEAR);
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || CAIRO_INT_STATUS_UNSUPPORTED);
-	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	    i965_shader_set_clip (&shader, clip);
-    }
-
-    status = i965_shader_acquire_pattern (&shader,
-					  &shader.source,
-					  &_cairo_pattern_clear.base,
-					  &extents->unbounded);
-    if (unlikely (status)) {
-	i965_shader_fini (&shader);
-	return status;
-    }
-
-    _cairo_boxes_init (&clear);
-
-    box.p1.x = _cairo_fixed_from_int (extents->unbounded.x + extents->unbounded.width);
-    box.p1.y = _cairo_fixed_from_int (extents->unbounded.y);
-    box.p2.x = _cairo_fixed_from_int (extents->unbounded.x);
-    box.p2.y = _cairo_fixed_from_int (extents->unbounded.y + extents->unbounded.height);
-
-    if (clip_region == NULL) {
-	cairo_boxes_t tmp;
-
-	_cairo_boxes_init (&tmp);
-
-	status = _cairo_boxes_add (&tmp, &box);
-	assert (status == CAIRO_STATUS_SUCCESS);
-
-	tmp.chunks.next = &boxes->chunks;
-	tmp.num_boxes += boxes->num_boxes;
-
-	status = _cairo_bentley_ottmann_tessellate_boxes (&tmp,
-							  CAIRO_FILL_RULE_WINDING,
-							  &clear);
-
-	tmp.chunks.next = NULL;
-    } else {
-	pixman_box32_t *pbox;
-
-	pbox = pixman_region32_rectangles (&clip_region->rgn, &i);
-	_cairo_boxes_limit (&clear, (cairo_box_t *) pbox, i);
-
-	status = _cairo_boxes_add (&clear, &box);
-	assert (status == CAIRO_STATUS_SUCCESS);
-
-	for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	    for (i = 0; i < chunk->count; i++) {
-		status = _cairo_boxes_add (&clear, &chunk->base[i]);
-		if (unlikely (status)) {
-		    _cairo_boxes_fini (&clear);
-		    return status;
-		}
-	    }
-	}
-
-	status = _cairo_bentley_ottmann_tessellate_boxes (&clear,
-							  CAIRO_FILL_RULE_WINDING,
-							  &clear);
-    }
-
-    if (likely (status == CAIRO_STATUS_SUCCESS && clear.num_boxes)) {
-	i965_device_t *device;
-
-	device = i965_device (dst);
-	status = cairo_device_acquire (&device->intel.base.base);
-	if (unlikely (status))
-	    goto err_shader;
-
-	status = i965_shader_commit (&shader, device);
-	if (unlikely (status))
-	    goto err_device;
-
-	for (chunk = &clear.chunks; chunk != NULL; chunk = chunk->next) {
-	    for (i = 0; i < chunk->count; i++) {
-		int x1 = _cairo_fixed_integer_part (chunk->base[i].p1.x);
-		int y1 = _cairo_fixed_integer_part (chunk->base[i].p1.y);
-		int x2 = _cairo_fixed_integer_part (chunk->base[i].p2.x);
-		int y2 = _cairo_fixed_integer_part (chunk->base[i].p2.y);
-
-		i965_shader_add_rectangle (&shader, x1, y1, x2 - x1, y2 - y1);
-	    }
-	}
-
-err_device:
-	cairo_device_release (&device->intel.base.base);
-err_shader:
-	i965_shader_fini (&shader);
-    }
-
-    _cairo_boxes_fini (&clear);
-
-    return status;
-}
-
-static cairo_status_t
-_composite_boxes (i965_surface_t *dst,
-		  cairo_operator_t op,
-		  const cairo_pattern_t *pattern,
-		  cairo_boxes_t *boxes,
-		  cairo_antialias_t antialias,
-		  cairo_clip_t *clip,
-		  const cairo_composite_rectangles_t *extents)
-{
-    cairo_bool_t need_clip_surface = FALSE;
-    cairo_region_t *clip_region = NULL;
-    const struct _cairo_boxes_chunk *chunk;
-    cairo_status_t status;
-    i965_shader_t shader;
-    i965_device_t *device;
-    int i;
-
-    /* If the boxes are not pixel-aligned, we will need to compute a real mask */
-    if (antialias != CAIRO_ANTIALIAS_NONE) {
-	if (! boxes->is_pixel_aligned)
-	    return CAIRO_INT_STATUS_UNSUPPORTED;
-    }
-
-    i965_shader_init (&shader, dst, op);
-
-    status = i965_shader_acquire_pattern (&shader,
-					  &shader.source,
-					  pattern,
-					  &extents->bounded);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || CAIRO_INT_STATUS_UNSUPPORTED);
-	need_clip_surface = status == CAIRO_INT_STATUS_UNSUPPORTED;
-	if (need_clip_surface)
-	    i965_shader_set_clip (&shader, clip);
-    }
-
-    device = i965_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto err_shader;
-
-    status = i965_shader_commit (&shader, i965_device (dst));
-    if (unlikely (status))
-	goto err_device;
-
-    for (chunk = &boxes->chunks; chunk != NULL; chunk = chunk->next) {
-	cairo_box_t *box = chunk->base;
-	for (i = 0; i < chunk->count; i++) {
-	    int x1 = _cairo_fixed_integer_round (box[i].p1.x);
-	    int y1 = _cairo_fixed_integer_round (box[i].p1.y);
-	    int x2 = _cairo_fixed_integer_round (box[i].p2.x);
-	    int y2 = _cairo_fixed_integer_round (box[i].p2.y);
-
-	    if (x2 > x1 && y2 > y1)
-		i965_shader_add_rectangle (&shader, x1, y1, x2 - x1, y2 - y1);
-	}
-    }
-
-    if (! extents->is_bounded)
-	status = i965_fixup_unbounded_boxes (dst, extents, clip, boxes);
-
-  err_device:
-    cairo_device_release (&device->intel.base.base);
-  err_shader:
-    i965_shader_fini (&shader);
-
-    return status;
-}
-
-static cairo_status_t
-_clip_and_composite_boxes (i965_surface_t *dst,
-			   cairo_operator_t op,
-			   const cairo_pattern_t *src,
-			   cairo_boxes_t *boxes,
-			   cairo_antialias_t antialias,
-			   const cairo_composite_rectangles_t *extents,
-			   cairo_clip_t *clip)
-{
-    cairo_status_t status;
-
-    if (boxes->num_boxes == 0) {
-	if (extents->is_bounded)
-	    return CAIRO_STATUS_SUCCESS;
-
-	return i965_fixup_unbounded (dst, extents, clip);
-    }
-
-    /* Use a fast path if the boxes are pixel aligned */
-    status = _composite_boxes (dst, op, src, boxes, antialias, clip, extents);
-    if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	return status;
-
-    /* Otherwise render the boxes via an implicit mask and composite in the usual
-     * fashion.
-     */
-    return i965_clip_and_composite_spans (dst, op, src, antialias,
-					  _composite_boxes_spans, boxes,
-					  extents, clip);
-}
-
-static cairo_int_status_t
-i965_surface_paint (void			*abstract_dst,
-		    cairo_operator_t		 op,
-		    const cairo_pattern_t	*source,
-		    cairo_clip_t		*clip)
-{
-    i965_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    cairo_boxes_t boxes;
-    cairo_box_t *clip_boxes = boxes.boxes_embedded;
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    int num_boxes = ARRAY_LENGTH (boxes.boxes_embedded);
-    cairo_status_t status;
-
-    /* XXX unsupported operators? use pixel shader blending, eventually */
-
-    status = _cairo_composite_rectangles_init_for_paint (&extents,
-							 dst->intel.drm.width,
-							 dst->intel.drm.height,
-							 op, source,
-							 clip);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL && _cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	have_clip = TRUE;
-    }
-
-    status = _cairo_clip_to_boxes (&clip, &extents, &clip_boxes, &num_boxes);
-    if (unlikely (status)) {
-	if (have_clip)
-	    _cairo_clip_fini (&local_clip);
-
-	return status;
-    }
-
-    _cairo_boxes_init_for_array (&boxes, clip_boxes, num_boxes);
-    status = _clip_and_composite_boxes (dst, op, source,
-					&boxes, CAIRO_ANTIALIAS_DEFAULT,
-					&extents, clip);
-    if (clip_boxes != boxes.boxes_embedded)
-	free (clip_boxes);
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static cairo_int_status_t
-i965_surface_mask (void				*abstract_dst,
-		   cairo_operator_t		 op,
-		   const cairo_pattern_t	*source,
-		   const cairo_pattern_t	*mask,
-		   cairo_clip_t			*clip)
-{
-    i965_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    i965_shader_t shader;
-    i965_device_t *device;
-    cairo_clip_t local_clip;
-    cairo_region_t *clip_region = NULL;
-    cairo_bool_t need_clip_surface = FALSE;
-    cairo_bool_t have_clip = FALSE;
-    cairo_status_t status;
-
-    status = _cairo_composite_rectangles_init_for_mask (&extents,
-							dst->intel.drm.width,
-							dst->intel.drm.height,
-							op, source, mask, clip);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL && _cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL && extents.is_bounded) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	status = _cairo_clip_rectangle (clip, &extents.bounded);
-	if (unlikely (status)) {
-	    _cairo_clip_fini (&local_clip);
-	    return status;
-	}
-
-	have_clip = TRUE;
-    }
-
-    i965_shader_init (&shader, dst, op);
-
-    status = i965_shader_acquire_pattern (&shader,
-					  &shader.source,
-					  source,
-					  &extents.bounded);
-    if (unlikely (status))
-	goto err_shader;
-
-    status = i965_shader_acquire_pattern (&shader,
-					  &shader.mask,
-					  mask,
-					  &extents.bounded);
-    if (unlikely (status))
-	goto err_shader;
-
-    if (clip != NULL) {
-	status = _cairo_clip_get_region (clip, &clip_region);
-	assert (status == CAIRO_STATUS_SUCCESS || CAIRO_INT_STATUS_UNSUPPORTED);
-	need_clip_surface = status == CAIRO_INT_STATUS_UNSUPPORTED;
-	if (need_clip_surface)
-	    i965_shader_set_clip (&shader, clip);
-    }
-
-    device = i965_device (dst);
-    status = cairo_device_acquire (&device->intel.base.base);
-    if (unlikely (status))
-	goto err_shader;
-
-    status = i965_shader_commit (&shader, device);
-    if (unlikely (status))
-	goto err_device;
-
-    if (clip_region != NULL) {
-	unsigned int n, num_rectangles;
-
-	num_rectangles = cairo_region_num_rectangles (clip_region);
-	for (n = 0; n < num_rectangles; n++) {
-	    cairo_rectangle_int_t rect;
-
-	    cairo_region_get_rectangle (clip_region, n, &rect);
-
-	    i965_shader_add_rectangle (&shader,
-				       rect.x, rect.y,
-				       rect.width, rect.height);
-	}
-    } else {
-	i965_shader_add_rectangle (&shader,
-				   extents.bounded.x,
-				   extents.bounded.y,
-				   extents.bounded.width,
-				   extents.bounded.height);
-    }
-
-    if (! extents.is_bounded)
-	status = i965_fixup_unbounded (dst, &extents, clip);
-
-  err_device:
-    cairo_device_release (&device->intel.base.base);
-  err_shader:
-    i965_shader_fini (&shader);
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-typedef struct {
-    cairo_polygon_t		polygon;
-    cairo_fill_rule_t		 fill_rule;
-    cairo_antialias_t		 antialias;
-} composite_polygon_info_t;
-
-static cairo_status_t
-_composite_polygon_spans (void                          *closure,
-			  cairo_span_renderer_t		*renderer,
-			  const cairo_rectangle_int_t   *extents)
-{
-    composite_polygon_info_t *info = closure;
-    cairo_botor_scan_converter_t converter;
-    cairo_status_t status;
-    cairo_box_t box;
-
-    box.p1.x = _cairo_fixed_from_int (extents->x);
-    box.p1.y = _cairo_fixed_from_int (extents->y);
-    box.p2.x = _cairo_fixed_from_int (extents->x + extents->width);
-    box.p2.y = _cairo_fixed_from_int (extents->y + extents->height);
-
-    _cairo_botor_scan_converter_init (&converter, &box, info->fill_rule);
-
-    status = converter.base.add_polygon (&converter.base, &info->polygon);
-    if (likely (status == CAIRO_STATUS_SUCCESS))
-	status = converter.base.generate (&converter.base, renderer);
-
-    converter.base.destroy (&converter.base);
-
-    return status;
-}
-
-static cairo_int_status_t
-i965_surface_stroke (void			*abstract_dst,
-		     cairo_operator_t		 op,
-		     const cairo_pattern_t	*source,
-		     cairo_path_fixed_t		*path,
-		     const cairo_stroke_style_t	*stroke_style,
-		     const cairo_matrix_t	*ctm,
-		     const cairo_matrix_t	*ctm_inverse,
-		     double			 tolerance,
-		     cairo_antialias_t		 antialias,
-		     cairo_clip_t		*clip)
-{
-    i965_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    composite_polygon_info_t info;
-    cairo_box_t boxes_stack[32], *clip_boxes = boxes_stack;
-    int num_boxes = ARRAY_LENGTH (boxes_stack);
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    cairo_status_t status;
-
-    status = _cairo_composite_rectangles_init_for_stroke (&extents,
-							  dst->intel.drm.width,
-							  dst->intel.drm.height,
-							  op, source,
-							  path, stroke_style, ctm,
-							  clip);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL && _cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	have_clip = TRUE;
-    }
-
-    status = _cairo_clip_to_boxes (&clip, &extents, &clip_boxes, &num_boxes);
-    if (unlikely (status)) {
-	if (have_clip)
-	    _cairo_clip_fini (&local_clip);
-
-	return status;
-    }
-
-    if (_cairo_path_fixed_stroke_is_rectilinear (path)) {
-	cairo_boxes_t boxes;
-
-	_cairo_boxes_init (&boxes);
-	_cairo_boxes_limit (&boxes, clip_boxes, num_boxes);
-	status = _cairo_path_fixed_stroke_rectilinear_to_boxes (path,
-								stroke_style,
-								ctm,
-								&boxes);
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = _clip_and_composite_boxes (dst, op, source,
-						&boxes, antialias,
-						&extents, clip);
-	}
-
-	_cairo_boxes_fini (&boxes);
-
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    goto CLEANUP_BOXES;
-    }
-
-    _cairo_polygon_init (&info.polygon, clip_boxes, num_boxes);
-
-    status = _cairo_path_fixed_stroke_to_polygon (path,
-						  stroke_style,
-						  ctm, ctm_inverse,
-						  tolerance,
-						  &info.polygon);
-    if (unlikely (status))
-	goto CLEANUP_POLYGON;
-
-    if (extents.is_bounded) {
-	cairo_rectangle_int_t rect;
-
-	_cairo_box_round_to_rectangle (&info.polygon.extents, &rect);
-	if (! _cairo_rectangle_intersect (&extents.bounded, &rect))
-	    goto CLEANUP_POLYGON;
-    }
-
-    if (info.polygon.num_edges == 0) {
-	if (! extents.is_bounded)
-	    status = i965_fixup_unbounded (dst, &extents, clip);
-    } else {
-	info.fill_rule = CAIRO_FILL_RULE_WINDING;
-	info.antialias = antialias;
-	status = i965_clip_and_composite_spans (dst, op, source, antialias,
-						_composite_polygon_spans, &info,
-						&extents, clip);
-    }
-
-CLEANUP_POLYGON:
-    _cairo_polygon_fini (&info.polygon);
-
-CLEANUP_BOXES:
-    if (clip_boxes != boxes_stack)
-	free (clip_boxes);
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static cairo_int_status_t
-i965_surface_fill (void			*abstract_dst,
-		   cairo_operator_t	 op,
-		   const cairo_pattern_t*source,
-		   cairo_path_fixed_t	*path,
-		   cairo_fill_rule_t	 fill_rule,
-		   double		 tolerance,
-		   cairo_antialias_t	 antialias,
-		   cairo_clip_t		*clip)
-{
-    i965_surface_t *dst = abstract_dst;
-    cairo_composite_rectangles_t extents;
-    composite_polygon_info_t info;
-    cairo_box_t boxes_stack[32], *clip_boxes = boxes_stack;
-    cairo_clip_t local_clip;
-    cairo_bool_t have_clip = FALSE;
-    int num_boxes = ARRAY_LENGTH (boxes_stack);
-    cairo_status_t status;
-
-    status = _cairo_composite_rectangles_init_for_fill (&extents,
-							dst->intel.drm.width,
-							dst->intel.drm.height,
-							op, source, path,
-							clip);
-    if (unlikely (status))
-	return status;
-
-    if (clip != NULL && _cairo_clip_contains_extents (clip, &extents))
-	clip = NULL;
-
-    if (clip != NULL) {
-	clip = _cairo_clip_init_copy (&local_clip, clip);
-	have_clip = TRUE;
-    }
-
-    status = _cairo_clip_to_boxes (&clip, &extents, &clip_boxes, &num_boxes);
-    if (unlikely (status)) {
-	if (have_clip)
-	    _cairo_clip_fini (&local_clip);
-
-	return status;
-    }
-
-    assert (! _cairo_path_fixed_fill_is_empty (path));
-
-    if (_cairo_path_fixed_fill_is_rectilinear (path)) {
-	cairo_boxes_t boxes;
-
-	_cairo_boxes_init (&boxes);
-	_cairo_boxes_limit (&boxes, clip_boxes, num_boxes);
-	status = _cairo_path_fixed_fill_rectilinear_to_boxes (path,
-							      fill_rule,
-							      &boxes);
-	if (likely (status == CAIRO_STATUS_SUCCESS)) {
-	    status = _clip_and_composite_boxes (dst, op, source,
-						&boxes, antialias,
-						&extents, clip);
-	}
-
-	_cairo_boxes_fini (&boxes);
-
-	if (status != CAIRO_INT_STATUS_UNSUPPORTED)
-	    goto CLEANUP_BOXES;
-    }
-
-    _cairo_polygon_init (&info.polygon, clip_boxes, num_boxes);
-
-    status = _cairo_path_fixed_fill_to_polygon (path, tolerance, &info.polygon);
-    if (unlikely (status))
-	goto CLEANUP_POLYGON;
-
-    if (extents.is_bounded) {
-	cairo_rectangle_int_t rect;
-
-	_cairo_box_round_to_rectangle (&info.polygon.extents, &rect);
-	if (! _cairo_rectangle_intersect (&extents.bounded, &rect))
-	    goto CLEANUP_POLYGON;
-    }
-
-    if (info.polygon.num_edges == 0) {
-	if (! extents.is_bounded)
-	    status = i965_fixup_unbounded (dst, &extents, clip);
-    } else {
-	info.fill_rule = fill_rule;
-	info.antialias = antialias;
-	status = i965_clip_and_composite_spans (dst, op, source, antialias,
-						_composite_polygon_spans, &info,
-						&extents, clip);
-    }
-
-CLEANUP_POLYGON:
-    _cairo_polygon_fini (&info.polygon);
-
-CLEANUP_BOXES:
-    if (clip_boxes != boxes_stack)
-	free (clip_boxes);
-
-    if (have_clip)
-	_cairo_clip_fini (&local_clip);
-
-    return status;
-}
-
-static const cairo_surface_backend_t i965_surface_backend = {
-    CAIRO_SURFACE_TYPE_DRM,
-    _cairo_default_context_create,
-
-    i965_surface_create_similar,
-    i965_surface_finish,
-
-    NULL,
-    intel_surface_acquire_source_image,
-    intel_surface_release_source_image,
-
-    NULL, NULL, NULL,
-    NULL, /* composite */
-    NULL, /* fill */
-    NULL, /* trapezoids */
-    NULL, /* span */
-    NULL, /* check-span */
-
-    NULL, /* copy_page */
-    NULL, /* show_page */
-    _cairo_drm_surface_get_extents,
-    NULL, /* old-glyphs */
-    _cairo_drm_surface_get_font_options,
-
-    i965_surface_flush,
-    NULL, /* mark_dirty */
-    intel_scaled_font_fini,
-    intel_scaled_glyph_fini,
-
-    i965_surface_paint,
-    i965_surface_mask,
-    i965_surface_stroke,
-    i965_surface_fill,
-    i965_surface_glyphs,
-};
-
-static void
-i965_surface_init (i965_surface_t *surface,
-		   cairo_drm_device_t *device,
-	           cairo_format_t format,
-		   int width, int height)
-{
-    intel_surface_init (&surface->intel, &i965_surface_backend, device,
-			format, width, height);
-    surface->stream = 0;
-}
-
-static inline int cairo_const
-i965_tiling_stride (uint32_t tiling, int stride)
-{
-    if (tiling == I915_TILING_NONE)
-	return stride;
-
-    return (stride + 127) & -128;
-}
-
-static inline int cairo_const
-i965_tiling_height (uint32_t tiling, int height)
-{
-    switch (tiling) {
-    default:
-    case I915_TILING_NONE: return (height + 1) & -2;
-    case I915_TILING_X: return (height + 7) & -8;
-    case I915_TILING_Y: return (height + 31) & -32;
-    }
-}
-
-cairo_surface_t *
-i965_surface_create_internal (cairo_drm_device_t *base_dev,
-		              cairo_format_t format,
-			      int width, int height,
-			      uint32_t tiling,
-			      cairo_bool_t gpu_target)
-{
-    i965_surface_t *surface;
-    cairo_status_t status_ignored;
-
-    surface = _cairo_malloc (sizeof (i965_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    i965_surface_init (surface, base_dev, format, width, height);
-
-    if (width && height) {
-	uint32_t size, stride;
-	intel_bo_t *bo;
-
-	width = (width + 3) & -4;
-	stride = cairo_format_stride_for_width (surface->intel.drm.format, width);
-	stride = (stride + 63) & ~63;
-	stride = i965_tiling_stride (tiling, stride);
-	surface->intel.drm.stride = stride;
-
-	height = i965_tiling_height (tiling, height);
-	assert (height <= I965_MAX_SIZE);
-
-	size = stride * height;
-	bo = intel_bo_create (to_intel_device (&base_dev->base),
-			      size, size,
-			      gpu_target, tiling, stride);
-	if (bo == NULL) {
-	    status_ignored = _cairo_drm_surface_finish (&surface->intel.drm);
-	    free (surface);
-	    return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-	}
-
-	bo->tiling = tiling;
-	bo->stride = stride;
-	surface->intel.drm.bo = &bo->base;
-
-	assert (bo->base.size >= (size_t) stride*height);
-    }
-
-    return &surface->intel.drm.base;
-}
-
-static cairo_surface_t *
-i965_surface_create (cairo_drm_device_t *device,
-		     cairo_format_t format, int width, int height)
-{
-    switch (format) {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB16_565:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_A8:
-	break;
-    case CAIRO_FORMAT_INVALID:
-    default:
-    case CAIRO_FORMAT_A1:
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-    }
-
-    return i965_surface_create_internal (device, format, width, height,
-	                                 I965_TILING_DEFAULT, TRUE);
-}
-
-static cairo_surface_t *
-i965_surface_create_for_name (cairo_drm_device_t *base_dev,
-			      unsigned int name,
-			      cairo_format_t format,
-			      int width, int height, int stride)
-{
-    i965_device_t *device;
-    i965_surface_t *surface;
-    cairo_status_t status_ignored;
-    int min_stride;
-
-    min_stride = cairo_format_stride_for_width (format, (width + 3) & -4);
-    if (stride < min_stride || stride & 63)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
-
-    if (format == CAIRO_FORMAT_A1)
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-
-    switch (format) {
-    case CAIRO_FORMAT_ARGB32:
-    case CAIRO_FORMAT_RGB16_565:
-    case CAIRO_FORMAT_RGB24:
-    case CAIRO_FORMAT_A8:
-	break;
-    case CAIRO_FORMAT_INVALID:
-    default:
-    case CAIRO_FORMAT_A1:
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
-    }
-
-    surface = _cairo_malloc (sizeof (i965_surface_t));
-    if (unlikely (surface == NULL))
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-
-    i965_surface_init (surface, base_dev, format, width, height);
-
-    device = (i965_device_t *) base_dev;
-    surface->intel.drm.bo = &intel_bo_create_for_name (&device->intel, name)->base;
-    if (unlikely (surface->intel.drm.bo == NULL)) {
-	status_ignored = _cairo_drm_surface_finish (&surface->intel.drm);
-	free (surface);
-	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
-    }
-
-    surface->intel.drm.stride = stride;
-
-    return &surface->intel.drm.base;
-}
-
-static cairo_status_t
-i965_surface_enable_scan_out (void *abstract_surface)
-{
-    i965_surface_t *surface = abstract_surface;
-    intel_bo_t *bo;
-
-    if (unlikely (surface->intel.drm.bo == NULL))
-	return _cairo_error (CAIRO_STATUS_INVALID_SIZE);
-
-    bo = to_intel_bo (surface->intel.drm.bo);
-    if (bo->tiling != I915_TILING_X) {
-	i965_device_t *device = i965_device (surface);
-	cairo_surface_pattern_t pattern;
-	cairo_surface_t *clone;
-	cairo_status_t status;
-
-	clone = i965_surface_create_internal (&device->intel.base,
-					      surface->intel.drm.base.content,
-					      surface->intel.drm.width,
-					      surface->intel.drm.height,
-					      I915_TILING_X,
-					      TRUE);
-	if (unlikely (clone->status))
-	    return clone->status;
-
-	/* 2D blit? */
-	_cairo_pattern_init_for_surface (&pattern, &surface->intel.drm.base);
-	pattern.base.filter = CAIRO_FILTER_NEAREST;
-
-	status = _cairo_surface_paint (clone,
-				       CAIRO_OPERATOR_SOURCE,
-				       &pattern.base,
-				       NULL);
-
-	_cairo_pattern_fini (&pattern.base);
-
-	if (unlikely (status)) {
-	    cairo_surface_destroy (clone);
-	    return status;
-	}
-
-	/* swap buffer objects */
-	surface->intel.drm.bo = ((cairo_drm_surface_t *) clone)->bo;
-	((cairo_drm_surface_t *) clone)->bo = &bo->base;
-	bo = to_intel_bo (surface->intel.drm.bo);
-
-	cairo_surface_destroy (clone);
-    }
-
-    if (unlikely (bo->tiling == I915_TILING_Y))
-	return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); /* XXX */
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-static cairo_int_status_t
-_i965_device_flush (cairo_drm_device_t *device)
-{
-    cairo_status_t status;
-
-    if (unlikely (device->base.finished))
-	return CAIRO_STATUS_SUCCESS;
-
-    status = cairo_device_acquire (&device->base);
-    if (likely (status == CAIRO_STATUS_SUCCESS))
-	status = i965_device_flush ((i965_device_t *) device);
-
-    cairo_device_release (&device->base);
-
-    return status;
-}
-
-static cairo_int_status_t
-_i965_device_throttle (cairo_drm_device_t *device)
-{
-    cairo_status_t status;
-
-    status = cairo_device_acquire (&device->base);
-    if (unlikely (status))
-	return status;
-
-    status = i965_device_flush ((i965_device_t *) device);
-    intel_throttle ((intel_device_t *) device);
-
-    cairo_device_release (&device->base);
-
-    return status;
-}
-
-static void
-_i965_device_destroy (void *base)
-{
-    i965_device_t *device = base;
-
-    i965_device_reset (device);
-    i965_general_state_reset (device);
-
-    _cairo_hash_table_destroy (device->sf_states);
-    _cairo_hash_table_destroy (device->samplers);
-    _cairo_hash_table_destroy (device->cc_states);
-    _cairo_hash_table_destroy (device->wm_kernels);
-    _cairo_hash_table_destroy (device->wm_states);
-    _cairo_hash_table_destroy (device->wm_bindings);
-
-    _cairo_freelist_fini (&device->sf_freelist);
-    _cairo_freelist_fini (&device->cc_freelist);
-    _cairo_freelist_fini (&device->wm_kernel_freelist);
-    _cairo_freelist_fini (&device->wm_state_freelist);
-    _cairo_freelist_fini (&device->wm_binding_freelist);
-    _cairo_freelist_fini (&device->sampler_freelist);
-
-    intel_device_fini (&device->intel);
-    free (device);
-}
-
-static cairo_bool_t
-hash_equal (const void *A, const void *B)
-{
-    const cairo_hash_entry_t *a = A, *b = B;
-    return a->hash == b->hash;
-}
-
-cairo_drm_device_t *
-_cairo_drm_i965_device_create (int fd, dev_t dev, int vendor_id, int chip_id)
-{
-    i965_device_t *device;
-    uint64_t gtt_size;
-    cairo_status_t status;
-
-    if (! intel_info (fd, &gtt_size))
-	return  NULL;
-
-    device = _cairo_malloc (sizeof (i965_device_t));
-    if (unlikely (device == NULL))
-	return (cairo_drm_device_t *) _cairo_device_create_in_error (CAIRO_STATUS_NO_MEMORY);
-
-    status = intel_device_init (&device->intel, fd);
-    if (unlikely (status))
-	goto CLEANUP;
-
-    device->is_g4x = IS_G4X (chip_id);
-    //device->is_g5x = IS_G5X (chip_id);
-
-    device->intel.base.surface.create = i965_surface_create;
-    device->intel.base.surface.create_for_name = i965_surface_create_for_name;
-    device->intel.base.surface.create_from_cacheable_image = NULL;
-    device->intel.base.surface.enable_scan_out = i965_surface_enable_scan_out;
-
-    device->intel.base.device.flush = _i965_device_flush;
-    device->intel.base.device.throttle = _i965_device_throttle;
-    device->intel.base.device.destroy = _i965_device_destroy;
-
-    device->sf_states = _cairo_hash_table_create (i965_sf_state_equal);
-    if (unlikely (device->sf_states == NULL))
-	goto CLEANUP_INTEL;
-
-    _cairo_freelist_init (&device->sf_freelist,
-			  sizeof (struct i965_sf_state));
-
-
-    device->cc_states = _cairo_hash_table_create (i965_cc_state_equal);
-    if (unlikely (device->cc_states == NULL))
-	goto CLEANUP_SF;
-
-    _cairo_freelist_init (&device->cc_freelist,
-			  sizeof (struct i965_cc_state));
-
-
-    device->wm_kernels = _cairo_hash_table_create (hash_equal);
-    if (unlikely (device->wm_kernels == NULL))
-	goto CLEANUP_CC;
-
-    _cairo_freelist_init (&device->wm_kernel_freelist,
-			  sizeof (struct i965_wm_kernel));
-
-    device->wm_states = _cairo_hash_table_create (i965_wm_state_equal);
-    if (unlikely (device->wm_states == NULL))
-	goto CLEANUP_WM_KERNEL;
-
-    _cairo_freelist_init (&device->wm_state_freelist,
-			  sizeof (struct i965_wm_state));
-
-
-    device->wm_bindings = _cairo_hash_table_create (i965_wm_binding_equal);
-    if (unlikely (device->wm_bindings == NULL))
-	goto CLEANUP_WM_STATE;
-
-    _cairo_freelist_init (&device->wm_binding_freelist,
-			  sizeof (struct i965_wm_binding));
-
-    device->samplers = _cairo_hash_table_create (hash_equal);
-    if (unlikely (device->samplers == NULL))
-	goto CLEANUP_WM_BINDING;
-
-    _cairo_freelist_init (&device->sampler_freelist,
-			  sizeof (struct i965_sampler));
-
-    i965_stream_init (&device->batch,
-		      device->batch_base, sizeof (device->batch_base),
-		      NULL, 0,
-		      device->batch_relocations,
-		      ARRAY_LENGTH (device->batch_relocations));
-
-    i965_stream_init (&device->surface,
-		      device->surface_base, sizeof (device->surface_base),
-		      device->surface_pending_relocations,
-		      ARRAY_LENGTH (device->surface_pending_relocations),
-		      device->surface_relocations,
-		      ARRAY_LENGTH (device->surface_relocations));
-
-    i965_stream_init (&device->general,
-		      device->general_base, sizeof (device->general_base),
-		      device->general_pending_relocations,
-		      ARRAY_LENGTH (device->general_pending_relocations),
-		      NULL, 0);
-
-    i965_stream_init (&device->vertex,
-		      device->vertex_base, sizeof (device->vertex_base),
-		      device->vertex_pending_relocations,
-		      ARRAY_LENGTH (device->vertex_pending_relocations),
-		      NULL, 0);
-
-    cairo_list_init (&device->flush);
-    i965_device_reset (device);
-    device->vs_offset = (uint32_t) -1;
-    device->border_color_offset = (uint32_t) -1;
-    device->general_state = NULL;
-
-    return _cairo_drm_device_init (&device->intel.base,
-				   fd, dev, vendor_id, chip_id,
-				   I965_MAX_SIZE);
-
-  CLEANUP_WM_BINDING:
-    _cairo_hash_table_destroy (device->wm_bindings);
-  CLEANUP_WM_STATE:
-    _cairo_hash_table_destroy (device->wm_states);
-  CLEANUP_WM_KERNEL:
-    _cairo_hash_table_destroy (device->wm_kernels);
-  CLEANUP_CC:
-    _cairo_hash_table_destroy (device->cc_states);
-  CLEANUP_SF:
-    _cairo_hash_table_destroy (device->sf_states);
-  CLEANUP_INTEL:
-    intel_device_fini (&device->intel);
-  CLEANUP:
-    free (device);
-    return (cairo_drm_device_t *) _cairo_device_create_in_error (status);
-}
diff --git a/src/drm/cairo-drm-intel-brw-defines.h b/src/drm/cairo-drm-intel-brw-defines.h
deleted file mode 100644
index b2be36f18..000000000
--- a/src/drm/cairo-drm-intel-brw-defines.h
+++ /dev/null
@@ -1,824 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2005 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 CAIRO_DRM_INTEL_BRW_DEFINES_H
-#define CAIRO_DRM_INTEL_BRW_DEFINES_H
-
-/* 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 PIPE_CONTROL_NOWRITE          0x00
-#define PIPE_CONTROL_WRITEIMMEDIATE   0x01
-#define PIPE_CONTROL_WRITEDEPTH       0x02
-#define PIPE_CONTROL_WRITETIMESTAMP   0x03
-
-#define PIPE_CONTROL_GTTWRITE_PROCESS_LOCAL 0x00
-#define PIPE_CONTROL_GTTWRITE_GLOBAL        0x01
-
-#define BRW_3D(Pipeline,Opcode,Subopcode) ((3 << 29) | \
-					   ((Pipeline) << 27) | \
-					   ((Opcode) << 24) | \
-					   ((Subopcode) << 16))
-
-#define BRW_PIPE_CONTROL			BRW_3D(3, 2, 0)
-#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_WRITE_TIME    (3 << 14)
-#define BRW_PIPE_CONTROL_DEPTH_STALL   (1 << 13)
-#define BRW_PIPE_CONTROL_WC_FLUSH      (1 << 12)
-#define BRW_PIPE_CONTROL_IS_FLUSH      (1 << 11)
-#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 _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 BRW_ANISORATIO_2     0
-#define BRW_ANISORATIO_4     1
-#define BRW_ANISORATIO_6     2
-#define BRW_ANISORATIO_8     3
-#define BRW_ANISORATIO_10    4
-#define BRW_ANISORATIO_12    5
-#define BRW_ANISORATIO_14    6
-#define BRW_ANISORATIO_16    7
-
-#define BRW_BLENDFACTOR_ONE                 0x1
-#define BRW_BLENDFACTOR_SRC_COLOR           0x2
-#define BRW_BLENDFACTOR_SRC_ALPHA           0x3
-#define BRW_BLENDFACTOR_DST_ALPHA           0x4
-#define BRW_BLENDFACTOR_DST_COLOR           0x5
-#define BRW_BLENDFACTOR_SRC_ALPHA_SATURATE  0x6
-#define BRW_BLENDFACTOR_CONST_COLOR         0x7
-#define BRW_BLENDFACTOR_CONST_ALPHA         0x8
-#define BRW_BLENDFACTOR_SRC1_COLOR          0x9
-#define BRW_BLENDFACTOR_SRC1_ALPHA          0x0A
-#define BRW_BLENDFACTOR_ZERO                0x11
-#define BRW_BLENDFACTOR_INV_SRC_COLOR       0x12
-#define BRW_BLENDFACTOR_INV_SRC_ALPHA       0x13
-#define BRW_BLENDFACTOR_INV_DST_ALPHA       0x14
-#define BRW_BLENDFACTOR_INV_DST_COLOR       0x15
-#define BRW_BLENDFACTOR_INV_CONST_COLOR     0x17
-#define BRW_BLENDFACTOR_INV_CONST_ALPHA     0x18
-#define BRW_BLENDFACTOR_INV_SRC1_COLOR      0x19
-#define BRW_BLENDFACTOR_INV_SRC1_ALPHA      0x1A
-
-#define BRW_BLENDFUNCTION_ADD               0
-#define BRW_BLENDFUNCTION_SUBTRACT          1
-#define BRW_BLENDFUNCTION_REVERSE_SUBTRACT  2
-#define BRW_BLENDFUNCTION_MIN               3
-#define BRW_BLENDFUNCTION_MAX               4
-
-#define BRW_ALPHATEST_FORMAT_UNORM8         0
-#define BRW_ALPHATEST_FORMAT_FLOAT32        1
-
-#define BRW_CHROMAKEY_KILL_ON_ANY_MATCH  0
-#define BRW_CHROMAKEY_REPLACE_BLACK      1
-
-#define BRW_CLIP_API_OGL     0
-#define BRW_CLIP_API_DX      1
-
-#define BRW_CLIPMODE_NORMAL              0
-#define BRW_CLIPMODE_CLIP_ALL            1
-#define BRW_CLIPMODE_CLIP_NON_REJECTED   2
-#define BRW_CLIPMODE_REJECT_ALL          3
-#define BRW_CLIPMODE_ACCEPT_ALL          4
-
-#define BRW_CLIP_NDCSPACE     0
-#define BRW_CLIP_SCREENSPACE  1
-
-#define BRW_COMPAREFUNCTION_ALWAYS       0
-#define BRW_COMPAREFUNCTION_NEVER        1
-#define BRW_COMPAREFUNCTION_LESS         2
-#define BRW_COMPAREFUNCTION_EQUAL        3
-#define BRW_COMPAREFUNCTION_LEQUAL       4
-#define BRW_COMPAREFUNCTION_GREATER      5
-#define BRW_COMPAREFUNCTION_NOTEQUAL     6
-#define BRW_COMPAREFUNCTION_GEQUAL       7
-
-#define BRW_COVERAGE_PIXELS_HALF     0
-#define BRW_COVERAGE_PIXELS_1        1
-#define BRW_COVERAGE_PIXELS_2        2
-#define BRW_COVERAGE_PIXELS_4        3
-
-#define BRW_CULLMODE_BOTH        0
-#define BRW_CULLMODE_NONE        1
-#define BRW_CULLMODE_FRONT       2
-#define BRW_CULLMODE_BACK        3
-
-#define BRW_DEFAULTCOLOR_R8G8B8A8_UNORM      0
-#define BRW_DEFAULTCOLOR_R32G32B32A32_FLOAT  1
-
-#define BRW_DEPTHFORMAT_D32_FLOAT_S8X24_UINT     0
-#define BRW_DEPTHFORMAT_D32_FLOAT                1
-#define BRW_DEPTHFORMAT_D24_UNORM_S8_UINT        2
-#define BRW_DEPTHFORMAT_D16_UNORM                5
-
-#define BRW_FLOATING_POINT_IEEE_754        0
-#define BRW_FLOATING_POINT_NON_IEEE_754    1
-
-#define BRW_FRONTWINDING_CW      0
-#define BRW_FRONTWINDING_CCW     1
-
-#define BRW_INDEX_BYTE     0
-#define BRW_INDEX_WORD     1
-#define BRW_INDEX_DWORD    2
-
-#define BRW_LOGICOPFUNCTION_CLEAR            0
-#define BRW_LOGICOPFUNCTION_NOR              1
-#define BRW_LOGICOPFUNCTION_AND_INVERTED     2
-#define BRW_LOGICOPFUNCTION_COPY_INVERTED    3
-#define BRW_LOGICOPFUNCTION_AND_REVERSE      4
-#define BRW_LOGICOPFUNCTION_INVERT           5
-#define BRW_LOGICOPFUNCTION_XOR              6
-#define BRW_LOGICOPFUNCTION_NAND             7
-#define BRW_LOGICOPFUNCTION_AND              8
-#define BRW_LOGICOPFUNCTION_EQUIV            9
-#define BRW_LOGICOPFUNCTION_NOOP             10
-#define BRW_LOGICOPFUNCTION_OR_INVERTED      11
-#define BRW_LOGICOPFUNCTION_COPY             12
-#define BRW_LOGICOPFUNCTION_OR_REVERSE       13
-#define BRW_LOGICOPFUNCTION_OR               14
-#define BRW_LOGICOPFUNCTION_SET              15
-
-#define BRW_MAPFILTER_NEAREST        0x0
-#define BRW_MAPFILTER_LINEAR         0x1
-#define BRW_MAPFILTER_ANISOTROPIC    0x2
-
-#define BRW_MIPFILTER_NONE        0
-#define BRW_MIPFILTER_NEAREST     1
-#define BRW_MIPFILTER_LINEAR      3
-
-#define BRW_POLYGON_FRONT_FACING     0
-#define BRW_POLYGON_BACK_FACING      1
-
-#define BRW_PREFILTER_ALWAYS     0x0
-#define BRW_PREFILTER_NEVER      0x1
-#define BRW_PREFILTER_LESS       0x2
-#define BRW_PREFILTER_EQUAL      0x3
-#define BRW_PREFILTER_LEQUAL     0x4
-#define BRW_PREFILTER_GREATER    0x5
-#define BRW_PREFILTER_NOTEQUAL   0x6
-#define BRW_PREFILTER_GEQUAL     0x7
-
-#define BRW_PROVOKING_VERTEX_0    0
-#define BRW_PROVOKING_VERTEX_1    1
-#define BRW_PROVOKING_VERTEX_2    2
-
-#define BRW_RASTRULE_UPPER_LEFT  0
-#define BRW_RASTRULE_UPPER_RIGHT 1
-
-#define BRW_RENDERTARGET_CLAMPRANGE_UNORM    0
-#define BRW_RENDERTARGET_CLAMPRANGE_SNORM    1
-#define BRW_RENDERTARGET_CLAMPRANGE_FORMAT   2
-
-#define BRW_STENCILOP_KEEP               0
-#define BRW_STENCILOP_ZERO               1
-#define BRW_STENCILOP_REPLACE            2
-#define BRW_STENCILOP_INCRSAT            3
-#define BRW_STENCILOP_DECRSAT            4
-#define BRW_STENCILOP_INCR               5
-#define BRW_STENCILOP_DECR               6
-#define BRW_STENCILOP_INVERT             7
-
-#define BRW_SURFACE_MIPMAPLAYOUT_BELOW   0
-#define BRW_SURFACE_MIPMAPLAYOUT_RIGHT   1
-
-#define BRW_SURFACEFORMAT_R32G32B32A32_FLOAT             0x000 
-#define BRW_SURFACEFORMAT_R32G32B32A32_SINT              0x001 
-#define BRW_SURFACEFORMAT_R32G32B32A32_UINT              0x002 
-#define BRW_SURFACEFORMAT_R32G32B32A32_UNORM             0x003 
-#define BRW_SURFACEFORMAT_R32G32B32A32_SNORM             0x004 
-#define BRW_SURFACEFORMAT_R64G64_FLOAT                   0x005 
-#define BRW_SURFACEFORMAT_R32G32B32X32_FLOAT             0x006 
-#define BRW_SURFACEFORMAT_R32G32B32A32_SSCALED           0x007
-#define BRW_SURFACEFORMAT_R32G32B32A32_USCALED           0x008
-#define BRW_SURFACEFORMAT_R32G32B32_FLOAT                0x040 
-#define BRW_SURFACEFORMAT_R32G32B32_SINT                 0x041 
-#define BRW_SURFACEFORMAT_R32G32B32_UINT                 0x042 
-#define BRW_SURFACEFORMAT_R32G32B32_UNORM                0x043 
-#define BRW_SURFACEFORMAT_R32G32B32_SNORM                0x044 
-#define BRW_SURFACEFORMAT_R32G32B32_SSCALED              0x045 
-#define BRW_SURFACEFORMAT_R32G32B32_USCALED              0x046 
-#define BRW_SURFACEFORMAT_R16G16B16A16_UNORM             0x080 
-#define BRW_SURFACEFORMAT_R16G16B16A16_SNORM             0x081 
-#define BRW_SURFACEFORMAT_R16G16B16A16_SINT              0x082 
-#define BRW_SURFACEFORMAT_R16G16B16A16_UINT              0x083 
-#define BRW_SURFACEFORMAT_R16G16B16A16_FLOAT             0x084 
-#define BRW_SURFACEFORMAT_R32G32_FLOAT                   0x085 
-#define BRW_SURFACEFORMAT_R32G32_SINT                    0x086 
-#define BRW_SURFACEFORMAT_R32G32_UINT                    0x087 
-#define BRW_SURFACEFORMAT_R32_FLOAT_X8X24_TYPELESS       0x088 
-#define BRW_SURFACEFORMAT_X32_TYPELESS_G8X24_UINT        0x089 
-#define BRW_SURFACEFORMAT_L32A32_FLOAT                   0x08A 
-#define BRW_SURFACEFORMAT_R32G32_UNORM                   0x08B 
-#define BRW_SURFACEFORMAT_R32G32_SNORM                   0x08C 
-#define BRW_SURFACEFORMAT_R64_FLOAT                      0x08D 
-#define BRW_SURFACEFORMAT_R16G16B16X16_UNORM             0x08E 
-#define BRW_SURFACEFORMAT_R16G16B16X16_FLOAT             0x08F 
-#define BRW_SURFACEFORMAT_A32X32_FLOAT                   0x090 
-#define BRW_SURFACEFORMAT_L32X32_FLOAT                   0x091 
-#define BRW_SURFACEFORMAT_I32X32_FLOAT                   0x092 
-#define BRW_SURFACEFORMAT_R16G16B16A16_SSCALED           0x093
-#define BRW_SURFACEFORMAT_R16G16B16A16_USCALED           0x094
-#define BRW_SURFACEFORMAT_R32G32_SSCALED                 0x095
-#define BRW_SURFACEFORMAT_R32G32_USCALED                 0x096
-#define BRW_SURFACEFORMAT_B8G8R8A8_UNORM                 0x0C0 
-#define BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB            0x0C1 
-#define BRW_SURFACEFORMAT_R10G10B10A2_UNORM              0x0C2 
-#define BRW_SURFACEFORMAT_R10G10B10A2_UNORM_SRGB         0x0C3 
-#define BRW_SURFACEFORMAT_R10G10B10A2_UINT               0x0C4 
-#define BRW_SURFACEFORMAT_R10G10B10_SNORM_A2_UNORM       0x0C5 
-#define BRW_SURFACEFORMAT_R8G8B8A8_UNORM                 0x0C7 
-#define BRW_SURFACEFORMAT_R8G8B8A8_UNORM_SRGB            0x0C8 
-#define BRW_SURFACEFORMAT_R8G8B8A8_SNORM                 0x0C9 
-#define BRW_SURFACEFORMAT_R8G8B8A8_SINT                  0x0CA 
-#define BRW_SURFACEFORMAT_R8G8B8A8_UINT                  0x0CB 
-#define BRW_SURFACEFORMAT_R16G16_UNORM                   0x0CC 
-#define BRW_SURFACEFORMAT_R16G16_SNORM                   0x0CD 
-#define BRW_SURFACEFORMAT_R16G16_SINT                    0x0CE 
-#define BRW_SURFACEFORMAT_R16G16_UINT                    0x0CF 
-#define BRW_SURFACEFORMAT_R16G16_FLOAT                   0x0D0 
-#define BRW_SURFACEFORMAT_B10G10R10A2_UNORM              0x0D1 
-#define BRW_SURFACEFORMAT_B10G10R10A2_UNORM_SRGB         0x0D2 
-#define BRW_SURFACEFORMAT_R11G11B10_FLOAT                0x0D3 
-#define BRW_SURFACEFORMAT_R32_SINT                       0x0D6 
-#define BRW_SURFACEFORMAT_R32_UINT                       0x0D7 
-#define BRW_SURFACEFORMAT_R32_FLOAT                      0x0D8 
-#define BRW_SURFACEFORMAT_R24_UNORM_X8_TYPELESS          0x0D9 
-#define BRW_SURFACEFORMAT_X24_TYPELESS_G8_UINT           0x0DA 
-#define BRW_SURFACEFORMAT_L16A16_UNORM                   0x0DF 
-#define BRW_SURFACEFORMAT_I24X8_UNORM                    0x0E0 
-#define BRW_SURFACEFORMAT_L24X8_UNORM                    0x0E1 
-#define BRW_SURFACEFORMAT_A24X8_UNORM                    0x0E2 
-#define BRW_SURFACEFORMAT_I32_FLOAT                      0x0E3 
-#define BRW_SURFACEFORMAT_L32_FLOAT                      0x0E4 
-#define BRW_SURFACEFORMAT_A32_FLOAT                      0x0E5 
-#define BRW_SURFACEFORMAT_B8G8R8X8_UNORM                 0x0E9 
-#define BRW_SURFACEFORMAT_B8G8R8X8_UNORM_SRGB            0x0EA 
-#define BRW_SURFACEFORMAT_R8G8B8X8_UNORM                 0x0EB 
-#define BRW_SURFACEFORMAT_R8G8B8X8_UNORM_SRGB            0x0EC 
-#define BRW_SURFACEFORMAT_R9G9B9E5_SHAREDEXP             0x0ED 
-#define BRW_SURFACEFORMAT_B10G10R10X2_UNORM              0x0EE 
-#define BRW_SURFACEFORMAT_L16A16_FLOAT                   0x0F0 
-#define BRW_SURFACEFORMAT_R32_UNORM                      0x0F1 
-#define BRW_SURFACEFORMAT_R32_SNORM                      0x0F2 
-#define BRW_SURFACEFORMAT_R10G10B10X2_USCALED            0x0F3
-#define BRW_SURFACEFORMAT_R8G8B8A8_SSCALED               0x0F4
-#define BRW_SURFACEFORMAT_R8G8B8A8_USCALED               0x0F5
-#define BRW_SURFACEFORMAT_R16G16_SSCALED                 0x0F6
-#define BRW_SURFACEFORMAT_R16G16_USCALED                 0x0F7
-#define BRW_SURFACEFORMAT_R32_SSCALED                    0x0F8
-#define BRW_SURFACEFORMAT_R32_USCALED                    0x0F9
-#define BRW_SURFACEFORMAT_B5G6R5_UNORM                   0x100 
-#define BRW_SURFACEFORMAT_B5G6R5_UNORM_SRGB              0x101 
-#define BRW_SURFACEFORMAT_B5G5R5A1_UNORM                 0x102 
-#define BRW_SURFACEFORMAT_B5G5R5A1_UNORM_SRGB            0x103 
-#define BRW_SURFACEFORMAT_B4G4R4A4_UNORM                 0x104 
-#define BRW_SURFACEFORMAT_B4G4R4A4_UNORM_SRGB            0x105 
-#define BRW_SURFACEFORMAT_R8G8_UNORM                     0x106 
-#define BRW_SURFACEFORMAT_R8G8_SNORM                     0x107 
-#define BRW_SURFACEFORMAT_R8G8_SINT                      0x108 
-#define BRW_SURFACEFORMAT_R8G8_UINT                      0x109 
-#define BRW_SURFACEFORMAT_R16_UNORM                      0x10A 
-#define BRW_SURFACEFORMAT_R16_SNORM                      0x10B 
-#define BRW_SURFACEFORMAT_R16_SINT                       0x10C 
-#define BRW_SURFACEFORMAT_R16_UINT                       0x10D 
-#define BRW_SURFACEFORMAT_R16_FLOAT                      0x10E 
-#define BRW_SURFACEFORMAT_I16_UNORM                      0x111 
-#define BRW_SURFACEFORMAT_L16_UNORM                      0x112 
-#define BRW_SURFACEFORMAT_A16_UNORM                      0x113 
-#define BRW_SURFACEFORMAT_L8A8_UNORM                     0x114 
-#define BRW_SURFACEFORMAT_I16_FLOAT                      0x115
-#define BRW_SURFACEFORMAT_L16_FLOAT                      0x116
-#define BRW_SURFACEFORMAT_A16_FLOAT                      0x117 
-#define BRW_SURFACEFORMAT_R5G5_SNORM_B6_UNORM            0x119 
-#define BRW_SURFACEFORMAT_B5G5R5X1_UNORM                 0x11A 
-#define BRW_SURFACEFORMAT_B5G5R5X1_UNORM_SRGB            0x11B
-#define BRW_SURFACEFORMAT_R8G8_SSCALED                   0x11C
-#define BRW_SURFACEFORMAT_R8G8_USCALED                   0x11D
-#define BRW_SURFACEFORMAT_R16_SSCALED                    0x11E
-#define BRW_SURFACEFORMAT_R16_USCALED                    0x11F
-#define BRW_SURFACEFORMAT_R8_UNORM                       0x140 
-#define BRW_SURFACEFORMAT_R8_SNORM                       0x141 
-#define BRW_SURFACEFORMAT_R8_SINT                        0x142 
-#define BRW_SURFACEFORMAT_R8_UINT                        0x143 
-#define BRW_SURFACEFORMAT_A8_UNORM                       0x144 
-#define BRW_SURFACEFORMAT_I8_UNORM                       0x145 
-#define BRW_SURFACEFORMAT_L8_UNORM                       0x146 
-#define BRW_SURFACEFORMAT_P4A4_UNORM                     0x147 
-#define BRW_SURFACEFORMAT_A4P4_UNORM                     0x148
-#define BRW_SURFACEFORMAT_R8_SSCALED                     0x149
-#define BRW_SURFACEFORMAT_R8_USCALED                     0x14A
-#define BRW_SURFACEFORMAT_R1_UINT                        0x181 
-#define BRW_SURFACEFORMAT_YCRCB_NORMAL                   0x182 
-#define BRW_SURFACEFORMAT_YCRCB_SWAPUVY                  0x183 
-#define BRW_SURFACEFORMAT_BC1_UNORM                      0x186 
-#define BRW_SURFACEFORMAT_BC2_UNORM                      0x187 
-#define BRW_SURFACEFORMAT_BC3_UNORM                      0x188 
-#define BRW_SURFACEFORMAT_BC4_UNORM                      0x189 
-#define BRW_SURFACEFORMAT_BC5_UNORM                      0x18A 
-#define BRW_SURFACEFORMAT_BC1_UNORM_SRGB                 0x18B 
-#define BRW_SURFACEFORMAT_BC2_UNORM_SRGB                 0x18C 
-#define BRW_SURFACEFORMAT_BC3_UNORM_SRGB                 0x18D 
-#define BRW_SURFACEFORMAT_MONO8                          0x18E 
-#define BRW_SURFACEFORMAT_YCRCB_SWAPUV                   0x18F 
-#define BRW_SURFACEFORMAT_YCRCB_SWAPY                    0x190 
-#define BRW_SURFACEFORMAT_DXT1_RGB                       0x191 
-#define BRW_SURFACEFORMAT_FXT1                           0x192 
-#define BRW_SURFACEFORMAT_R8G8B8_UNORM                   0x193 
-#define BRW_SURFACEFORMAT_R8G8B8_SNORM                   0x194 
-#define BRW_SURFACEFORMAT_R8G8B8_SSCALED                 0x195 
-#define BRW_SURFACEFORMAT_R8G8B8_USCALED                 0x196 
-#define BRW_SURFACEFORMAT_R64G64B64A64_FLOAT             0x197 
-#define BRW_SURFACEFORMAT_R64G64B64_FLOAT                0x198 
-#define BRW_SURFACEFORMAT_BC4_SNORM                      0x199 
-#define BRW_SURFACEFORMAT_BC5_SNORM                      0x19A 
-#define BRW_SURFACEFORMAT_R16G16B16_UNORM                0x19C 
-#define BRW_SURFACEFORMAT_R16G16B16_SNORM                0x19D 
-#define BRW_SURFACEFORMAT_R16G16B16_SSCALED              0x19E 
-#define BRW_SURFACEFORMAT_R16G16B16_USCALED              0x19F
-
-#define BRW_SURFACERETURNFORMAT_FLOAT32  0
-#define BRW_SURFACERETURNFORMAT_S1       1
-
-#define BRW_SURFACE_1D      0
-#define BRW_SURFACE_2D      1
-#define BRW_SURFACE_3D      2
-#define BRW_SURFACE_CUBE    3
-#define BRW_SURFACE_BUFFER  4
-#define BRW_SURFACE_NULL    7
-
-#define BRW_BORDER_COLOR_MODE_DEFAULT	0
-#define BRW_BORDER_COLOR_MODE_LEGACY	1
-
-#define BRW_TEXCOORDMODE_WRAP            0
-#define BRW_TEXCOORDMODE_MIRROR          1
-#define BRW_TEXCOORDMODE_CLAMP           2
-#define BRW_TEXCOORDMODE_CUBE            3
-#define BRW_TEXCOORDMODE_CLAMP_BORDER    4
-#define BRW_TEXCOORDMODE_MIRROR_ONCE     5
-
-#define BRW_THREAD_PRIORITY_NORMAL   0
-#define BRW_THREAD_PRIORITY_HIGH     1
-
-#define BRW_TILEWALK_XMAJOR                 0
-#define BRW_TILEWALK_YMAJOR                 1
-
-#define BRW_VERTEX_SUBPIXEL_PRECISION_8BITS  0
-#define BRW_VERTEX_SUBPIXEL_PRECISION_4BITS  1
-
-#define BRW_VERTEXBUFFER_ACCESS_VERTEXDATA     0
-#define BRW_VERTEXBUFFER_ACCESS_INSTANCEDATA   1
-
-#define BRW_VFCOMPONENT_NOSTORE      0
-#define BRW_VFCOMPONENT_STORE_SRC    1
-#define BRW_VFCOMPONENT_STORE_0      2
-#define BRW_VFCOMPONENT_STORE_1_FLT  3
-#define BRW_VFCOMPONENT_STORE_1_INT  4
-#define BRW_VFCOMPONENT_STORE_VID    5
-#define BRW_VFCOMPONENT_STORE_IID    6
-#define BRW_VFCOMPONENT_STORE_PID    7
-
-
-
-/* Execution Unit (EU) defines */
-
-#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
-
-#define BRW_COMPRESSION_NONE          0
-#define BRW_COMPRESSION_2NDHALF       1
-#define BRW_COMPRESSION_COMPRESSED    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_C     7
-#define BRW_CONDITIONAL_O     8
-
-#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
-
-#define BRW_OPCODE_MOV        1
-#define BRW_OPCODE_SEL        2
-#define BRW_OPCODE_NOT        4
-#define BRW_OPCODE_AND        5
-#define BRW_OPCODE_OR         6
-#define BRW_OPCODE_XOR        7
-#define BRW_OPCODE_SHR        8
-#define BRW_OPCODE_SHL        9
-#define BRW_OPCODE_RSR        10
-#define BRW_OPCODE_RSL        11
-#define BRW_OPCODE_ASR        12
-#define BRW_OPCODE_CMP        16
-#define BRW_OPCODE_JMPI       32
-#define BRW_OPCODE_IF         34
-#define BRW_OPCODE_IFF        35
-#define BRW_OPCODE_ELSE       36
-#define BRW_OPCODE_ENDIF      37
-#define BRW_OPCODE_DO         38
-#define BRW_OPCODE_WHILE      39
-#define BRW_OPCODE_BREAK      40
-#define BRW_OPCODE_CONTINUE   41
-#define BRW_OPCODE_HALT       42
-#define BRW_OPCODE_MSAVE      44
-#define BRW_OPCODE_MRESTORE   45
-#define BRW_OPCODE_PUSH       46
-#define BRW_OPCODE_POP        47
-#define BRW_OPCODE_WAIT       48
-#define BRW_OPCODE_SEND       49
-#define BRW_OPCODE_ADD        64
-#define BRW_OPCODE_MUL        65
-#define BRW_OPCODE_AVG        66
-#define BRW_OPCODE_FRC        67
-#define BRW_OPCODE_RNDU       68
-#define BRW_OPCODE_RNDD       69
-#define BRW_OPCODE_RNDE       70
-#define BRW_OPCODE_RNDZ       71
-#define BRW_OPCODE_MAC        72
-#define BRW_OPCODE_MACH       73
-#define BRW_OPCODE_LZD        74
-#define BRW_OPCODE_SAD2       80
-#define BRW_OPCODE_SADA2      81
-#define BRW_OPCODE_DP4        84
-#define BRW_OPCODE_DPH        85
-#define BRW_OPCODE_DP3        86
-#define BRW_OPCODE_DP2        87
-#define BRW_OPCODE_DPA2       88
-#define BRW_OPCODE_LINE       89
-#define BRW_OPCODE_NOP        126
-
-#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_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
-#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 BRW_SAMPLER_RETURN_FORMAT_FLOAT32     0
-#define BRW_SAMPLER_RETURN_FORMAT_UINT32      2
-#define BRW_SAMPLER_RETURN_FORMAT_SINT32      3
-
-#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_SIMD4X2_RESINFO           2
-#define BRW_SAMPLER_MESSAGE_SIMD8_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 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
-
-#define BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ          0
-#define BRW_DATAPORT_READ_MESSAGE_OWORD_DUAL_BLOCK_READ     1
-#define BRW_DATAPORT_READ_MESSAGE_DWORD_BLOCK_READ          2
-#define BRW_DATAPORT_READ_MESSAGE_DWORD_SCATTERED_READ      3
-
-#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
-
-#define BRW_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE                0
-#define BRW_DATAPORT_WRITE_MESSAGE_OWORD_DUAL_BLOCK_WRITE           1
-#define BRW_DATAPORT_WRITE_MESSAGE_DWORD_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
-
-#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
-#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 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 BRW_VFE_MODE_GENERIC		0x0
-#define BRW_VFE_MODE_VLD_MPEG2		0x1
-#define BRW_VFE_MODE_IS			0x2
-#define BRW_VFE_MODE_AVC_MC		0x4
-#define BRW_VFE_MODE_AVC_IT		0x7
-#define BRW_VFE_MODE_VC1_IT		0xB
-
-#define BRW_VFE_DEBUG_COUNTER_FREE	0
-#define BRW_VFE_DEBUG_COUNTER_FROZEN	1
-#define BRW_VFE_DEBUG_COUNTER_ONCE	2
-#define BRW_VFE_DEBUG_COUNTER_ALWAYS	3
-
-/* VLD_STATE */
-#define BRW_MPEG_TOP_FIELD		1
-#define BRW_MPEG_BOTTOM_FIELD		2
-#define BRW_MPEG_FRAME			3
-#define BRW_MPEG_QSCALE_LINEAR		0
-#define BRW_MPEG_QSCALE_NONLINEAR	1
-#define BRW_MPEG_ZIGZAG_SCAN		0
-#define BRW_MPEG_ALTER_VERTICAL_SCAN	1
-#define BRW_MPEG_I_PICTURE		1
-#define BRW_MPEG_P_PICTURE		2
-#define BRW_MPEG_B_PICTURE		3
-
-#endif
diff --git a/src/drm/cairo-drm-intel-brw-eu-emit.c b/src/drm/cairo-drm-intel-brw-eu-emit.c
deleted file mode 100644
index f27b23804..000000000
--- a/src/drm/cairo-drm-intel-brw-eu-emit.c
+++ /dev/null
@@ -1,1089 +0,0 @@
-/*
-   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 at tungstengraphics.com>
- */
-
-#include "cairoint.h"
-#include "cairo-drm-intel-brw-eu.h"
-
-#include <string.h>
-
-/***********************************************************************
- * Internal helper for constructing instructions
- */
-
-static void guess_execution_size( struct brw_instruction *insn,
-				  struct brw_reg reg )
-{
-    if (reg.width == BRW_WIDTH_8 &&
-	insn->header.compression_control == BRW_COMPRESSION_COMPRESSED)
-	insn->header.execution_size = BRW_EXECUTE_16;
-    else
-	insn->header.execution_size = reg.width;	/* note - definitions are compatible */
-}
-
-
-void
-brw_instruction_set_destination (struct brw_instruction *insn,
-				 struct brw_reg 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;
-	}
-    } 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;
-	}
-    }
-
-    /* NEW: Set the execution size based on dest.width and
-     * insn->compression_control:
-     */
-    guess_execution_size(insn, dest);
-}
-
-void
-brw_instruction_set_source0 (struct brw_instruction *insn,
-			     struct brw_reg reg)
-{
-    assert(reg.file != BRW_MESSAGE_REGISTER_FILE);
-
-    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_instruction *insn,
-		   struct brw_reg reg )
-{
-    assert(reg.file != BRW_MESSAGE_REGISTER_FILE);
-
-    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;
-	}
-    }
-}
-
-
-
-static void brw_set_math_message( struct brw_instruction *insn,
-				  uint32_t msg_length,
-				  uint32_t response_length,
-				  uint32_t function,
-				  uint32_t integer_type,
-				  int low_precision,
-				  int saturate,
-				  uint32_t dataType )
-{
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    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;
-    insn->bits3.math.response_length = response_length;
-    insn->bits3.math.msg_length = msg_length;
-    insn->bits3.math.msg_target = BRW_MESSAGE_TARGET_MATH;
-    insn->bits3.math.end_of_thread = 0;
-}
-
-static void brw_set_urb_message( struct brw_instruction *insn,
-				 int allocate,
-				 int used,
-				 uint32_t msg_length,
-				 uint32_t response_length,
-				 int end_of_thread,
-				 int complete,
-				 uint32_t offset,
-				 uint32_t swizzle_control )
-{
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    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;
-    insn->bits3.urb.response_length = response_length;
-    insn->bits3.urb.msg_length = msg_length;
-    insn->bits3.urb.msg_target = BRW_MESSAGE_TARGET_URB;
-    insn->bits3.urb.end_of_thread = end_of_thread;
-}
-
-void
-brw_instruction_set_dp_write_message (struct brw_instruction *insn,
-				      uint32_t binding_table_index,
-				      uint32_t msg_control,
-				      uint32_t msg_type,
-				      uint32_t msg_length,
-				      uint32_t pixel_scoreboard_clear,
-				      uint32_t response_length,
-				      uint32_t end_of_thread)
-{
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    insn->bits3.dp_write.binding_table_index = binding_table_index;
-    insn->bits3.dp_write.msg_control = msg_control;
-    insn->bits3.dp_write.pixel_scoreboard_clear = pixel_scoreboard_clear;
-    insn->bits3.dp_write.msg_type = msg_type;
-    insn->bits3.dp_write.send_commit_msg = 0;
-    insn->bits3.dp_write.response_length = response_length;
-    insn->bits3.dp_write.msg_length = msg_length;
-    insn->bits3.dp_write.msg_target = BRW_MESSAGE_TARGET_DATAPORT_WRITE;
-    insn->bits3.urb.end_of_thread = end_of_thread;
-}
-
-static void brw_set_dp_read_message( struct brw_instruction *insn,
-				     uint32_t binding_table_index,
-				     uint32_t msg_control,
-				     uint32_t msg_type,
-				     uint32_t target_cache,
-				     uint32_t msg_length,
-				     uint32_t response_length,
-				     uint32_t end_of_thread )
-{
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    insn->bits3.dp_read.binding_table_index = binding_table_index;
-    insn->bits3.dp_read.msg_control = msg_control;
-    insn->bits3.dp_read.msg_type = msg_type;
-    insn->bits3.dp_read.target_cache = target_cache;
-    insn->bits3.dp_read.response_length = response_length;
-    insn->bits3.dp_read.msg_length = msg_length;
-    insn->bits3.dp_read.msg_target = BRW_MESSAGE_TARGET_DATAPORT_READ;
-    insn->bits3.dp_read.end_of_thread = end_of_thread;
-}
-
-static void
-brw_set_sampler_message (struct brw_instruction *insn,
-			 cairo_bool_t is_g4x,
-			 uint32_t binding_table_index,
-			 uint32_t sampler,
-			 uint32_t msg_type,
-			 uint32_t response_length,
-			 uint32_t msg_length,
-			 cairo_bool_t eot)
-{
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    if (is_g4x) {
-	/* XXX presume the driver is sane! */
-	insn->bits3.sampler_g4x.binding_table_index = binding_table_index;
-	insn->bits3.sampler_g4x.sampler = sampler;
-	insn->bits3.sampler_g4x.msg_type = msg_type;
-	insn->bits3.sampler_g4x.response_length = response_length;
-	insn->bits3.sampler_g4x.msg_length = msg_length;
-	insn->bits3.sampler_g4x.end_of_thread = eot;
-	insn->bits3.sampler_g4x.msg_target = BRW_MESSAGE_TARGET_SAMPLER;
-    } 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;
-	insn->bits3.sampler.response_length = response_length;
-	insn->bits3.sampler.msg_length = msg_length;
-	insn->bits3.sampler.end_of_thread = eot;
-	insn->bits3.sampler.msg_target = BRW_MESSAGE_TARGET_SAMPLER;
-    }
-}
-
-struct brw_instruction *
-brw_next_instruction (struct brw_compile *p,
-		      uint32_t opcode)
-{
-    struct brw_instruction *insn;
-
-    assert(p->nr_insn + 1 < BRW_EU_MAX_INSN);
-
-    insn = &p->store[p->nr_insn++];
-    memcpy(insn, p->current, sizeof(*insn));
-
-    /* Reset this one-shot flag: */
-    if (p->current->header.destreg__conditonalmod) {
-	p->current->header.destreg__conditonalmod = 0;
-	p->current->header.predicate_control = BRW_PREDICATE_NORMAL;
-    }
-
-    insn->header.opcode = opcode;
-    return insn;
-}
-
-static struct brw_instruction *brw_alu1( struct brw_compile *p,
-					 uint32_t opcode,
-					 struct brw_reg dest,
-					 struct brw_reg src )
-{
-    struct brw_instruction *insn = brw_next_instruction(p, opcode);
-    brw_instruction_set_destination(insn, dest);
-    brw_instruction_set_source0(insn, src);
-    return insn;
-}
-
-static struct brw_instruction *brw_alu2(struct brw_compile *p,
-					uint32_t opcode,
-					struct brw_reg dest,
-					struct brw_reg src0,
-					struct brw_reg src1 )
-{
-    struct brw_instruction *insn = brw_next_instruction(p, opcode);
-    brw_instruction_set_destination(insn, dest);
-    brw_instruction_set_source0(insn, src0);
-    brw_set_src1(insn, src1);
-    return insn;
-}
-
-
-/***********************************************************************
- * Convenience routines.
- */
-#define ALU1(OP)					\
-    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)					\
-    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);	\
-}
-
-
-    ALU1(MOV)
-    ALU2(SEL)
-    ALU1(NOT)
-    ALU2(AND)
-    ALU2(OR)
-    ALU2(XOR)
-    ALU2(SHR)
-    ALU2(SHL)
-    ALU2(RSR)
-    ALU2(RSL)
-    ALU2(ASR)
-    ALU2(ADD)
-    ALU2(MUL)
-    ALU1(FRC)
-    ALU1(RNDD)
-    ALU1(RNDZ)
-    ALU2(MAC)
-    ALU2(MACH)
-    ALU1(LZD)
-    ALU2(DP4)
-    ALU2(DPH)
-    ALU2(DP3)
-    ALU2(DP2)
-ALU2(LINE)
-
-
-
-
-void brw_NOP(struct brw_compile *p)
-{
-    struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_NOP);
-    brw_instruction_set_destination(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD));
-    brw_instruction_set_source0(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD));
-    brw_set_src1(insn, brw_imm_ud(0x0));
-}
-
-
-
-
-
-/***********************************************************************
- * Comparisons, if/else/endif
- */
-
-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);
-
-    p->current->header.predicate_control = BRW_PREDICATE_NONE;
-
-    return insn;
-}
-
-/* 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 relevant flags are inverted.
- *
- * When the matching 'endif' instruction is reached, the flags are
- * popped off.  If the stack is now empty, normal execution resumes.
- *
- * No attempt is made to deal with stack overflow (14 elements?).
- */
-struct brw_instruction *brw_IF(struct brw_compile *p, uint32_t execute_size)
-{
-    struct brw_instruction *insn;
-
-    if (p->single_program_flow) {
-	assert(execute_size == BRW_EXECUTE_1);
-
-	insn = brw_next_instruction(p, BRW_OPCODE_ADD);
-	insn->header.predicate_inverse = 1;
-    } else {
-	insn = brw_next_instruction(p, BRW_OPCODE_IF);
-    }
-
-    /* Override the defaults for this instruction:
-    */
-    brw_instruction_set_destination (insn, brw_ip_reg ());
-    brw_instruction_set_source0 (insn, brw_ip_reg ());
-    brw_set_src1 (insn, brw_imm_d (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;
-
-    return insn;
-}
-
-
-struct brw_instruction *brw_ELSE(struct brw_compile *p,
-				 struct brw_instruction *if_insn)
-{
-    struct brw_instruction *insn;
-
-    if (p->single_program_flow) {
-	insn = brw_next_instruction(p, BRW_OPCODE_ADD);
-    } else {
-	insn = brw_next_instruction(p, BRW_OPCODE_ELSE);
-    }
-
-    brw_instruction_set_destination (insn, brw_ip_reg ());
-    brw_instruction_set_source0 (insn, brw_ip_reg ());
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    insn->header.compression_control = BRW_COMPRESSION_NONE;
-    insn->header.execution_size = if_insn->header.execution_size;
-    insn->header.mask_control = BRW_MASK_ENABLE;
-    if (!p->single_program_flow)
-	insn->header.thread_control = BRW_THREAD_SWITCH;
-
-    /* Patch the if instruction to point at this instruction.
-    */
-    if (p->single_program_flow) {
-	assert(if_insn->header.opcode == BRW_OPCODE_ADD);
-
-	if_insn->bits3.ud = (insn - if_insn + 1) * 16;
-    } else {
-	assert(if_insn->header.opcode == BRW_OPCODE_IF);
-
-	if_insn->bits3.if_else.jump_count = insn - if_insn;
-	if_insn->bits3.if_else.pop_count = 1;
-	if_insn->bits3.if_else.pad0 = 0;
-    }
-
-    return insn;
-}
-
-void brw_ENDIF(struct brw_compile *p,
-	       struct brw_instruction *patch_insn)
-{
-    if (p->single_program_flow) {
-	/* In single program flow mode, there's no need to execute an ENDIF,
-	 * since we don't need to do any stack operations, and if we're executing
-	 * currently, we want to just continue executing.
-	 */
-	struct brw_instruction *next = &p->store[p->nr_insn];
-
-	assert(patch_insn->header.opcode == BRW_OPCODE_ADD);
-
-	patch_insn->bits3.ud = (next - patch_insn) * 16;
-    } else {
-	struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_ENDIF);
-
-	brw_instruction_set_destination(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD));
-	brw_instruction_set_source0(insn, retype(brw_vec4_grf(0,0), BRW_REGISTER_TYPE_UD));
-	brw_set_src1 (insn, brw_imm_d (0));
-
-	insn->header.compression_control = BRW_COMPRESSION_NONE;
-	insn->header.execution_size = patch_insn->header.execution_size;
-	insn->header.mask_control = BRW_MASK_ENABLE;
-	insn->header.thread_control = BRW_THREAD_SWITCH;
-
-	assert(patch_insn->bits3.if_else.jump_count == 0);
-
-	/* Patch the if or else instructions to point at this or the next
-	 * instruction respectively.
-	 */
-	if (patch_insn->header.opcode == BRW_OPCODE_IF) {
-	    /* Automagically turn it into an IFF:
-	    */
-	    patch_insn->header.opcode = BRW_OPCODE_IFF;
-	    patch_insn->bits3.if_else.jump_count = insn - patch_insn + 1;
-	    patch_insn->bits3.if_else.pop_count = 0;
-	    patch_insn->bits3.if_else.pad0 = 0;
-	} else if (patch_insn->header.opcode == BRW_OPCODE_ELSE) {
-	    patch_insn->bits3.if_else.jump_count = insn - patch_insn + 1;
-	    patch_insn->bits3.if_else.pop_count = 1;
-	    patch_insn->bits3.if_else.pad0 = 0;
-	} else {
-	    assert(0);
-	}
-
-	/* Also pop item off the stack in the endif instruction:
-	*/
-	insn->bits3.if_else.jump_count = 0;
-	insn->bits3.if_else.pop_count = 1;
-	insn->bits3.if_else.pad0 = 0;
-    }
-}
-
-struct brw_instruction *brw_BREAK(struct brw_compile *p)
-{
-    struct brw_instruction *insn;
-    insn = brw_next_instruction(p, BRW_OPCODE_BREAK);
-    brw_instruction_set_destination(insn, brw_ip_reg());
-    brw_instruction_set_source0(insn, brw_ip_reg());
-    brw_set_src1(insn, brw_imm_d (0));
-    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;
-    return insn;
-}
-
-struct brw_instruction *brw_CONT(struct brw_compile *p)
-{
-    struct brw_instruction *insn;
-    insn = brw_next_instruction(p, BRW_OPCODE_CONTINUE);
-    brw_instruction_set_destination(insn, brw_ip_reg());
-    brw_instruction_set_source0(insn, brw_ip_reg());
-    brw_set_src1 (insn, brw_imm_d (0));
-    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;
-    return insn;
-}
-
-/* DO/WHILE loop:
-*/
-struct brw_instruction *brw_DO(struct brw_compile *p, uint32_t execute_size)
-{
-    if (p->single_program_flow) {
-	return &p->store[p->nr_insn];
-    } else {
-	struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_DO);
-
-	/* Override the defaults for this instruction:
-	*/
-	brw_instruction_set_destination(insn, brw_null_reg());
-	brw_instruction_set_source0(insn, brw_null_reg());
-	brw_set_src1(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;
-
-    if (p->single_program_flow)
-	insn = brw_next_instruction(p, BRW_OPCODE_ADD);
-    else
-	insn = brw_next_instruction(p, BRW_OPCODE_WHILE);
-
-    brw_instruction_set_destination(insn, brw_ip_reg());
-    brw_instruction_set_source0(insn, brw_ip_reg());
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    insn->header.compression_control = BRW_COMPRESSION_NONE;
-
-    if (p->single_program_flow) {
-	insn->header.execution_size = BRW_EXECUTE_1;
-
-	insn->bits3.d = (do_insn - insn) * 16;
-    } else {
-	insn->header.execution_size = do_insn->header.execution_size;
-
-	assert(do_insn->header.opcode == BRW_OPCODE_DO);
-	insn->bits3.if_else.jump_count = do_insn - insn + 1;
-	insn->bits3.if_else.pop_count = 0;
-	insn->bits3.if_else.pad0 = 0;
-    }
-
-    /*    insn->header.mask_control = BRW_MASK_ENABLE; */
-
-    /* insn->header.mask_control = BRW_MASK_DISABLE; */
-    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];
-
-    assert(jmp_insn->header.opcode == BRW_OPCODE_JMPI);
-    assert(jmp_insn->bits1.da1.src1_reg_file = BRW_IMMEDIATE_VALUE);
-
-    jmp_insn->bits3.ud = (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,
-	     uint32_t conditional,
-	     struct brw_reg src0,
-	     struct brw_reg src1)
-{
-    struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_CMP);
-
-    insn->header.destreg__conditonalmod = conditional;
-    brw_instruction_set_destination(insn, dest);
-    brw_instruction_set_source0(insn, src0);
-    brw_set_src1(insn, src1);
-
-    /*    guess_execution_size(insn, src0); */
-
-
-    /* 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;
-    }
-}
-
-
-
-/***********************************************************************
- * Helpers for the various SEND message types:
- */
-
-/* Invert 8 values
-*/
-void brw_math( struct brw_compile *p,
-	       struct brw_reg dest,
-	       uint32_t function,
-	       uint32_t saturate,
-	       uint32_t msg_reg_nr,
-	       struct brw_reg src,
-	       uint32_t data_type,
-	       uint32_t precision )
-{
-    struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-    uint32_t msg_length = (function == BRW_MATH_FUNCTION_POW) ? 2 : 1;
-    uint32_t response_length = (function == BRW_MATH_FUNCTION_SINCOS) ? 2 : 1;
-
-    /* Example code doesn't set predicate_control for send
-     * instructions.
-     */
-    insn->header.predicate_control = 0;
-    insn->header.destreg__conditonalmod = msg_reg_nr;
-
-    response_length = 1;
-
-    brw_instruction_set_destination(insn, dest);
-    brw_instruction_set_source0(insn, src);
-    brw_set_math_message(insn,
-			 msg_length, response_length,
-			 function,
-			 BRW_MATH_INTEGER_UNSIGNED,
-			 precision,
-			 saturate,
-			 data_type);
-}
-
-/* Use 2 send instructions to invert 16 elements
-*/
-void brw_math_16( struct brw_compile *p,
-		  struct brw_reg dest,
-		  uint32_t function,
-		  uint32_t saturate,
-		  uint32_t msg_reg_nr,
-		  struct brw_reg src,
-		  uint32_t precision )
-{
-    struct brw_instruction *insn;
-    uint32_t msg_length = (function == BRW_MATH_FUNCTION_POW) ? 2 : 1;
-    uint32_t response_length = (function == BRW_MATH_FUNCTION_SINCOS) ? 2 : 1;
-
-    /* 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_instruction(p, BRW_OPCODE_SEND);
-    insn->header.destreg__conditonalmod = msg_reg_nr;
-
-    brw_instruction_set_destination(insn, dest);
-    brw_instruction_set_source0(insn, src);
-    brw_set_math_message(insn,
-			 msg_length, response_length,
-			 function,
-			 BRW_MATH_INTEGER_UNSIGNED,
-			 precision,
-			 saturate,
-			 BRW_MATH_DATA_VECTOR);
-
-    /* Second instruction:
-    */
-    insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-    insn->header.compression_control = BRW_COMPRESSION_2NDHALF;
-    insn->header.destreg__conditonalmod = msg_reg_nr+1;
-
-    brw_instruction_set_destination(insn, offset(dest,1));
-    brw_instruction_set_source0(insn, src);
-    brw_set_math_message(insn,
-			 msg_length, response_length,
-			 function,
-			 BRW_MATH_INTEGER_UNSIGNED,
-			 precision,
-			 saturate,
-			 BRW_MATH_DATA_VECTOR);
-
-    brw_pop_insn_state(p);
-}
-
-
-
-
-void brw_dp_WRITE_16( struct brw_compile *p,
-		      struct brw_reg src,
-		      uint32_t msg_reg_nr,
-		      uint32_t scratch_offset )
-{
-    {
-	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_D),
-		brw_imm_d (scratch_offset));
-
-	brw_pop_insn_state(p);
-    }
-
-    {
-	uint32_t msg_length = 3;
-	struct brw_reg dest = retype(brw_null_reg(), BRW_REGISTER_TYPE_UW);
-	struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-
-	insn->header.predicate_control = 0; /* XXX */
-	insn->header.compression_control = BRW_COMPRESSION_NONE;
-	insn->header.destreg__conditonalmod = msg_reg_nr;
-
-	brw_instruction_set_destination(insn, dest);
-	brw_instruction_set_source0(insn, src);
-
-	brw_instruction_set_dp_write_message(insn,
-					     255, /* bti */
-					     BRW_DATAPORT_OWORD_BLOCK_4_OWORDS, /* msg_control */
-					     BRW_DATAPORT_WRITE_MESSAGE_OWORD_BLOCK_WRITE, /* msg_type */
-					     msg_length,
-					     0, /* pixel scoreboard */
-					     0, /* response_length */
-					     0); /* eot */
-    }
-
-}
-
-
-void brw_dp_READ_16( struct brw_compile *p,
-		     struct brw_reg dest,
-		     uint32_t msg_reg_nr,
-		     uint32_t scratch_offset )
-{
-    {
-	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 (brw_vec1_grf (0, 2), BRW_REGISTER_TYPE_D),
-		brw_imm_d (scratch_offset));
-
-	brw_pop_insn_state(p);
-    }
-
-    {
-	struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-
-	insn->header.predicate_control = 0; /* XXX */
-	insn->header.compression_control = BRW_COMPRESSION_NONE;
-	insn->header.destreg__conditonalmod = msg_reg_nr;
-
-	brw_instruction_set_destination(insn, dest);	/* UW? */
-	brw_instruction_set_source0(insn, retype(brw_vec8_grf(0), BRW_REGISTER_TYPE_UW));
-
-	brw_set_dp_read_message(insn,
-				255, /* bti */
-				3,  /* msg_control */
-				BRW_DATAPORT_READ_MESSAGE_OWORD_BLOCK_READ, /* msg_type */
-				1, /* target cache */
-				1, /* msg_length */
-				2, /* response_length */
-				0); /* eot */
-    }
-}
-
-
-void brw_fb_WRITE(struct brw_compile *p,
-		  struct brw_reg dest,
-		  uint32_t msg_reg_nr,
-		  struct brw_reg src0,
-		  uint32_t binding_table_index,
-		  uint32_t msg_length,
-		  uint32_t response_length,
-		  int eot)
-{
-    struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-
-    insn->header.predicate_control = 0; /* XXX */
-    insn->header.compression_control = BRW_COMPRESSION_NONE;
-    insn->header.destreg__conditonalmod = msg_reg_nr;
-
-    brw_instruction_set_destination(insn, dest);
-    brw_instruction_set_source0(insn, src0);
-    brw_instruction_set_dp_write_message(insn,
-					 binding_table_index,
-					 BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE, /* msg_control */
-					 BRW_DATAPORT_WRITE_MESSAGE_RENDER_TARGET_WRITE, /* msg_type */
-					 msg_length,
-					 1,	/* pixel scoreboard */
-					 response_length,
-					 eot);
-}
-
-
-
-void brw_SAMPLE (struct brw_compile *p,
-		 struct brw_reg dest,
-		 uint32_t msg_reg_nr,
-		 struct brw_reg src0,
-		 uint32_t binding_table_index,
-		 uint32_t sampler,
-		 uint32_t writemask,
-		 uint32_t msg_type,
-		 uint32_t response_length,
-		 uint32_t msg_length,
-		 cairo_bool_t eot)
-{
-    int need_stall = 0;
-
-    if(writemask == 0) {
-	/*       printf("%s: zero writemask??\n", __FUNCTION__); */
-	return;
-    }
-
-    /* Hardware doesn't do destination dependency checking on send
-     * instructions properly.  Add a workaround which generates the
-     * dependency by other means.  In practice it seems like this bug
-     * only crops up for texture samples, and only where registers are
-     * written by the send and then written again later without being
-     * read in between.  Luckily for us, we already track that
-     * information and use it to modify the writemask for the
-     * instruction, so that is a guide for whether a workaround is
-     * needed.
-     */
-    if (writemask != WRITEMASK_XYZW) {
-	uint32_t dst_offset = 0;
-	uint32_t i, newmask = 0, len = 0;
-
-	for (i = 0; i < 4; i++) {
-	    if (writemask & (1<<i))
-		break;
-	    dst_offset += 2;
-	}
-	for (; i < 4; i++) {
-	    if (!(writemask & (1<<i)))
-		break;
-	    newmask |= 1<<i;
-	    len++;
-	}
-
-	if (newmask != writemask) {
-	    need_stall = 1;
-	    /*	 printf("need stall %x %x\n", newmask , writemask); */
-	}
-	else {
-	    struct brw_reg m1 = brw_message_reg(msg_reg_nr);
-
-	    newmask = ~newmask & 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, m1, brw_vec8_grf(0));
-	    brw_MOV(p, get_element_ud(m1, 2), brw_imm_ud(newmask << 12));
-
-	    brw_pop_insn_state(p);
-
-	    src0 = retype(brw_null_reg(), BRW_REGISTER_TYPE_UW);
-	    dest = offset(dest, dst_offset);
-	    response_length = len * 2;
-	}
-    }
-
-    {
-	struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-
-	insn->header.predicate_control = 0; /* XXX */
-	insn->header.compression_control = BRW_COMPRESSION_NONE;
-	insn->header.destreg__conditonalmod = msg_reg_nr;
-
-	brw_instruction_set_destination(insn, dest);
-	brw_instruction_set_source0(insn, src0);
-	brw_set_sampler_message (insn, p->is_g4x,
-				 binding_table_index,
-				 sampler,
-				 msg_type,
-				 response_length,
-				 msg_length,
-				 eot);
-    }
-
-    if (need_stall)
-    {
-	struct brw_reg reg = vec8(offset(dest, response_length-1));
-
-	/*  mov (8) r9.0<1>:f    r9.0<8;8,1>:f    { Align1 }
-	*/
-	brw_push_insn_state(p);
-	brw_set_compression_control(p, 0);
-	brw_MOV(p, reg, reg);
-	brw_pop_insn_state(p);
-    }
-}
-
-/* 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,
-		   uint32_t msg_reg_nr,
-		   struct brw_reg src0,
-		   int allocate,
-		   int used,
-		   uint32_t msg_length,
-		   uint32_t response_length,
-		   int eot,
-		   int writes_complete,
-		   uint32_t offset,
-		   uint32_t swizzle)
-{
-    struct brw_instruction *insn = brw_next_instruction(p, BRW_OPCODE_SEND);
-
-    assert(msg_length < 16);
-
-    brw_instruction_set_destination (insn, dest);
-    brw_instruction_set_source0 (insn, src0);
-    brw_set_src1 (insn, brw_imm_d (0));
-
-    insn->header.destreg__conditonalmod = msg_reg_nr;
-
-    brw_set_urb_message (insn,
-			 allocate,
-			 used,
-			 msg_length,
-			 response_length,
-			 eot,
-			 writes_complete,
-			 offset,
-			 swizzle);
-}
diff --git a/src/drm/cairo-drm-intel-brw-eu-util.c b/src/drm/cairo-drm-intel-brw-eu-util.c
deleted file mode 100644
index 592235b12..000000000
--- a/src/drm/cairo-drm-intel-brw-eu-util.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
-   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 at tungstengraphics.com>
- */
-
-
-#include "cairoint.h"
-#include "cairo-drm-intel-brw-eu.h"
-
-
-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_copy4(struct brw_compile *p,
-	       struct brw_reg dst,
-	       struct brw_reg src,
-	       uint32_t count)
-{
-    uint32_t i;
-
-    dst = vec4(dst);
-    src = vec4(src);
-
-    for (i = 0; i < count; i++)
-    {
-	uint32_t delta = i*32;
-	brw_MOV(p, byte_offset(dst, delta),    byte_offset(src, delta));
-	brw_MOV(p, byte_offset(dst, delta+16), byte_offset(src, delta+16));
-    }
-}
-
-
-void brw_copy8(struct brw_compile *p,
-	       struct brw_reg dst,
-	       struct brw_reg src,
-	       uint32_t count)
-{
-    uint32_t i;
-
-    dst = vec8(dst);
-    src = vec8(src);
-
-    for (i = 0; i < count; i++)
-    {
-	uint32_t delta = i*32;
-	brw_MOV(p, byte_offset(dst, delta),    byte_offset(src, delta));
-    }
-}
-
-
-void brw_copy_indirect_to_indirect(struct brw_compile *p,
-				   struct brw_indirect dst_ptr,
-				   struct brw_indirect src_ptr,
-				   uint32_t count)
-{
-    uint32_t i;
-
-    for (i = 0; i < count; i++)
-    {
-	uint32_t delta = i*32;
-	brw_MOV(p, deref_4f(dst_ptr, delta),    deref_4f(src_ptr, delta));
-	brw_MOV(p, deref_4f(dst_ptr, delta+16), deref_4f(src_ptr, delta+16));
-    }
-}
-
-
-void brw_copy_from_indirect(struct brw_compile *p,
-			    struct brw_reg dst,
-			    struct brw_indirect ptr,
-			    uint32_t count)
-{
-    uint32_t i;
-
-    dst = vec4(dst);
-
-    for (i = 0; i < count; i++)
-    {
-	uint32_t delta = i*32;
-	brw_MOV(p, byte_offset(dst, delta),    deref_4f(ptr, delta));
-	brw_MOV(p, byte_offset(dst, delta+16), deref_4f(ptr, delta+16));
-    }
-}
diff --git a/src/drm/cairo-drm-intel-brw-eu.c b/src/drm/cairo-drm-intel-brw-eu.c
deleted file mode 100644
index 2b47d8c37..000000000
--- a/src/drm/cairo-drm-intel-brw-eu.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
-   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 at tungstengraphics.com>
- */
-
-#include "cairoint.h"
-#include "cairo-drm-intel-brw-eu.h"
-
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
-
-/* 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, uint32_t value )
-{
-    p->current->header.predicate_control = BRW_PREDICATE_NONE;
-
-    if (value != 0xff) {
-	if (value != p->flag_value) {
-	    brw_push_insn_state(p);
-	    brw_MOV(p, brw_flag_reg(), brw_imm_uw(value));
-	    p->flag_value = value;
-	    brw_pop_insn_state(p);
-	}
-
-	p->current->header.predicate_control = BRW_PREDICATE_NORMAL;
-    }
-}
-
-void brw_set_predicate_control( struct brw_compile *p, uint32_t pc )
-{
-    p->current->header.predicate_control = pc;
-}
-
-void brw_set_conditionalmod( struct brw_compile *p, uint32_t conditional )
-{
-    p->current->header.destreg__conditonalmod = conditional;
-}
-
-void brw_set_access_mode( struct brw_compile *p, uint32_t access_mode )
-{
-    p->current->header.access_mode = access_mode;
-}
-
-void brw_set_compression_control( struct brw_compile *p, int compression_control )
-{
-    p->current->header.compression_control = compression_control;
-}
-
-void brw_set_mask_control( struct brw_compile *p, uint32_t value )
-{
-    p->current->header.mask_control = value;
-}
-
-void brw_set_saturate( struct brw_compile *p, uint32_t value )
-{
-    p->current->header.saturate = value;
-}
-
-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->current++;
-}
-
-void brw_pop_insn_state( struct brw_compile *p )
-{
-    assert(p->current != p->stack);
-    p->current--;
-}
-
-/************************************************************************/
-void
-brw_compile_init (struct brw_compile *p,
-		  cairo_bool_t is_g4x)
-{
-    p->nr_insn = 0;
-    p->current = p->stack;
-    memset (p->current, 0, sizeof (p->current[0]));
-
-    p->is_g4x = is_g4x;
-
-    /* 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);
-}
-
-const uint32_t *
-brw_get_program (struct brw_compile *p,
-		 uint32_t *sz)
-{
-    *sz = p->nr_insn * sizeof (struct brw_instruction);
-    return (const uint32_t *)p->store;
-}
-
-
-
-/*
- * Subroutine calls require special attention.
- * Mesa instructions may be expanded into multiple hardware instructions
- * so the prog_instruction::BranchTarget field can't be used as an index
- * into the hardware instructions.
- *
- * The BranchTarget field isn't needed, however.  Mesa's GLSL compiler
- * emits CAL and BGNSUB instructions with labels that can be used to map
- * subroutine calls to actual subroutine code blocks.
- *
- * The structures and function here implement patching of CAL instructions
- * so they jump to the right subroutine code...
- */
-
-
-/*
- * For each OPCODE_BGNSUB we create one of these.
- */
-struct brw_glsl_label
-{
-    const char *name; /*< the label string */
-    uint32_t position;  /*< the position of the brw instruction for this label */
-    struct brw_glsl_label *next;  /*< next in linked list */
-};
-
-
-/*
- * For each OPCODE_CAL we create one of these.
- */
-struct brw_glsl_call
-{
-    uint32_t call_inst_pos;  /*< location of the CAL instruction */
-    const char *sub_name;  /*< name of subroutine to call */
-    struct brw_glsl_call *next;  /*< next in linked list */
-};
-
-
-/*
- * Called for each OPCODE_BGNSUB.
- */
-    void
-brw_save_label(struct brw_compile *c, const char *name, uint32_t position)
-{
-    struct brw_glsl_label *label = calloc(1, sizeof *label);
-    label->name = name;
-    label->position = position;
-    label->next = c->first_label;
-    c->first_label = label;
-}
-
-
-/*
- * Called for each OPCODE_CAL.
- */
-    void
-brw_save_call(struct brw_compile *c, const char *name, uint32_t call_pos)
-{
-    struct brw_glsl_call *call = calloc(1, sizeof *call);
-    call->call_inst_pos = call_pos;
-    call->sub_name = name;
-    call->next = c->first_call;
-    c->first_call = call;
-}
-
-
-/*
- * Lookup a label, return label's position/offset.
- */
-    static uint32_t
-brw_lookup_label(struct brw_compile *c, const char *name)
-{
-    const struct brw_glsl_label *label;
-    for (label = c->first_label; label; label = label->next) {
-	if (strcmp(name, label->name) == 0) {
-	    return label->position;
-	}
-    }
-    abort();  /* should never happen */
-    return ~0;
-}
-
-
-/*
- * When we're done generating code, this function is called to resolve
- * subroutine calls.
- */
-    void
-brw_resolve_cals(struct brw_compile *c)
-{
-    const struct brw_glsl_call *call;
-
-    for (call = c->first_call; call; call = call->next) {
-	const uint32_t sub_loc = brw_lookup_label(c, call->sub_name);
-	struct brw_instruction *brw_call_inst = &c->store[call->call_inst_pos];
-	struct brw_instruction *brw_sub_inst = &c->store[sub_loc];
-	int32_t offset = brw_sub_inst - brw_call_inst;
-
-	/* patch brw_inst1 to point to brw_inst2 */
-	brw_set_src1(brw_call_inst, brw_imm_d(offset * 16));
-    }
-
-    /* free linked list of calls */
-    {
-	struct brw_glsl_call *call, *next;
-	for (call = c->first_call; call; call = next) {
-	    next = call->next;
-	    free(call);
-	}
-	c->first_call = NULL;
-    }
-
-    /* free linked list of labels */
-    {
-	struct brw_glsl_label *label, *next;
-	for (label = c->first_label; label; label = next) {
-	    next = label->next;
-	    free(label);
-	}
-	c->first_label = NULL;
-    }
-}
diff --git a/src/drm/cairo-drm-intel-brw-eu.h b/src/drm/cairo-drm-intel-brw-eu.h
deleted file mode 100644
index ef6e9771e..000000000
--- a/src/drm/cairo-drm-intel-brw-eu.h
+++ /dev/null
@@ -1,1044 +0,0 @@
-/*
-   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 at tungstengraphics.com>
- */
-
-#ifndef CAIRO_DRM_INTEL_BRW_EU_H
-#define CAIRO_DRM_INTEL_BRW_EU_H
-
-#include "cairo.h"
-#include "cairo-drm-intel-brw-structs.h"
-#include "cairo-drm-intel-brw-defines.h"
-
-#include <assert.h>
-
-
-/*
- * Writemask values, 1 bit per component.
- */
-#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_XZ    (WRITEMASK_X | WRITEMASK_Z)
-#define WRITEMASK_YZ    (WRITEMASK_Y | WRITEMASK_Z)
-#define WRITEMASK_XYZ   (WRITEMASK_X | WRITEMASK_Y | WRITEMASK_Z)
-#define WRITEMASK_XW    (WRITEMASK_X | WRITEMASK_W)
-#define WRITEMASK_YW    (WRITEMASK_Y | WRITEMASK_W)
-#define WRITEMASK_XYW   (WRITEMASK_X | WRITEMASK_Y | WRITEMASK_W)
-#define WRITEMASK_ZW    (WRITEMASK_Z | WRITEMASK_W)
-#define WRITEMASK_XZW   (WRITEMASK_X | WRITEMASK_Z | WRITEMASK_W)
-#define WRITEMASK_YZW   (WRITEMASK_Y | WRITEMASK_Z | WRITEMASK_W)
-#define WRITEMASK_XYZW  (WRITEMASK_X | WRITEMASK_Y | WRITEMASK_Z | WRITEMASK_W)
-
-#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_XYXY      BRW_SWIZZLE4 (0,1,0,1)
-
-#define REG_SIZE (8*4)
-
-/* 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 {
-   uint32_t type:4;
-   uint32_t file:2;
-   uint32_t nr:8;
-   uint32_t subnr:5;		/* :1 in align16 */
-   uint32_t negate:1;		/* source only */
-   uint32_t abs:1;		/* source only */
-   uint32_t vstride:4;		/* source only */
-   uint32_t width:3;		/* src only, align1 only */
-   uint32_t hstride:2;		/* align1 only */
-   uint32_t address_mode:1;	/* relative addressing, hopefully! */
-   uint32_t pad0:1;
-
-   union {
-      struct {
-	 uint32_t swizzle:8;		/* src only, align16 only */
-	 uint32_t writemask:4;		/* dest only, align16 only */
-	 int32_t  indirect_offset:10;	/* relative addressing offset */
-	 uint32_t pad1:10;		/* two dwords total */
-      } bits;
-
-      float f;
-      int32_t   d;
-      uint32_t ud;
-   } dw1;
-};
-
-struct brw_indirect {
-   uint32_t addr_subnr:4;
-   int32_t addr_offset:10;
-   uint32_t pad:18;
-};
-
-struct brw_glsl_label;
-struct brw_glsl_call;
-
-#define BRW_EU_MAX_INSN_STACK 5
-#define BRW_EU_MAX_INSN 200
-
-struct brw_compile {
-   struct brw_instruction store[BRW_EU_MAX_INSN];
-   uint32_t nr_insn;
-
-   cairo_bool_t is_g4x;
-
-   /* Allow clients to push/pop instruction state:
-    */
-   struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
-   struct brw_instruction *current;
-
-   uint32_t flag_value;
-   int single_program_flow;
-   struct brw_context *brw;
-
-   struct brw_glsl_label *first_label;  /*< linked list of labels */
-   struct brw_glsl_call *first_call;    /*< linked list of CALs */
-};
-
-cairo_private void
-brw_save_label (struct brw_compile *c,
-		const char *name,
-		uint32_t position);
-
-cairo_private void
-brw_save_call (struct brw_compile *c,
-	       const char *name,
-	       uint32_t call_pos);
-
-cairo_private void
-brw_resolve_cals (struct brw_compile *c);
-
-static cairo_always_inline int
-type_sz (uint32_t 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 cairo_always_inline struct brw_reg
-brw_reg (uint32_t file,
-	 uint32_t nr,
-	 uint32_t subnr,
-	 uint32_t type,
-	 uint32_t vstride,
-	 uint32_t width,
-	 uint32_t hstride,
-	 uint32_t swizzle,
-	 uint32_t writemask)
-{
-   struct brw_reg reg;
-
-   if (type == BRW_GENERAL_REGISTER_FILE)
-      assert(nr < 128);
-   else if (type == BRW_MESSAGE_REGISTER_FILE)
-      assert(nr < 9);
-   else if (type == 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 cairo_always_inline struct brw_reg
-brw_vec16_reg (uint32_t file,
-	       uint32_t nr,
-	       uint32_t 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 cairo_always_inline struct brw_reg
-brw_vec8_reg (uint32_t file,
-	      uint32_t nr,
-	      uint32_t 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 cairo_always_inline struct brw_reg
-brw_vec4_reg (uint32_t file,
-	      uint32_t nr,
-	      uint32_t 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 cairo_always_inline struct brw_reg
-brw_vec2_reg (uint32_t file,
-	      uint32_t nr,
-	      uint32_t 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 cairo_always_inline struct brw_reg
-brw_vec1_reg (uint32_t file,
-	      uint32_t nr,
-	      uint32_t 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 cairo_always_inline struct brw_reg
-retype (struct brw_reg reg,
-	uint32_t type)
-{
-   reg.type = type;
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-suboffset (struct brw_reg reg,
-	   uint32_t delta)
-{
-   reg.subnr += delta * type_sz (reg.type);
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-offset (struct brw_reg reg,
-	uint32_t delta)
-{
-   reg.nr += delta;
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-byte_offset (struct brw_reg reg,
-	     uint32_t bytes)
-{
-   uint32_t 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 cairo_always_inline struct brw_reg
-brw_uw16_reg (uint32_t file,
-	      uint32_t nr,
-	      uint32_t subnr)
-{
-   return suboffset (retype (brw_vec16_reg (file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
-}
-
-/* Construct unsigned word[8] register */
-static cairo_always_inline struct brw_reg
-brw_uw8_reg (uint32_t file,
-	     uint32_t nr,
-	     uint32_t subnr)
-{
-   return suboffset (retype (brw_vec8_reg (file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
-}
-
-/* Construct unsigned word[2] register */
-static cairo_always_inline struct brw_reg
-brw_uw2_reg (uint32_t file,
-	     uint32_t nr,
-	     uint32_t subnr)
-{
-   return suboffset (retype (brw_vec2_reg (file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
-}
-
-/* Construct unsigned word[1] register */
-static cairo_always_inline struct brw_reg
-brw_uw1_reg (uint32_t file,
-	     uint32_t nr,
-	     uint32_t subnr)
-{
-   return suboffset (retype (brw_vec1_reg (file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
-}
-
-static cairo_always_inline struct brw_reg
-brw_imm_reg (uint32_t 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 cairo_always_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 cairo_always_inline struct brw_reg brw_imm_d( int32_t d )
-{
-   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_D);
-   imm.dw1.d = d;
-   return imm;
-}
-
-/* Construct uint immediate register */
-static cairo_always_inline struct brw_reg brw_imm_ud( uint32_t ud )
-{
-   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UD);
-   imm.dw1.ud = ud;
-   return imm;
-}
-
-/* Construct ushort immediate register */
-static cairo_always_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 cairo_always_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 cairo_always_inline
-struct brw_reg brw_imm_v (uint32_t 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 cairo_always_inline struct brw_reg
-brw_imm_vf (uint32_t 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 cairo_always_inline struct brw_reg
-brw_imm_vf4 (uint32_t v0,
-	     uint32_t v1,
-	     uint32_t v2,
-	     uint32_t 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 cairo_always_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 cairo_always_inline struct brw_reg
-brw_vec1_grf (uint32_t nr, uint32_t subnr)
-{
-   return brw_vec1_reg (BRW_GENERAL_REGISTER_FILE, nr, subnr);
-}
-
-/* Construct float[2] general-purpose register */
-static cairo_always_inline struct brw_reg
-brw_vec2_grf (uint32_t nr, uint32_t subnr)
-{
-   return brw_vec2_reg (BRW_GENERAL_REGISTER_FILE, nr, subnr);
-}
-
-/* Construct float[4] general-purpose register */
-static cairo_always_inline struct brw_reg
-brw_vec4_grf (uint32_t nr, uint32_t subnr)
-{
-   return brw_vec4_reg (BRW_GENERAL_REGISTER_FILE, nr, subnr);
-}
-
-/* Construct float[8] general-purpose register */
-static cairo_always_inline struct brw_reg
-brw_vec8_grf (uint32_t nr)
-{
-   return brw_vec8_reg (BRW_GENERAL_REGISTER_FILE, nr, 0);
-}
-
-static cairo_always_inline struct brw_reg
-brw_uw8_grf (uint32_t nr, uint32_t subnr)
-{
-   return brw_uw8_reg (BRW_GENERAL_REGISTER_FILE, nr, subnr);
-}
-
-static cairo_always_inline struct brw_reg
-brw_uw16_grf (uint32_t nr, uint32_t subnr)
-{
-   return brw_uw16_reg (BRW_GENERAL_REGISTER_FILE, nr, subnr);
-}
-
-/* Construct null register (usually used for setting condition codes) */
-static cairo_always_inline struct brw_reg
-brw_null_reg (void)
-{
-   return brw_vec8_reg (BRW_ARCHITECTURE_REGISTER_FILE,
-			BRW_ARF_NULL,
-			0);
-}
-
-static cairo_always_inline struct brw_reg
-brw_address_reg (uint32_t 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 cairo_always_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,
-		   WRITEMASK_XYZW);
-}
-
-static cairo_always_inline struct brw_reg
-brw_acc_reg (void)
-{
-   return brw_vec8_reg (BRW_ARCHITECTURE_REGISTER_FILE,
-			BRW_ARF_ACCUMULATOR,
-			0);
-}
-
-static cairo_always_inline struct brw_reg
-brw_flag_reg (void)
-{
-   return brw_uw1_reg (BRW_ARCHITECTURE_REGISTER_FILE,
-		       BRW_ARF_FLAG,
-		       0);
-}
-
-static cairo_always_inline struct brw_reg
-brw_mask_reg (uint32_t subnr)
-{
-   return brw_uw1_reg (BRW_ARCHITECTURE_REGISTER_FILE,
-		       BRW_ARF_MASK,
-		       subnr);
-}
-
-static cairo_always_inline struct brw_reg
-brw_message4_reg (uint32_t nr)
-{
-    return brw_vec4_reg (BRW_MESSAGE_REGISTER_FILE,
-			 nr,
-			 0);
-}
-
-static cairo_always_inline struct brw_reg
-brw_message_reg (uint32_t nr)
-{
-   return brw_vec8_reg (BRW_MESSAGE_REGISTER_FILE,
-			nr,
-			0);
-}
-
-/* This is almost always called with a numeric constant argument, so
- * make things easy to evaluate at compile time:
- */
-static cairo_always_inline uint32_t
-cvt (uint32_t 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 cairo_always_inline struct brw_reg
-stride (struct brw_reg reg,
-	uint32_t vstride,
-	uint32_t width,
-	uint32_t hstride)
-{
-   reg.vstride = cvt (vstride);
-   reg.width   = cvt (width) - 1;
-   reg.hstride = cvt (hstride);
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-vec16 (struct brw_reg reg)
-{
-   return stride (reg, 16,16,1);
-}
-
-static cairo_always_inline struct brw_reg
-vec8 (struct brw_reg reg)
-{
-   return stride (reg, 8,8,1);
-}
-
-static cairo_always_inline struct brw_reg
-vec4 (struct brw_reg reg)
-{
-   return stride (reg, 4,4,1);
-}
-
-static cairo_always_inline struct brw_reg
-vec2 (struct brw_reg reg)
-{
-   return stride (reg, 2,2,1);
-}
-
-static cairo_always_inline struct brw_reg
-vec1 (struct brw_reg reg)
-{
-   return stride (reg, 0,1,0);
-}
-
-static cairo_always_inline struct brw_reg
-get_element (struct brw_reg reg, uint32_t elt)
-{
-   return vec1 (suboffset (reg, elt));
-}
-
-static cairo_always_inline struct brw_reg
-get_element_ud (struct brw_reg reg, uint32_t elt)
-{
-   return vec1 (suboffset (retype (reg, BRW_REGISTER_TYPE_UD), elt));
-}
-
-static cairo_always_inline struct brw_reg
-brw_swizzle (struct brw_reg reg,
-	     uint32_t x,
-	     uint32_t y,
-	     uint32_t z,
-	     uint32_t w)
-{
-    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 cairo_always_inline struct brw_reg
-brw_swizzle1 (struct brw_reg reg,
-	      uint32_t x)
-{
-   return brw_swizzle (reg, x, x, x, x);
-}
-
-static cairo_always_inline struct brw_reg
-brw_writemask (struct brw_reg reg,
-	       uint32_t mask)
-{
-   reg.dw1.bits.writemask &= mask;
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-brw_set_writemask (struct brw_reg reg,
-		   uint32_t mask)
-{
-   reg.dw1.bits.writemask = mask;
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-negate (struct brw_reg reg)
-{
-   reg.negate ^= 1;
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-brw_abs (struct brw_reg reg)
-{
-   reg.abs = 1;
-   return reg;
-}
-
-static cairo_always_inline struct brw_reg
-brw_vec4_indirect (uint32_t subnr,
-		   int32_t 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 cairo_always_inline struct brw_reg
-brw_vec1_indirect (uint32_t subnr,
-		   int32_t 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 cairo_always_inline struct brw_reg
-deref_4f (struct brw_indirect ptr, int32_t offset)
-{
-   return brw_vec4_indirect (ptr.addr_subnr, ptr.addr_offset + offset);
-}
-
-static cairo_always_inline struct brw_reg
-deref_1f(struct brw_indirect ptr, int32_t offset)
-{
-   return brw_vec1_indirect (ptr.addr_subnr, ptr.addr_offset + offset);
-}
-
-static cairo_always_inline struct brw_reg
-deref_4b(struct brw_indirect ptr, int32_t offset)
-{
-   return retype (deref_4f (ptr, offset), BRW_REGISTER_TYPE_B);
-}
-
-static cairo_always_inline struct brw_reg
-deref_1uw(struct brw_indirect ptr, int32_t offset)
-{
-   return retype (deref_1f (ptr, offset), BRW_REGISTER_TYPE_UW);
-}
-
-static cairo_always_inline struct brw_reg
-deref_1d (struct brw_indirect ptr, int32_t offset)
-{
-   return retype (deref_1f (ptr, offset), BRW_REGISTER_TYPE_D);
-}
-
-static cairo_always_inline struct brw_reg
-deref_1ud (struct brw_indirect ptr, int32_t offset)
-{
-   return retype (deref_1f (ptr, offset), BRW_REGISTER_TYPE_UD);
-}
-
-static cairo_always_inline struct brw_reg
-get_addr_reg (struct brw_indirect ptr)
-{
-   return brw_address_reg (ptr.addr_subnr);
-}
-
-static cairo_always_inline struct brw_indirect
-brw_indirect_offset (struct brw_indirect ptr, int32_t offset)
-{
-   ptr.addr_offset += offset;
-   return ptr;
-}
-
-static cairo_always_inline struct brw_indirect
-brw_indirect (uint32_t addr_subnr, int32_t offset)
-{
-   struct brw_indirect ptr;
-   ptr.addr_subnr = addr_subnr;
-   ptr.addr_offset = offset;
-   ptr.pad = 0;
-   return ptr;
-}
-
-static cairo_always_inline struct brw_instruction *
-current_insn (struct brw_compile *p)
-{
-   return &p->store[p->nr_insn];
-}
-
-cairo_private void brw_pop_insn_state (struct brw_compile *p);
-cairo_private void brw_push_insn_state (struct brw_compile *p);
-cairo_private void brw_set_mask_control (struct brw_compile *p, uint32_t value);
-cairo_private void brw_set_saturate (struct brw_compile *p, uint32_t value);
-cairo_private void brw_set_access_mode (struct brw_compile *p, uint32_t access_mode);
-cairo_private void brw_set_compression_control (struct brw_compile *p, int control);
-cairo_private void brw_set_predicate_control_flag_value (struct brw_compile *p, uint32_t value);
-cairo_private void brw_set_predicate_control (struct brw_compile *p, uint32_t pc);
-cairo_private void brw_set_conditionalmod (struct brw_compile *p, uint32_t conditional);
-
-cairo_private void
-brw_compile_init (struct brw_compile *p,
-		  cairo_bool_t is_g4x);
-cairo_private const uint32_t *brw_get_program (struct brw_compile *p, uint32_t *sz);
-
-/* Helpers for regular instructions:
- */
-#define ALU1(OP)					\
-cairo_private_no_warn struct brw_instruction * \
-brw_##OP(struct brw_compile *p,	\
-	 struct brw_reg dest,			\
-	 struct brw_reg src0);
-
-#define ALU2(OP)					\
-cairo_private_no_warn struct brw_instruction * \
-brw_##OP(struct brw_compile *p,	\
-	 struct brw_reg dest,			\
-	 struct brw_reg src0,			\
-	 struct brw_reg src1);
-
-ALU1(MOV)
-ALU2(SEL)
-ALU1(NOT)
-ALU2(AND)
-ALU2(OR)
-ALU2(XOR)
-ALU2(SHR)
-ALU2(SHL)
-ALU2(RSR)
-ALU2(RSL)
-ALU2(ASR)
-ALU2(JMPI)
-ALU2(ADD)
-ALU2(MUL)
-ALU1(FRC)
-ALU1(RNDD)
-ALU1(RNDZ)
-ALU2(MAC)
-ALU2(MACH)
-ALU1(LZD)
-ALU2(DP4)
-ALU2(DPH)
-ALU2(DP3)
-ALU2(DP2)
-ALU2(LINE)
-
-#undef ALU1
-#undef ALU2
-
-/* Helpers for SEND instruction: */
-cairo_private void
-brw_urb_WRITE (struct brw_compile *p,
-	       struct brw_reg dest,
-	       uint32_t msg_reg_nr,
-	       struct brw_reg src0,
-	       int allocate,
-	       int used,
-	       uint32_t msg_length,
-	       uint32_t response_length,
-	       int eot,
-	       int writes_complete,
-	       uint32_t offset,
-	       uint32_t swizzle);
-
-cairo_private void
-brw_fb_WRITE (struct brw_compile *p,
-	      struct brw_reg dest,
-	      uint32_t msg_reg_nr,
-	      struct brw_reg src0,
-	      uint32_t binding_table_index,
-	      uint32_t msg_length,
-	      uint32_t response_length,
-	      int eot);
-
-cairo_private void
-brw_SAMPLE (struct brw_compile *p,
-	    struct brw_reg dest,
-	    uint32_t msg_reg_nr,
-	    struct brw_reg src0,
-	    uint32_t binding_table_index,
-	    uint32_t sampler,
-	    uint32_t writemask,
-	    uint32_t msg_type,
-	    uint32_t response_length,
-	    uint32_t msg_length,
-	    cairo_bool_t eot);
-
-cairo_private void
-brw_math_16 (struct brw_compile *p,
-	     struct brw_reg dest,
-	     uint32_t function,
-	     uint32_t saturate,
-	     uint32_t msg_reg_nr,
-	     struct brw_reg src,
-	     uint32_t precision);
-
-cairo_private void
-brw_math (struct brw_compile *p,
-	  struct brw_reg dest,
-	  uint32_t function,
-	  uint32_t saturate,
-	  uint32_t msg_reg_nr,
-	  struct brw_reg src,
-	  uint32_t data_type,
-	  uint32_t precision);
-
-cairo_private void
-brw_dp_READ_16 (struct brw_compile *p,
-		struct brw_reg dest,
-		uint32_t msg_reg_nr,
-		uint32_t scratch_offset);
-
-cairo_private void
-brw_dp_WRITE_16 (struct brw_compile *p,
-		 struct brw_reg src,
-		 uint32_t msg_reg_nr,
-		 uint32_t scratch_offset);
-
-/* If/else/endif.  Works by manipulating the execution flags on each
- * channel.
- */
-cairo_private struct brw_instruction *
-brw_IF (struct brw_compile *p,
-	uint32_t execute_size);
-
-cairo_private struct brw_instruction *
-brw_ELSE (struct brw_compile *p,
-	  struct brw_instruction *if_insn);
-
-cairo_private void
-brw_ENDIF (struct brw_compile *p,
-	   struct brw_instruction *if_or_else_insn);
-
-
-/* DO/WHILE loops: */
-cairo_private struct brw_instruction *
-brw_DO (struct brw_compile *p,
-	uint32_t execute_size);
-
-cairo_private struct brw_instruction *
-brw_WHILE (struct brw_compile *p,
-	   struct brw_instruction *patch_insn);
-
-cairo_private struct brw_instruction *
-brw_BREAK (struct brw_compile *p);
-
-cairo_private struct brw_instruction *
-brw_CONT (struct brw_compile *p);
-
-/* Forward jumps: */
-cairo_private void
-brw_land_fwd_jump (struct brw_compile *p,
-		  struct brw_instruction *jmp_insn);
-
-cairo_private void
-brw_NOP (struct brw_compile *p);
-
-/* Special case: there is never a destination, execution size will be
- * taken from src0:
- */
-cairo_private void
-brw_CMP (struct brw_compile *p,
-	 struct brw_reg dest,
-	 uint32_t conditional,
-	 struct brw_reg src0,
-	 struct brw_reg src1);
-
-cairo_private void
-brw_print_reg (struct brw_reg reg);
-
-cairo_private struct brw_instruction *
-brw_next_instruction (struct brw_compile *p,
-		      uint32_t opcode);
-
-cairo_private void
-brw_instruction_set_destination (struct brw_instruction *insn,
-				 struct brw_reg dest);
-
-cairo_private void
-brw_instruction_set_source0 (struct brw_instruction *insn,
-			     struct brw_reg reg);
-
-cairo_private void
-brw_instruction_set_dp_write_message (struct brw_instruction *insn,
-				      uint32_t binding_table_index,
-				      uint32_t msg_control,
-				      uint32_t msg_type,
-				      uint32_t msg_length,
-				      uint32_t pixel_scoreboard_clear,
-				      uint32_t response_length,
-				      uint32_t end_of_thread);
-
-/***********************************************************************
- * brw_eu_util.c:
- */
-
-cairo_private void
-brw_copy_indirect_to_indirect (struct brw_compile *p,
-			       struct brw_indirect dst_ptr,
-			       struct brw_indirect src_ptr,
-			       uint32_t count);
-
-cairo_private void
-brw_copy_from_indirect (struct brw_compile *p,
-		       struct brw_reg dst,
-		       struct brw_indirect ptr,
-		       uint32_t count);
-
-cairo_private void
-brw_copy4 (struct brw_compile *p,
-	   struct brw_reg dst,
-	   struct brw_reg src,
-	   uint32_t count);
-
-cairo_private void
-brw_copy8 (struct brw_compile *p,
-	   struct brw_reg dst,
-	   struct brw_reg src,
-	   uint32_t count);
-
-cairo_private void
-brw_math_invert (struct brw_compile *p,
-		 struct brw_reg dst,
-		 struct brw_reg src);
-
-cairo_private void
-brw_set_src1 (struct brw_instruction *insn,
-	      struct brw_reg reg);
-
-#endif
diff --git a/src/drm/cairo-drm-intel-brw-structs.h b/src/drm/cairo-drm-intel-brw-structs.h
deleted file mode 100644
index 3ea9c6c36..000000000
--- a/src/drm/cairo-drm-intel-brw-structs.h
+++ /dev/null
@@ -1,1329 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2005 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 CAIRO_DRM_INTEL_BRW_STRUCTS_H
-#define CAIRO_DRM_INTEL_BRW_STRUCTS_H
-
-#include "cairo.h"
-#include "cairo-types-private.h"
-
-/* Command packets:
-*/
-struct header {
-    unsigned int length:16;
-    unsigned int opcode:16;
-};
-
-union header_union {
-    struct header bits;
-    unsigned int dword;
-};
-
-struct brw_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 brw_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 BRW_FLUSH_READ_CACHE           0x1
-#define BRW_FLUSH_STATE_CACHE          0x2
-#define BRW_INHIBIT_FLUSH_RENDER_CACHE 0x4
-#define BRW_FLUSH_SNAPSHOT_COUNTERS    0x8
-
-struct brw_mi_flush {
-    unsigned int flags:4;
-    unsigned int pad:12;
-    unsigned int opcode:16;
-};
-
-struct brw_vf_statistics {
-    unsigned int statistics_enable:1;
-    unsigned int pad:15;
-    unsigned int opcode:16;
-};
-
-
-struct brw_binding_table_pointers {
-    struct header header;
-    unsigned int vs;
-    unsigned int gs;
-    unsigned int clp;
-    unsigned int sf;
-    unsigned int wm;
-};
-
-struct brw_blend_constant_color {
-    struct header header;
-    float blend_constant_color[4];
-};
-
-struct brw_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 brw_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 brw_global_depth_offset_clamp {
-    struct header header;
-    float depth_offset_clamp;
-};
-
-struct brw_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 brw_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 brw_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:6;
-	unsigned int offset:26;
-    } cc;
-};
-
-struct brw_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 brw_polygon_stipple {
-    struct header header;
-    unsigned int stipple[32];
-};
-
-struct brw_pipeline_select {
-    struct {
-	unsigned int pipeline_select:1;
-	unsigned int pad:15;
-	unsigned int opcode:16;
-    } header;
-};
-
-struct brw_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 brw_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 brw_constant_buffer_state {
-    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 brw_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 brw_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 brw_state_prefetch {
-    struct header header;
-
-    struct {
-	unsigned int prefetch_count:3;
-	unsigned int pad:3;
-	unsigned int prefetch_pointer:26;
-    } bits0;
-};
-
-struct brw_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 brw_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 brw_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 brw_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 brw_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 brw_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 brw_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;
-};
-
-/* 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 brw_sampler_default_border_color {
-    float color[4];
-};
-
-struct brw_sampler_legacy_border_color {
-    uint8_t color[4];
-};
-
-struct brw_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 brw_clipper_viewport {
-    float xmin;
-    float xmax;
-    float ymin;
-    float ymax;
-};
-
-struct brw_cc_viewport {
-    float min_depth;
-    float max_depth;
-};
-
-struct brw_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 brw_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 brw_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 BRW_VBP_MAX 17
-
-struct brw_vb_array_state {
-    struct header header;
-    struct brw_vertex_buffer_state vb[BRW_VBP_MAX];
-};
-
-struct brw_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 BRW_VEP_MAX 18
-
-struct brw_vertex_element_packet {
-    struct header header;
-    struct brw_vertex_element_state ve[BRW_VEP_MAX];
-};
-
-struct brw_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 brw_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 {
-	    uint32_t binding_table_index:8;
-	    uint32_t sampler:4;
-	    uint32_t msg_type:4;
-	    uint32_t response_length:4;
-	    uint32_t msg_length:4;
-	    uint32_t msg_target:4;
-	    uint32_t pad1:3;
-	    uint32_t end_of_thread:1;
-	} sampler_g4x;
-
-	struct brw_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;
-
-	uint32_t ud;
-	int32_t d;
-    } bits3;
-};
-
-/* media pipeline */
-
-struct brw_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 brw_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 brw_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;
-};
-
-#endif
diff --git a/src/drm/cairo-drm-intel-command-private.h b/src/drm/cairo-drm-intel-command-private.h
deleted file mode 100644
index a93ac12ab..000000000
--- a/src/drm/cairo-drm-intel-command-private.h
+++ /dev/null
@@ -1,909 +0,0 @@
-/**************************************************************************
- *
- * 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 CAIRO_DRM_INTEL_COMMAND_PRIVATE_H
-#define CAIRO_DRM_INTEL_COMMAND_PRIVATE_H
-
-#include "cairo-types-private.h"
-
-#define CMD_MI				(0x0 << 29)
-#define CMD_misc			(0x1 << 29)
-#define CMD_2D				(0x2 << 29)
-#define CMD_3D				(0x3 << 29)
-/* 4-7 reserved */
-
-#define MI_NOOP				(CMD_MI | 0)
-/* Batch */
-#define MI_BATCH_BUFFER		        (CMD_MI | (0x30 << 23) | 1)
-#define MI_BATCH_BUFFER_START	        (CMD_MI | (0x31 << 23))
-#define MI_BATCH_BUFFER_END		(CMD_MI | (0x0a << 23))
-#define MI_BATCH_NON_SECURE		(1)
-#define MI_BATCH_NON_SECURE_I965	(1 << 8)
-/* Flush */
-#define MI_FLUSH			(CMD_MI | (0x04 << 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)
-
-#define PRIM3D				(CMD_3D | (0x1f<<24))
-#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)
-#define PRIM3D_INDIRECT_SEQUENTIAL	((1<<23) | (0<<17))
-#define PRIM3D_INDIRECT_ELTS		((1<<23) | (1<<17))
-
-/* 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)
-#define BUF_3D_PITCH(x)         (x)
-/* 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_FRMT_16_FIXED		0
-#define DEPTH_FRMT_16_FLOAT		(1<<2)
-#define DEPTH_FRMT_24_FIXED_8_OTHER	(2<<2)
-#define VERT_LINE_STRIDE_1		(1<<1)
-#define VERT_LINE_STRIDE_0		(0<<1)
-#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)			((x)<<16)
-#define DRAW_XMIN(x)			(x)
-/* Dword 3 */
-#define DRAW_YMAX(x)			((x-1)<<16)
-#define DRAW_XMAX(x)			(x-1)
-/* Dword 4 */
-#define DRAW_YORG(x)			((x)<<16)
-#define DRAW_XORG(x)			(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   (CMD_3D | (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               (~0U)
-
-#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 COMPAREFUNC_ALWAYS		0
-#define COMPAREFUNC_NEVER		0x1
-#define COMPAREFUNC_LESS		0x2
-#define COMPAREFUNC_EQUAL		0x3
-#define COMPAREFUNC_LEQUAL		0x4
-#define COMPAREFUNC_GREATER		0x5
-#define COMPAREFUNC_NOTEQUAL		0x6
-#define COMPAREFUNC_GEQUAL		0x7
-
-#define STENCILOP_KEEP			0
-#define STENCILOP_ZERO			0x1
-#define STENCILOP_REPLACE		0x2
-#define STENCILOP_INCRSAT		0x3
-#define STENCILOP_DECRSAT		0x4
-#define STENCILOP_INCR			0x5
-#define STENCILOP_DECR			0x6
-#define STENCILOP_INVERT		0x7
-
-#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)
-
-/* BLT commands */
-#define COLOR_BLT_CMD		        (CMD_2D | (0x40 << 22) | 3)
-#define XY_COLOR_BLT_CMD		(CMD_2D | (0x50 << 22) | 4)
-#define XY_SETUP_CLIP_BLT_CMD		(CMD_2D | (0x03 << 22) | 1)
-#define XY_SRC_COPY_BLT_CMD             (CMD_2D | (0x53 << 22) | 6)
-#define SRC_COPY_BLT_CMD		(CMD_2D | (0x43 << 22) | 4)
-
-#define XY_MONO_PAT_BLT_CMD		(CMD_2D  | (0x52<<22)|0x7)
-#define XY_MONO_PAT_VERT_SEED		((1<<10) | (1<<9)|(1<<8))
-#define XY_MONO_PAT_HORT_SEED		((1<<14) | (1<<13)|(1<<12))
-#define XY_MONO_SRC_BLT_CMD		(CMD_2D  | (0x54<<22)|(0x6))
-
-#define XY_SETUP_BLT_CMD		(CMD_2D | (0x01 << 22) | 6)
-#define XY_TEXT_IMMEDIATE_BLIT_CMD	(CMD_2D | (0x31 << 22))
-#define XY_TEXT_BYTE_PACKED		(1 << 16)
-
-/* BR00 */
-#define XY_BLT_WRITE_ALPHA	(1 << 21)
-#define XY_BLT_WRITE_RGB	(1 << 20)
-#define XY_SRC_TILED		(1 << 15)
-#define XY_DST_TILED		(1 << 11)
-
-/* BR13 */
-#define BR13_565		(0x1 << 24)
-#define BR13_8888		(0x3 << 24)
-
-#endif /* CAIRO_DRM_INTEL_COMMAND_PRIVATE_H */
diff --git a/src/drm/cairo-drm-intel-debug.c b/src/drm/cairo-drm-intel-debug.c
deleted file mode 100644
index bfe513667..000000000
--- a/src/drm/cairo-drm-intel-debug.c
+++ /dev/null
@@ -1,1209 +0,0 @@
-/**************************************************************************
- *
- * 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.
- *
- **************************************************************************/
-
-#include "cairoint.h"
-#include "cairo-drm-intel-private.h"
-
-struct debug_stream {
-    unsigned offset;	/* current gtt offset */
-    const char *ptr;		/* pointer to gtt offset zero */
-    const char *end;		/* pointer to gtt offset zero */
-};
-
-static cairo_bool_t
-debug (struct debug_stream *stream, const char *name, uint32_t len)
-{
-    uint32_t i;
-    const uint32_t *ptr = (uint32_t *)(stream->ptr + stream->offset);
-
-    if (len == 0) {
-	fprintf (stderr, "Error - zero length packet (0x%08x)\n", stream->ptr[0]);
-	ASSERT_NOT_REACHED;
-	return FALSE;
-    }
-
-    fprintf (stderr, "%04x:  ", stream->offset);
-
-    fprintf (stderr, "%s (%d dwords):\n", name, len);
-    for (i = 0; i < len; i++)
-	fprintf (stderr, "\t0x%08x\n",  ptr[i]);
-    fprintf (stderr, "\n");
-
-    stream->offset += len * sizeof(uint32_t);
-    return TRUE;
-}
-
-
-static const char *
-get_prim_name (uint32_t val)
-{
-    switch (val & PRIM3D_MASK) {
-    case PRIM3D_TRILIST: return "TRILIST";
-    case PRIM3D_TRISTRIP: return "TRISTRIP";
-    case PRIM3D_TRISTRIP_RVRSE: return "TRISTRIP_RVRSE";
-    case PRIM3D_TRIFAN: return "TRIFAN";
-    case PRIM3D_POLY: return "POLY";
-    case PRIM3D_LINELIST: return "LINELIST";
-    case PRIM3D_LINESTRIP: return "LINESTRIP";
-    case PRIM3D_RECTLIST: return "RECTLIST";
-    case PRIM3D_POINTLIST: return "POINTLIST";
-    case PRIM3D_DIB: return "DIB";
-    case PRIM3D_CLEAR_RECT: return "CLEAR_RECT";
-    case PRIM3D_ZONE_INIT: return "ZONE_INIT";
-    default: return "????";
-    }
-}
-
-static cairo_bool_t
-debug_prim (struct debug_stream *stream,
-	    const char *name,
-	    cairo_bool_t dump_floats,
-	    uint32_t len)
-{
-    uint32_t *ptr = (uint32_t *)(stream->ptr + stream->offset);
-    const char *prim = get_prim_name( ptr[0] );
-    uint32_t i;
-
-    fprintf (stderr, "%04x:  ", stream->offset);
-    fprintf (stderr, "%s %s (%d dwords):\n", name, prim, len);
-    fprintf (stderr, "\t0x%08x\n",  ptr[0]);
-    for (i = 1; i < len; i++) {
-	if (dump_floats)
-	    fprintf (stderr, "\t0x%08x // %f\n",  ptr[i], *(float *)&ptr[i]);
-	else
-	    fprintf (stderr, "\t0x%08x\n",  ptr[i]);
-    }
-
-    fprintf (stderr, "\n");
-
-    stream->offset += len * sizeof(uint32_t);
-    return TRUE;
-}
-
-static const char *opcodes[] = {
-    "NOP",
-    "ADD",
-    "MOV",
-    "MUL",
-    "MAD",
-    "DP2ADD",
-    "DP3",
-    "DP4",
-    "FRC",
-    "RCP",
-    "RSQ",
-    "EXP",
-    "LOG",
-    "CMP",
-    "MIN",
-    "MAX",
-    "FLR",
-    "MOD",
-    "TRC",
-    "SGE",
-    "SLT",
-    "TEXLD",
-    "TEXLDP",
-    "TEXLDB",
-    "TEXKILL",
-    "DCL",
-    "0x1a",
-    "0x1b",
-    "0x1c",
-    "0x1d",
-    "0x1e",
-    "0x1f",
-};
-
-static const int args[] = {
-    0,                           /* 0 nop */
-    2,                           /* 1 add */
-    1,                           /* 2 mov */
-    2,                           /* 3 m ul */
-    3,                           /* 4 mad */
-    3,                           /* 5 dp2add */
-    2,                           /* 6 dp3 */
-    2,                           /* 7 dp4 */
-    1,                           /* 8 frc */
-    1,                           /* 9 rcp */
-    1,                           /* a rsq */
-    1,                           /* b exp */
-    1,                           /* c log */
-    3,                           /* d cmp */
-    2,                           /* e min */
-    2,                           /* f max */
-    1,                           /* 10 flr */
-    1,                           /* 11 mod */
-    1,                           /* 12 trc */
-    2,                           /* 13 sge */
-    2,                           /* 14 slt */
-    1,
-    1,
-    1,
-    1,
-    0,
-    0,
-    0,
-    0,
-    0,
-    0,
-    0,
-};
-
-static const char *regname[] = {
-    "R",
-    "T",
-    "CONST",
-    "S",
-    "OC",
-    "OD",
-    "U",
-    "UNKNOWN",
-};
-
-static void
-print_reg_type_nr(uint32_t type, uint32_t nr)
-{
-    switch (type) {
-    case REG_TYPE_T:
-	switch (nr) {
-	case T_DIFFUSE:
-	    fprintf (stderr, "T_DIFFUSE");
-	    return;
-	case T_SPECULAR:
-	    fprintf (stderr, "T_SPECULAR");
-	    return;
-	case T_FOG_W:
-	    fprintf (stderr, "T_FOG_W");
-	    return;
-	default:
-	    fprintf (stderr, "T_TEX%d", nr);
-	    return;
-	}
-    case REG_TYPE_OC:
-	if (nr == 0) {
-	    fprintf (stderr, "oC");
-	    return;
-	}
-	break;
-    case REG_TYPE_OD:
-	if (nr == 0) {
-	    fprintf (stderr, "oD");
-	    return;
-	}
-	break;
-    default:
-	break;
-    }
-
-    fprintf (stderr, "%s[%d]", regname[type], nr);
-}
-
-#define REG_SWIZZLE_MASK 0x7777
-#define REG_NEGATE_MASK 0x8888
-
-#define REG_SWIZZLE_XYZW ((SRC_X << A2_SRC2_CHANNEL_X_SHIFT) |	\
-			  (SRC_Y << A2_SRC2_CHANNEL_Y_SHIFT) |	\
-			  (SRC_Z << A2_SRC2_CHANNEL_Z_SHIFT) |	\
-			  (SRC_W << A2_SRC2_CHANNEL_W_SHIFT))
-
-static void
-print_reg_neg_swizzle(uint32_t reg)
-{
-    int i;
-
-    if ((reg & REG_SWIZZLE_MASK) == REG_SWIZZLE_XYZW &&
-	(reg & REG_NEGATE_MASK) == 0)
-	return;
-
-    fprintf (stderr, ".");
-
-    for (i = 12; i >= 0; i -= 4) {
-	if (reg & (8 << i))
-	    fprintf (stderr, "-");
-
-	switch ((reg >> i) & 0x7) {
-	case 0:
-	    fprintf (stderr, "x");
-	    break;
-	case 1:
-	    fprintf (stderr, "y");
-	    break;
-	case 2:
-	    fprintf (stderr, "z");
-	    break;
-	case 3:
-	    fprintf (stderr, "w");
-	    break;
-	case 4:
-	    fprintf (stderr, "0");
-	    break;
-	case 5:
-	    fprintf (stderr, "1");
-	    break;
-	default:
-	    fprintf (stderr, "?");
-	    break;
-	}
-    }
-}
-
-static void
-print_src_reg(uint32_t dword)
-{
-    uint32_t nr = (dword >> A2_SRC2_NR_SHIFT) & REG_NR_MASK;
-    uint32_t type = (dword >> A2_SRC2_TYPE_SHIFT) & REG_TYPE_MASK;
-    print_reg_type_nr(type, nr);
-    print_reg_neg_swizzle(dword);
-}
-
-static void
-print_dest_reg(uint32_t dword)
-{
-    uint32_t nr = (dword >> A0_DEST_NR_SHIFT) & REG_NR_MASK;
-    uint32_t type = (dword >> A0_DEST_TYPE_SHIFT) & REG_TYPE_MASK;
-    print_reg_type_nr(type, nr);
-    if ((dword & A0_DEST_CHANNEL_ALL) == A0_DEST_CHANNEL_ALL)
-	return;
-    fprintf (stde