[PATCH 15/21] glamor: Add glamor_program based poly_text and image_text

Keith Packard keithp at keithp.com
Tue Apr 1 17:29:14 PDT 2014


Accelerates text painting with GPU-based geometry computation and stippling

v2: Simplify get_glyphs, expand single character variable names to
    more descriptive ones. (Markus Wick)

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 glamor/Makefile.am          |   6 +-
 glamor/glamor.c             |   3 +
 glamor/glamor.h             |  25 ++
 glamor/glamor_copy.c        | 605 ++++++++++++++++++++++++++++++++++++++++++
 glamor/glamor_copyarea.c    | 630 --------------------------------------------
 glamor/glamor_copyplane.c   |  75 ------
 glamor/glamor_copywindow.c  |  56 ----
 glamor/glamor_core.c        |   8 +-
 glamor/glamor_font.c        | 186 +++++++++++++
 glamor/glamor_font.h        |  49 ++++
 glamor/glamor_glyphs.c      |   6 +-
 glamor/glamor_largepixmap.c |  13 +-
 glamor/glamor_priv.h        |  66 +++--
 glamor/glamor_program.c     |  10 +-
 glamor/glamor_program.h     |   3 +
 glamor/glamor_render.c      |  11 +-
 glamor/glamor_text.c        | 526 ++++++++++++++++++++++++++++++++++++
 17 files changed, 1478 insertions(+), 800 deletions(-)
 create mode 100644 glamor/glamor_copy.c
 delete mode 100644 glamor/glamor_copyarea.c
 delete mode 100644 glamor/glamor_copyplane.c
 delete mode 100644 glamor/glamor_copywindow.c
 create mode 100644 glamor/glamor_font.c
 create mode 100644 glamor/glamor_font.h
 create mode 100644 glamor/glamor_text.c

diff --git a/glamor/Makefile.am b/glamor/Makefile.am
index 4ede88c..31e5f72 100644
--- a/glamor/Makefile.am
+++ b/glamor/Makefile.am
@@ -7,11 +7,11 @@ AM_CFLAGS = $(CWARNFLAGS) $(DIX_CFLAGS) $(GLAMOR_CFLAGS)
 libglamor_la_SOURCES = \
 	glamor.c \
 	glamor_context.h \
-	glamor_copyarea.c \
-	glamor_copywindow.c \
+	glamor_copy.c \
 	glamor_core.c \
 	glamor_debug.h \
 	glamor_fill.c \
+	glamor_font.c \
 	glamor_glx.c \
 	glamor_glyphs.c \
 	glamor_polylines.c \
@@ -24,6 +24,7 @@ libglamor_la_SOURCES = \
 	glamor_program.c \
 	glamor_rects.c \
 	glamor_spans.c \
+	glamor_text.c \
 	glamor_transfer.c \
 	glamor_transfer.h \
 	glamor_transform.c \
@@ -32,7 +33,6 @@ libglamor_la_SOURCES = \
 	glamor_triangles.c\
 	glamor_addtraps.c\
 	glamor_getimage.c\
-	glamor_copyplane.c\
 	glamor_glyphblt.c\
 	glamor_points.c\
 	glamor_priv.h\
diff --git a/glamor/glamor.c b/glamor/glamor.c
index a7d981c..e9d3f47 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -415,6 +415,9 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         screen->CreateScreenResources;
     screen->CreateScreenResources = glamor_create_screen_resources;
 
+    if (!glamor_font_init(screen))
+        goto fail;
+
     if (flags & GLAMOR_USE_SCREEN) {
         if (!RegisterBlockAndWakeupHandlers(_glamor_block_handler,
                                             _glamor_wakeup_handler,
diff --git a/glamor/glamor.h b/glamor/glamor.h
index 2ff0409..5fe8e41 100644
--- a/glamor/glamor.h
+++ b/glamor/glamor.h
@@ -347,6 +347,17 @@ extern _X_EXPORT Bool glamor_copy_n_to_n_nf(DrawablePtr src,
                                             Bool upsidedown, Pixel bitplane,
                                             void *closure);
 
+extern _X_EXPORT Bool glamor_copy_nf(DrawablePtr src,
+                                     DrawablePtr dst,
+                                     GCPtr gc,
+                                     BoxPtr box,
+                                     int nbox,
+                                     int dx,
+                                     int dy,
+                                     Bool reverse,
+                                     Bool upsidedown, Pixel bitplane,
+                                     void *closure);
+
 extern _X_EXPORT Bool glamor_composite_nf(CARD8 op,
                                           PicturePtr source,
                                           PicturePtr mask,
@@ -434,6 +445,20 @@ extern _X_EXPORT Bool glamor_poly_segment_nf(DrawablePtr pDrawable, GCPtr pGC,
 extern _X_EXPORT Bool glamor_poly_lines_nf(DrawablePtr drawable, GCPtr gc,
                                            int mode, int n, DDXPointPtr points);
 
+extern _X_EXPORT Bool glamor_poly_text8_nf(DrawablePtr drawable, GCPtr gc,
+                                           int x, int y, int count, char *chars, int *final_pos);
+
+extern _X_EXPORT Bool glamor_poly_text16_nf(DrawablePtr drawable, GCPtr gc,
+                                            int x, int y, int count, unsigned short *chars, int *final_pos);
+
+extern _X_EXPORT Bool glamor_image_text8_nf(DrawablePtr drawable, GCPtr gc,
+                                            int x, int y, int count, char *chars);
+
+extern _X_EXPORT Bool glamor_image_text16_nf(DrawablePtr drawable, GCPtr gc,
+                                             int x, int y, int count, unsigned short *chars);
+
+#define HAS_GLAMOR_TEXT 1
+
 #ifdef GLAMOR_FOR_XORG
 extern _X_EXPORT XF86VideoAdaptorPtr glamor_xv_init(ScreenPtr pScreen,
                                                     int num_texture_ports);
diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c
new file mode 100644
index 0000000..9204ee6
--- /dev/null
+++ b/glamor/glamor_copy.c
@@ -0,0 +1,605 @@
+/*
+ * Copyright © 2014 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "glamor_priv.h"
+#include "glamor_transfer.h"
+#include "glamor_prepare.h"
+#include "glamor_transform.h"
+
+struct copy_args {
+    PixmapPtr           src_pixmap;
+    glamor_pixmap_fbo   *src;
+    uint32_t            bitplane;
+    int                 dx, dy;
+};
+
+static Bool
+use_copyarea(PixmapPtr dst, GCPtr gc, glamor_program *prog, void *arg)
+{
+    struct copy_args *args = arg;
+    glamor_pixmap_fbo *src = args->src;
+
+    glActiveTexture(GL_TEXTURE0);
+    glBindTexture(GL_TEXTURE_2D, src->tex);
+
+    glUniform2f(prog->fill_offset_uniform, args->dx, args->dy);
+    glUniform2f(prog->fill_size_uniform, src->width, src->height);
+
+    return TRUE;
+}
+
+static const glamor_facet glamor_facet_copyarea = {
+    "copy_area",
+    .version = 130,
+    .vs_vars = "attribute vec4 primitive;\n",
+    .vs_exec = ("       vec2 pos = (primitive.zw - primitive.xy) * vec2(gl_VertexID&1, (gl_VertexID&2)>>1);\n"
+                GLAMOR_POS(gl_Position, (primitive.xy + pos))
+                "       fill_pos = fill_offset + primitive.xy + pos;\n"),
+    .fs_exec = "       gl_FragColor = texelFetch(sampler, ivec2(fill_pos), 0);\n",
+    .locations = glamor_program_location_fill,
+    .use = use_copyarea,
+};
+
+static Bool
+use_copyplane(PixmapPtr dst, GCPtr gc, glamor_program *prog, void *arg)
+{
+    struct copy_args *args = arg;
+    glamor_pixmap_fbo *src = args->src;
+
+    glActiveTexture(GL_TEXTURE0);
+    glBindTexture(GL_TEXTURE_2D, src->tex);
+
+    glUniform2f(prog->fill_offset_uniform, args->dx, args->dy);
+    glUniform2f(prog->fill_size_uniform, src->width, src->height);
+
+    glamor_set_color(dst, gc->fgPixel, prog->fg_uniform);
+    glamor_set_color(dst, gc->bgPixel, prog->bg_uniform);
+
+    /* XXX handle 2 10 10 10 and 1555 formats; presumably the pixmap private knows this? */
+    switch (args->src_pixmap->drawable.depth) {
+    case 24:
+        glUniform4ui(prog->bitplane_uniform,
+                     (args->bitplane >> 16) & 0xff,
+                     (args->bitplane >>  8) & 0xff,
+                     (args->bitplane      ) & 0xff,
+                     0);
+
+        glUniform4ui(prog->bitmul_uniform, 0xff, 0xff, 0xff, 0);
+        break;
+    case 32:
+        glUniform4ui(prog->bitplane_uniform,
+                     (args->bitplane >> 16) & 0xff,
+                     (args->bitplane >>  8) & 0xff,
+                     (args->bitplane      ) & 0xff,
+                     (args->bitplane >> 24) & 0xff);
+
+        glUniform4ui(prog->bitmul_uniform, 0xff, 0xff, 0xff, 0xff);
+        break;
+    case 16:
+        glUniform4ui(prog->bitplane_uniform,
+                     (args->bitplane >> 11) & 0x1f,
+                     (args->bitplane >>  5) & 0x3f,
+                     (args->bitplane      ) & 0x1f,
+                     0);
+
+        glUniform4ui(prog->bitmul_uniform, 0x1f, 0x3f, 0x1f, 0);
+        break;
+    case 15:
+        glUniform4ui(prog->bitplane_uniform,
+                     (args->bitplane >> 10) & 0x1f,
+                     (args->bitplane >>  5) & 0x1f,
+                     (args->bitplane      ) & 0x1f,
+                     0);
+
+        glUniform4ui(prog->bitmul_uniform, 0x1f, 0x1f, 0x1f, 0);
+        break;
+    case 8:
+        glUniform4ui(prog->bitplane_uniform,
+                     0, 0, 0, args->bitplane);
+        glUniform4ui(prog->bitmul_uniform, 0, 0, 0, 0xff);
+        break;
+    case 1:
+        glUniform4ui(prog->bitplane_uniform,
+                     0, 0, 0, args->bitplane);
+        glUniform4ui(prog->bitmul_uniform, 0, 0, 0, 0xff);
+        break;
+    }
+
+    return TRUE;
+}
+
+static const glamor_facet glamor_facet_copyplane = {
+    "copy_plane",
+    .version = 130,
+    .vs_vars = "attribute vec4 primitive;\n",
+    .vs_exec = ("       vec2 pos = (primitive.zw - primitive.xy) * vec2(gl_VertexID&1, (gl_VertexID&2)>>1);\n"
+                GLAMOR_POS(gl_Position, (primitive.xy + pos))
+                "       fill_pos = fill_offset + primitive.xy + pos;\n"),
+    .fs_exec = ("       uvec4 bits = uvec4(texelFetch(sampler, ivec2(fill_pos), 0) * bitmul + vec4(0.5,0.5,0.5,0.5));\n"
+                "       if ((bits & bitplane) != uvec4(0,0,0,0))\n"
+                "               gl_FragColor = fg;\n"
+                "       else\n"
+                "               gl_FragColor = bg;\n"),
+    .locations = glamor_program_location_fill|glamor_program_location_fg|glamor_program_location_bg|glamor_program_location_bitplane,
+    .use = use_copyplane,
+};
+
+static void
+glamor_copy_bail(DrawablePtr src,
+                 DrawablePtr dst,
+                 GCPtr gc,
+                 BoxPtr box,
+                 int nbox,
+                 int dx,
+                 int dy,
+                 Bool reverse,
+                 Bool upsidedown,
+                 Pixel bitplane,
+                 void *closure)
+{
+    if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW) && glamor_prep_drawable(src, GLAMOR_ACCESS_RO)) {
+        if (bitplane) {
+            if (src->bitsPerPixel > 1)
+                fbCopyNto1(src, dst, gc, box, nbox, dx, dy,
+                           reverse, upsidedown, bitplane, closure);
+            else
+                fbCopy1toN(src, dst, gc, box, nbox, dx, dy,
+                           reverse, upsidedown, bitplane, closure);
+        } else {
+            fbCopyNtoN(src, dst, gc, box, nbox, dx, dy,
+                       reverse, upsidedown, bitplane, closure);
+        }
+    }
+    glamor_finish_access(dst);
+    glamor_finish_access(src);
+}
+
+static void
+glamor_copy_cpu_fbo(DrawablePtr src,
+                    DrawablePtr dst,
+                    GCPtr gc,
+                    BoxPtr box,
+                    int nbox,
+                    int dx,
+                    int dy,
+                    Bool reverse,
+                    Bool upsidedown,
+                    Pixel bitplane,
+                    void *closure)
+{
+    ScreenPtr screen = dst->pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
+    glamor_pixmap_private *dst_priv = glamor_get_pixmap_private(dst_pixmap);
+    FbBits *src_bits;
+    FbStride src_stride;
+    int src_bpp;
+    int src_xoff, src_yoff;
+    int dst_xoff, dst_yoff;
+
+    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_priv))
+        goto bail;
+
+    if (gc && gc->alu != GXcopy)
+        goto bail;
+
+    if (gc && !glamor_pm_is_solid(dst, gc->planemask))
+        goto bail;
+
+    glamor_get_context(glamor_priv);
+    glamor_prepare_access(src, GLAMOR_ACCESS_RO);
+
+    glamor_get_drawable_deltas(dst, dst_pixmap, &dst_xoff, &dst_yoff);
+
+    fbGetDrawable(src, src_bits, src_stride, src_bpp, src_xoff, src_yoff);
+
+    glamor_upload_boxes(dst_pixmap, box, nbox, src_xoff + dx, src_yoff + dy,
+                        dst_xoff, dst_yoff,
+                        (uint8_t *) src_bits, src_stride * sizeof (FbBits));
+    glamor_finish_access(src);
+    glamor_put_context(glamor_priv);
+
+    return;
+
+bail:
+    glamor_copy_bail(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
+}
+
+static void
+glamor_copy_fbo_fbo(DrawablePtr src,
+                    DrawablePtr dst,
+                    GCPtr gc,
+                    BoxPtr box,
+                    int nbox,
+                    int dx,
+                    int dy,
+                    Bool reverse,
+                    Bool upsidedown,
+                    Pixel bitplane,
+                    void *closure)
+{
+    ScreenPtr screen = dst->pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
+    PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
+    glamor_pixmap_private *src_priv = glamor_get_pixmap_private(src_pixmap);
+    glamor_pixmap_private *dst_priv = glamor_get_pixmap_private(dst_pixmap);
+    int src_box_x, src_box_y, dst_box_x, dst_box_y;
+    int b;
+    Bool use_copy_pixels = FALSE;
+
+    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_priv) || !GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_priv))
+        goto bail;
+
+    glamor_get_context(glamor_priv);
+
+    if (gc && !glamor_set_planemask(dst_pixmap, gc->planemask))
+        goto bail_ctx;
+
+    if (!glamor_set_alu(screen, gc ? gc->alu : GXcopy))
+        goto bail_ctx;
+
+    if (src_pixmap == dst_pixmap) {
+        if (bitplane)
+            goto bail_ctx;
+        use_copy_pixels = TRUE;
+    }
+
+    if (use_copy_pixels) {
+        static float modelview[16] = {
+            1, 0, 0, 0,
+            0, 1, 0, 0,
+            0, 0, 1, 0,
+            -1, -1, 0, 1,
+        };
+        int src_x_start, src_x_end, src_x_step;
+        int src_y_start, src_y_end, src_y_step;
+        int dst_x_start, dst_x_end, dst_x_step;
+        int dst_y_start, dst_y_end, dst_y_step;
+
+        if (reverse) {
+            src_x_start = glamor_pixmap_wcnt(src_priv) - 1;
+            src_x_end = -1;
+            src_x_step = -1;
+
+            dst_x_start = glamor_pixmap_wcnt(dst_priv) - 1;
+            dst_x_end = -1;
+            dst_x_step = -1;
+        } else {
+            src_x_start = 0;
+            src_x_end = glamor_pixmap_wcnt(src_priv);
+            src_x_step = 1;
+
+            dst_x_start = 0;
+            dst_x_end = glamor_pixmap_wcnt(dst_priv);
+            dst_x_step = 1;
+        }
+
+        if (upsidedown) {
+            src_y_start = glamor_pixmap_hcnt(src_priv) - 1;
+            src_y_end = -1;
+            src_y_step = -1;
+
+            dst_y_start = glamor_pixmap_hcnt(dst_priv) - 1;
+            dst_y_end = -1;
+            dst_y_step = -1;
+        } else {
+            src_y_start = 0;
+            src_y_end = glamor_pixmap_hcnt(src_priv);
+            src_y_step = 1;
+
+            dst_y_start = 0;
+            dst_y_end = glamor_pixmap_hcnt(dst_priv);
+            dst_y_step = 1;
+        }
+
+        glMatrixMode(GL_PROJECTION);
+        glLoadIdentity();
+
+        for (b = 0; b < nbox; b++) {
+            for (src_box_y = src_y_start; src_box_y != src_y_end; src_box_y += src_y_step)
+                for (src_box_x = src_x_start; src_box_x != src_x_end; src_box_x += src_x_step) {
+                    BoxPtr src_box = glamor_pixmap_box_at(src_priv, src_box_x, src_box_y);
+                    glBindFramebuffer(GL_READ_FRAMEBUFFER, glamor_pixmap_fbo_at(src_priv, src_box_x, src_box_y)->fb);
+
+                    for (dst_box_y = dst_y_start; dst_box_y != dst_y_end; dst_box_y += dst_y_step)
+                        for (dst_box_x = dst_x_start; dst_box_x != dst_x_end; dst_box_x += dst_x_step) {
+                            int     dx1, dx2, dy1, dy2;
+
+                            BoxPtr dst_box = glamor_pixmap_box_at(dst_priv, dst_box_x, dst_box_y);
+
+                            glBindFramebuffer(GL_DRAW_FRAMEBUFFER, glamor_pixmap_fbo_at(dst_priv, dst_box_x, dst_box_y)->fb);
+                            glViewport(0, 0, dst_box->x2 - dst_box->x1, dst_box->y2 - dst_box->y1);
+
+                            glMatrixMode(GL_MODELVIEW);
+
+                            modelview[0] = 2.0f / (dst_box->x2 - dst_box->x1);
+                            modelview[5] = 2.0f / (dst_box->y2 - dst_box->y1);
+
+                            glLoadMatrixf(modelview);
+
+                            dx1 = box[b].x1;
+                            dx2 = box[b].x2;
+
+                            dy1 = box[b].y1;
+                            dy2 = box[b].y2;
+
+                            /* clip to the destination box */
+                            if (dx1 < dst_box->x1)
+                                dx1 = dst_box->x1;
+                            if (dst_box->x2 < dx2)
+                                dx2 = dst_box->x2;
+
+                            if (dy1 < dst_box->y1)
+                                dy1 = dst_box->y1;
+                            if (dst_box->y2 < dy2)
+                                dy2 = dst_box->y2;
+
+                            /* clip to the source box */
+
+                            if (dx1 < src_box->x1 - dx)
+                                dx1 = src_box->x1 - dx;
+                            if (src_box->x2 - dx < dx2)
+                                dx2 = src_box->x2 - dx;
+
+                            if (dy1 < src_box->y1 - dy)
+                                dy1 = src_box->y1 - dy;
+                            if (src_box->y2 - dy < dy2)
+                                dy2 = src_box->y2 - dy;
+
+                            if (dx1 >= dx2)
+                                continue;
+                            if (dy1 >= dy2)
+                                continue;
+
+                            glRasterPos2i(dx1 - dst_box->x1, dy1 - dst_box->y1);
+                            glCopyPixels (dx1 + dx - src_box->x1,
+                                          dy1 + dy - src_box->y1,
+                                          dx2 - dx1, dy2 - dy1, GL_COLOR);
+                        }
+                }
+        }
+    } else {
+
+        int dst_off_x, dst_off_y;
+        int src_off_x, src_off_y;
+        GLshort *v;
+        char *vbo_offset;
+        struct copy_args args;
+        glamor_program *prog;
+        const glamor_facet *copy_facet;
+        Bool set_scissor;
+
+        if (bitplane) {
+            prog = &glamor_priv->copy_plane_prog;
+            copy_facet = &glamor_facet_copyplane;
+        } else {
+            prog = &glamor_priv->copy_area_prog;
+            copy_facet = &glamor_facet_copyarea;
+        }
+
+        if (prog->failed)
+            goto bail_ctx;
+
+        if (!prog->prog) {
+            if (!glamor_build_program(screen, prog,
+                                      copy_facet, NULL))
+                goto bail_ctx;
+        }
+
+        args.src_pixmap = src_pixmap;
+        args.bitplane = bitplane;
+
+        /* Set up the vertex buffers for the points */
+
+        v = glamor_get_vbo_space(dst->pScreen, nbox * sizeof (BoxRec), &vbo_offset);
+
+        glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
+        glVertexAttribDivisor(GLAMOR_VERTEX_POS, 1);
+        glVertexAttribPointer(GLAMOR_VERTEX_POS, 4, GL_SHORT, GL_FALSE,
+                              4 * sizeof (GLshort), vbo_offset);
+
+        memcpy(v, box, nbox * sizeof (BoxRec));
+
+        glamor_put_vbo_space(screen);
+
+        glamor_get_drawable_deltas(src, src_pixmap, &src_off_x, &src_off_y);
+
+        set_scissor = src_priv->type == GLAMOR_TEXTURE_LARGE;
+        if (set_scissor)
+            glEnable(GL_SCISSOR_TEST);
+
+        glamor_pixmap_loop(src_priv, src_box_x, src_box_y) {
+            BoxPtr src_box = glamor_pixmap_box_at(src_priv, src_box_x, src_box_y);
+
+            args.dx = dx + src_off_x - src_box->x1;
+            args.dy = dy + src_off_y - src_box->y1;
+            args.src = glamor_pixmap_fbo_at(src_priv, src_box_x, src_box_y);
+
+            if (!glamor_use_program(dst_pixmap, gc, prog, &args))
+                goto bail_ctx;
+
+            glamor_pixmap_loop(dst_priv, dst_box_x, dst_box_y) {
+                glamor_set_destination_drawable(dst, dst_box_x, dst_box_y, FALSE, FALSE,
+                                                prog->matrix_uniform, &dst_off_x, &dst_off_y);
+
+                if (set_scissor)
+                    glScissor(dst_off_x - args.dx,
+                              dst_off_y - args.dy,
+                              src_box->x2 - src_box->x1,
+                              src_box->y2 - src_box->y1);
+
+                glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, nbox);
+            }
+        }
+        if (set_scissor)
+            glDisable(GL_SCISSOR_TEST);
+        glVertexAttribDivisor(GLAMOR_VERTEX_POS, 0);
+        glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
+    }
+
+    glDisable(GL_COLOR_LOGIC_OP);
+    glamor_put_context(glamor_priv);
+    return;
+
+bail_ctx:
+    glDisable(GL_COLOR_LOGIC_OP);
+    glamor_put_context(glamor_priv);
+bail:
+    glamor_copy_bail(src, dst, gc, box, nbox, dx, dy,
+                     reverse, upsidedown, bitplane, closure);
+}
+
+static Bool
+glamor_copy_gl(DrawablePtr src,
+               DrawablePtr dst,
+               GCPtr gc,
+               BoxPtr box,
+               int nbox,
+               int dx,
+               int dy,
+               Bool reverse,
+               Bool upsidedown,
+               Pixel bitplane,
+               void *closure)
+{
+    PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
+    PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
+    glamor_pixmap_private *src_priv = glamor_get_pixmap_private(src_pixmap);
+    glamor_pixmap_private *dst_priv = glamor_get_pixmap_private(dst_pixmap);
+
+    if (GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_priv)) {
+        if (GLAMOR_PIXMAP_PRIV_HAS_FBO(src_priv)) {
+            glamor_copy_fbo_fbo(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
+            return TRUE;
+        }
+        if (bitplane == 0) {
+            glamor_copy_cpu_fbo(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
+void
+glamor_copy(DrawablePtr src,
+            DrawablePtr dst,
+            GCPtr gc,
+            BoxPtr box,
+            int nbox,
+            int dx,
+            int dy,
+            Bool reverse,
+            Bool upsidedown,
+            Pixel bitplane,
+            void *closure)
+{
+    if (glamor_copy_gl(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure))
+        return;
+    glamor_copy_bail(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
+}
+
+RegionPtr
+glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                 int srcx, int srcy, int width, int height, int dstx, int dsty)
+{
+    return miDoCopy(src, dst, gc,
+                    srcx, srcy, width, height,
+                    dstx, dsty, glamor_copy, 0, NULL);
+}
+
+RegionPtr
+glamor_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                  int srcx, int srcy, int width, int height, int dstx, int dsty,
+                  unsigned long bitplane)
+{
+    if ((bitplane & FbFullMask(src->depth)) == 0)
+        return miHandleExposures(src, dst, gc,
+                                 srcx, srcy, width, height, dstx, dsty,
+                                 bitplane);
+    return miDoCopy(src, dst, gc,
+                    srcx, srcy, width, height,
+                    dstx, dsty, glamor_copy, bitplane, NULL);
+}
+
+void
+glamor_copy_window(WindowPtr window, DDXPointRec old_origin, RegionPtr src_region)
+{
+    PixmapPtr pixmap = glamor_get_drawable_pixmap(&window->drawable);
+    DrawablePtr drawable = &pixmap->drawable;
+    RegionRec dst_region;
+    int dx, dy;
+
+    dx = old_origin.x - window->drawable.x;
+    dy = old_origin.y - window->drawable.y;
+    RegionTranslate(src_region, -dx, -dy);
+
+    RegionNull(&dst_region);
+
+    RegionIntersect(&dst_region, &window->borderClip, src_region);
+
+#ifdef COMPOSITE
+    if (pixmap->screen_x || pixmap->screen_y)
+        RegionTranslate(&dst_region, -pixmap->screen_x, -pixmap->screen_y);
+#endif
+
+    miCopyRegion(drawable, drawable,
+                 0, &dst_region, dx, dy, glamor_copy, 0, 0);
+
+    RegionUninit(&dst_region);
+}
+
+Bool
+glamor_copy_n_to_n_nf(DrawablePtr src,
+                      DrawablePtr dst,
+                      GCPtr gc,
+                      BoxPtr box,
+                      int nbox,
+                      int dx,
+                      int dy,
+                      Bool reverse,
+                      Bool upsidedown, Pixel bitplane,
+                      void *closure)
+{
+    if (glamor_copy_gl(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure))
+        return TRUE;
+    if (glamor_ddx_fallback_check_pixmap(src) && glamor_ddx_fallback_check_pixmap(dst))
+        return FALSE;
+    glamor_copy_bail(src, dst, gc, box, nbox, dx, dy, reverse, upsidedown, bitplane, closure);
+    return TRUE;
+}
+
+Bool
+glamor_copy_plane_nf(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                     int srcx, int srcy, int w, int h, int dstx, int dsty,
+                     unsigned long bitplane, RegionPtr *region)
+{
+    if (glamor_ddx_fallback_check_pixmap(src) &&
+        glamor_ddx_fallback_check_pixmap(dst) &&
+        glamor_ddx_fallback_check_gc(gc))
+        return FALSE;
+
+    *region = glamor_copy_plane(src, dst, gc,
+                                srcx, srcy, w, h, dstx, dsty,
+                                bitplane);
+    return TRUE;
+}
diff --git a/glamor/glamor_copyarea.c b/glamor/glamor_copyarea.c
deleted file mode 100644
index 996611c..0000000
--- a/glamor/glamor_copyarea.c
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * Copyright © 2008 Intel Corporation
- * Copyright © 1998 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * Authors:
- *    Eric Anholt <eric at anholt.net>
- *    Zhigang Gong <zhigang.gong at linux.intel.com>
- */
-
-#include "glamor_priv.h"
-
-/** @file glamor_copyarea.c
- *
- * GC CopyArea implementation
- */
-static Bool
-glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
-                            DrawablePtr dst,
-                            GCPtr gc, BoxPtr box, int nbox, int dx, int dy)
-{
-    ScreenPtr screen = dst->pScreen;
-    PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
-    PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
-    glamor_pixmap_private *src_pixmap_priv, *dst_pixmap_priv;
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    int dst_x_off, dst_y_off, src_x_off, src_y_off, i;
-    int fbo_x_off, fbo_y_off;
-    int src_fbo_x_off, src_fbo_y_off;
-
-    if (!glamor_priv->has_fbo_blit) {
-        glamor_delayed_fallback(screen, "no EXT_framebuffer_blit\n");
-        return FALSE;
-    }
-    src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
-    dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
-
-    if (gc) {
-        if (gc->alu != GXcopy) {
-            glamor_delayed_fallback(screen, "non-copy ALU\n");
-            return FALSE;
-        }
-    }
-
-    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)) {
-        glamor_delayed_fallback(screen, "no src fbo\n");
-        return FALSE;
-    }
-
-    if (glamor_set_destination_pixmap(dst_pixmap))
-        return FALSE;
-
-    pixmap_priv_get_fbo_off(dst_pixmap_priv, &fbo_x_off, &fbo_y_off);
-    pixmap_priv_get_fbo_off(src_pixmap_priv, &src_fbo_x_off, &src_fbo_y_off);
-
-    glamor_get_context(glamor_priv);
-    glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->base.fbo->fb);
-    glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
-    glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
-    dst_x_off += fbo_x_off;
-    dst_y_off += fbo_y_off;
-    src_y_off += dy + src_fbo_y_off;
-    src_x_off += src_fbo_x_off;
-
-    for (i = 0; i < nbox; i++) {
-        if (glamor_priv->yInverted) {
-            glBlitFramebuffer(box[i].x1 + dx + src_x_off,
-                              box[i].y1 + src_y_off,
-                              box[i].x2 + dx + src_x_off,
-                              box[i].y2 + src_y_off,
-                              box[i].x1 + dst_x_off,
-                              box[i].y1 + dst_y_off,
-                              box[i].x2 + dst_x_off,
-                              box[i].y2 + dst_y_off,
-                              GL_COLOR_BUFFER_BIT, GL_NEAREST);
-        }
-        else {
-            int flip_dst_y1 =
-                dst_pixmap->drawable.height - (box[i].y2 + dst_y_off);
-            int flip_dst_y2 =
-                dst_pixmap->drawable.height - (box[i].y1 + dst_y_off);
-            int flip_src_y1 =
-                src_pixmap->drawable.height - (box[i].y2 + src_y_off);
-            int flip_src_y2 =
-                src_pixmap->drawable.height - (box[i].y1 + src_y_off);
-
-            glBlitFramebuffer(box[i].x1 + dx + src_x_off,
-                              flip_src_y1,
-                              box[i].x2 + dx + src_x_off,
-                              flip_src_y2,
-                              box[i].x1 + dst_x_off,
-                              flip_dst_y1,
-                              box[i].x2 + dst_x_off,
-                              flip_dst_y2,
-                              GL_COLOR_BUFFER_BIT, GL_NEAREST);
-        }
-    }
-    glamor_put_context(glamor_priv);
-    glamor_priv->state = BLIT_STATE;
-    return TRUE;
-}
-
-static Bool
-glamor_copy_n_to_n_textured(DrawablePtr src,
-                            DrawablePtr dst,
-                            GCPtr gc, BoxPtr box, int nbox, int dx, int dy)
-{
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(dst->pScreen);
-    PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
-    PixmapPtr dst_pixmap = glamor_get_drawable_pixmap(dst);
-    int i;
-    float vertices[8], texcoords[8];
-    glamor_pixmap_private *src_pixmap_priv;
-    glamor_pixmap_private *dst_pixmap_priv;
-    int src_x_off, src_y_off, dst_x_off, dst_y_off;
-    enum glamor_pixmap_status src_status = GLAMOR_NONE;
-    GLfloat dst_xscale, dst_yscale, src_xscale, src_yscale;
-
-    src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
-    dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
-
-    if (src_pixmap_priv->base.gl_fbo == GLAMOR_FBO_UNATTACHED) {
-#ifndef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
-        glamor_delayed_fallback(dst->pScreen, "src has no fbo.\n");
-        return FALSE;
-#else
-        src_status = glamor_upload_pixmap_to_texture(src_pixmap);
-        if (src_status != GLAMOR_UPLOAD_DONE)
-            return FALSE;
-
-        src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
-#endif
-    }
-
-    pixmap_priv_get_dest_scale(dst_pixmap_priv, &dst_xscale, &dst_yscale);
-    pixmap_priv_get_scale(src_pixmap_priv, &src_xscale, &src_yscale);
-
-    glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
-
-    glamor_get_context(glamor_priv);
-
-    glamor_set_destination_pixmap_priv_nc(dst_pixmap_priv);
-    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
-                          GL_FALSE, 2 * sizeof(float), vertices);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
-
-    glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
-    dx += src_x_off;
-    dy += src_y_off;
-
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex);
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-    }
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-    glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT, GL_FALSE,
-                          2 * sizeof(float), texcoords);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    glUseProgram(glamor_priv->finish_access_prog[0]);
-    glUniform1i(glamor_priv->finish_access_revert[0], REVERT_NONE);
-    glUniform1i(glamor_priv->finish_access_swap_rb[0], SWAP_NONE_UPLOADING);
-
-    for (i = 0; i < nbox; i++) {
-
-        glamor_set_normalize_vcoords(dst_pixmap_priv,
-                                     dst_xscale, dst_yscale,
-                                     box[i].x1 + dst_x_off,
-                                     box[i].y1 + dst_y_off,
-                                     box[i].x2 + dst_x_off,
-                                     box[i].y2 + dst_y_off,
-                                     glamor_priv->yInverted, vertices);
-
-        glamor_set_normalize_tcoords(src_pixmap_priv,
-                                     src_xscale,
-                                     src_yscale,
-                                     box[i].x1 + dx,
-                                     box[i].y1 + dy,
-                                     box[i].x2 + dx,
-                                     box[i].y2 + dy,
-                                     glamor_priv->yInverted, texcoords);
-        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-    }
-
-    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    /* The source texture is bound to a fbo, we have to flush it here. */
-    glamor_put_context(glamor_priv);
-    glamor_priv->state = RENDER_STATE;
-    glamor_priv->render_idle_cnt = 0;
-    return TRUE;
-}
-
-static Bool
-__glamor_copy_n_to_n(DrawablePtr src,
-                     DrawablePtr dst,
-                     GCPtr gc,
-                     BoxPtr box,
-                     int nbox,
-                     int dx,
-                     int dy,
-                     Bool reverse,
-                     Bool upsidedown, Pixel bitplane, void *closure)
-{
-    PixmapPtr dst_pixmap, src_pixmap, temp_pixmap = NULL;
-    DrawablePtr temp_src = src;
-    glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv;
-    glamor_screen_private *glamor_priv;
-    BoxRec bound;
-    ScreenPtr screen;
-    int temp_dx = dx;
-    int temp_dy = dy;
-    int src_x_off, src_y_off, dst_x_off, dst_y_off;
-    int i;
-    int overlaped = 0;
-    Bool ret = FALSE;
-
-    dst_pixmap = glamor_get_drawable_pixmap(dst);
-    dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
-    src_pixmap = glamor_get_drawable_pixmap(src);
-    src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
-    screen = dst_pixmap->drawable.pScreen;
-    glamor_priv = glamor_get_screen_private(dst->pScreen);
-    glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
-
-    glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
-
-    if (src_pixmap_priv->base.fbo
-        && src_pixmap_priv->base.fbo->fb == dst_pixmap_priv->base.fbo->fb) {
-        int x_shift = abs(src_x_off - dx - dst_x_off);
-        int y_shift = abs(src_y_off - dy - dst_y_off);
-
-        for (i = 0; i < nbox; i++) {
-            if (x_shift < abs(box[i].x2 - box[i].x1)
-                && y_shift < abs(box[i].y2 - box[i].y1)) {
-                overlaped = 1;
-                break;
-            }
-        }
-    }
-    DEBUGF("Copy %d %d %dx%d dx %d dy %d from %p to %p \n",
-           box[0].x1, box[0].y1,
-           box[0].x2 - box[0].x1, box[0].y2 - box[0].y1,
-           dx, dy, src_pixmap, dst_pixmap);
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP &&
-        !overlaped &&
-        (glamor_priv->state != RENDER_STATE
-         || !src_pixmap_priv->base.gl_tex || !dst_pixmap_priv->base.gl_tex)
-        && glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, dy)) {
-        ret = TRUE;
-        goto done;
-    }
-    glamor_calculate_boxes_bound(&bound, box, nbox);
-
-    /*  Overlaped indicate the src and dst are the same pixmap. */
-    if (overlaped || (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)
-                      && (((bound.x2 - bound.x1) * (bound.y2 - bound.y1)
-                           * 4 >
-                           src_pixmap->drawable.width *
-                           src_pixmap->drawable.height)
-                          || !(glamor_check_fbo_size(glamor_priv,
-                                                     src_pixmap->drawable.width,
-                                                     src_pixmap->drawable.
-                                                     height))))) {
-
-        temp_pixmap = glamor_create_pixmap(screen,
-                                           bound.x2 - bound.x1,
-                                           bound.y2 - bound.y1,
-                                           src_pixmap->drawable.depth,
-                                           overlaped ? 0 :
-                                           GLAMOR_CREATE_PIXMAP_CPU);
-        assert(bound.x2 - bound.x1 <= glamor_priv->max_fbo_size);
-        assert(bound.y2 - bound.y1 <= glamor_priv->max_fbo_size);
-        if (!temp_pixmap)
-            goto done;
-        glamor_translate_boxes(box, nbox, -bound.x1, -bound.y1);
-        temp_src = &temp_pixmap->drawable;
-
-        if (overlaped)
-            glamor_copy_n_to_n_textured(src, temp_src, gc, box,
-                                        nbox,
-                                        temp_dx + bound.x1, temp_dy + bound.y1);
-        else
-            fbCopyNtoN(src, temp_src, gc, box, nbox,
-                       temp_dx + bound.x1, temp_dy + bound.y1,
-                       reverse, upsidedown, bitplane, closure);
-        glamor_translate_boxes(box, nbox, bound.x1, bound.y1);
-        temp_dx = -bound.x1;
-        temp_dy = -bound.y1;
-    }
-    else {
-        temp_dx = dx;
-        temp_dy = dy;
-        temp_src = src;
-    }
-
-    if (glamor_copy_n_to_n_textured
-        (temp_src, dst, gc, box, nbox, temp_dx, temp_dy)) {
-        ret = TRUE;
-    }
- done:
-    if (temp_src != src)
-        glamor_destroy_pixmap(temp_pixmap);
-    return ret;
-}
-
-static Bool
-_glamor_copy_n_to_n(DrawablePtr src,
-                    DrawablePtr dst,
-                    GCPtr gc,
-                    BoxPtr box,
-                    int nbox,
-                    int dx,
-                    int dy,
-                    Bool reverse,
-                    Bool upsidedown, Pixel bitplane,
-                    void *closure, Bool fallback)
-{
-    ScreenPtr screen = dst->pScreen;
-    PixmapPtr dst_pixmap, src_pixmap;
-    glamor_pixmap_private *dst_pixmap_priv, *src_pixmap_priv;
-    glamor_screen_private *glamor_priv;
-    BoxPtr extent;
-    RegionRec region;
-    int src_x_off, src_y_off, dst_x_off, dst_y_off;
-    Bool ok = FALSE;
-    int force_clip = 0;
-
-    if (nbox == 0)
-        return TRUE;
-    dst_pixmap = glamor_get_drawable_pixmap(dst);
-    dst_pixmap_priv = glamor_get_pixmap_private(dst_pixmap);
-    src_pixmap = glamor_get_drawable_pixmap(src);
-    src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
-
-    glamor_priv = glamor_get_screen_private(screen);
-
-    DEBUGF("Copy %d %d %dx%d dx %d dy %d from %p to %p \n",
-           box[0].x1, box[0].y1,
-           box[0].x2 - box[0].x1, box[0].y2 - box[0].y1,
-           dx, dy, src_pixmap, dst_pixmap);
-
-    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dst_pixmap_priv))
-        goto fall_back;
-
-    if (gc) {
-        if (!glamor_set_planemask(dst_pixmap, gc->planemask))
-            goto fall_back;
-        glamor_get_context(glamor_priv);
-        if (!glamor_set_alu(screen, gc->alu)) {
-            glamor_put_context(glamor_priv);
-            goto fail;
-        }
-        glamor_put_context(glamor_priv);
-    }
-
-    if (!src_pixmap_priv) {
-        glamor_set_pixmap_type(src_pixmap, GLAMOR_MEMORY);
-        src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
-    }
-
-    glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
-    glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
-
-    RegionInitBoxes(&region, box, nbox);
-    extent = RegionExtents(&region);
-
-    if (!glamor_check_fbo_size(glamor_priv,
-                               extent->x2 - extent->x1, extent->y2 - extent->y1)
-        && (src_pixmap_priv->type == GLAMOR_MEMORY
-            || (src_pixmap_priv == dst_pixmap_priv))) {
-        force_clip = 1;
-    }
-
-    if (force_clip || dst_pixmap_priv->type == GLAMOR_TEXTURE_LARGE
-        || src_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
-        glamor_pixmap_clipped_regions *clipped_dst_regions;
-        int n_dst_region, i, j;
-        PixmapPtr temp_source_pixmap;
-        glamor_pixmap_private *temp_source_priv = NULL;
-
-        RegionTranslate(&region, dst_x_off, dst_y_off);
-        if (!force_clip)
-            clipped_dst_regions =
-                glamor_compute_clipped_regions(dst_pixmap_priv, &region,
-                                               &n_dst_region, 0, reverse,
-                                               upsidedown);
-        else
-            clipped_dst_regions =
-                glamor_compute_clipped_regions_ext(dst_pixmap_priv, &region,
-                                                   &n_dst_region,
-                                                   glamor_priv->max_fbo_size,
-                                                   glamor_priv->max_fbo_size,
-                                                   reverse, upsidedown);
-        for (i = 0; i < n_dst_region; i++) {
-            int n_src_region;
-            glamor_pixmap_clipped_regions *clipped_src_regions;
-            BoxPtr current_boxes;
-            int n_current_boxes;
-
-            SET_PIXMAP_FBO_CURRENT(dst_pixmap_priv,
-                                   clipped_dst_regions[i].block_idx);
-
-            temp_source_pixmap = NULL;
-            if (src_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
-                RegionTranslate(clipped_dst_regions[i].region,
-                                -dst_x_off + src_x_off + dx,
-                                -dst_y_off + src_y_off + dy);
-                clipped_src_regions =
-                    glamor_compute_clipped_regions(src_pixmap_priv,
-                                                   clipped_dst_regions[i].
-                                                   region, &n_src_region, 0,
-                                                   reverse, upsidedown);
-                DEBUGF("Source is large pixmap.\n");
-                for (j = 0; j < n_src_region; j++) {
-                    if (src_pixmap_priv != dst_pixmap_priv)
-                        SET_PIXMAP_FBO_CURRENT(src_pixmap_priv,
-                                               clipped_src_regions[j].
-                                               block_idx);
-                    else if (src_pixmap_priv == dst_pixmap_priv &&
-                             clipped_src_regions[j].block_idx !=
-                             clipped_dst_regions[i].block_idx) {
-                        /* source and the dest are the same, but need different block_idx.
-                         * we create a empty pixmap and fill the required source fbo and box to
-                         * it. It's a little hacky, but avoid extra copy. */
-                        temp_source_pixmap =
-                            glamor_create_pixmap(src->pScreen, 0, 0, src->depth,
-                                                 0);
-                        if (!temp_source_pixmap) {
-                            ok = FALSE;
-                            goto fail;
-                        }
-                        src->pScreen->ModifyPixmapHeader(temp_source_pixmap,
-                                                         src_pixmap->drawable.
-                                                         width,
-                                                         src_pixmap->drawable.
-                                                         height, 0, 0,
-                                                         src_pixmap->devKind,
-                                                         NULL);
-                        temp_source_priv =
-                            glamor_get_pixmap_private(temp_source_pixmap);
-                        *temp_source_priv = *src_pixmap_priv;
-                        temp_source_priv->large.box =
-                            src_pixmap_priv->large.
-                            box_array[clipped_src_regions[j].block_idx];
-                        temp_source_priv->base.fbo =
-                            src_pixmap_priv->large.
-                            fbo_array[clipped_src_regions[j].block_idx];
-                        temp_source_priv->base.pixmap = temp_source_pixmap;
-                    }
-                    assert(temp_source_pixmap ||
-                           !(src_pixmap_priv == dst_pixmap_priv &&
-                             (clipped_src_regions[j].block_idx !=
-                              clipped_dst_regions[i].block_idx)));
-
-                    RegionTranslate(clipped_src_regions[j].region,
-                                    -src_x_off - dx, -src_y_off - dy);
-                    current_boxes = RegionRects(clipped_src_regions[j].region);
-                    n_current_boxes =
-                        RegionNumRects(clipped_src_regions[j].region);
-                    DEBUGF("dst pixmap fbo idx %d src pixmap fbo idx %d \n",
-                           clipped_dst_regions[i].block_idx,
-                           clipped_src_regions[j].block_idx);
-                    DEBUGF("Copy %d %d %d %d dx %d dy %d from %p to %p \n",
-                           current_boxes[0].x1, current_boxes[0].y1,
-                           current_boxes[0].x2, current_boxes[0].y2, dx, dy,
-                           src_pixmap, dst_pixmap);
-                    if (!temp_source_pixmap)
-                        ok = __glamor_copy_n_to_n(src, dst, gc, current_boxes,
-                                                  n_current_boxes, dx, dy,
-                                                  reverse, upsidedown, bitplane,
-                                                  closure);
-                    else {
-                        ok = __glamor_copy_n_to_n(&temp_source_pixmap->drawable,
-                                                  dst, gc, current_boxes,
-                                                  n_current_boxes, dx, dy,
-                                                  reverse, upsidedown, bitplane,
-                                                  closure);
-                        temp_source_priv->type = GLAMOR_MEMORY;
-                        temp_source_priv->base.fbo = NULL;
-                        glamor_destroy_pixmap(temp_source_pixmap);
-                        temp_source_pixmap = NULL;
-                    }
-
-                    RegionDestroy(clipped_src_regions[j].region);
-                    if (!ok) {
-                        assert(0);
-                        goto fail;
-                    }
-                }
-
-                if (n_src_region == 0)
-                    ok = TRUE;
-                free(clipped_src_regions);
-            }
-            else {
-                RegionTranslate(clipped_dst_regions[i].region,
-                                -dst_x_off, -dst_y_off);
-                current_boxes = RegionRects(clipped_dst_regions[i].region);
-                n_current_boxes = RegionNumRects(clipped_dst_regions[i].region);
-
-                DEBUGF("dest pixmap fbo idx %d \n",
-                       clipped_dst_regions[i].block_idx);
-                DEBUGF("Copy %d %d %d %d dx %d dy %d from %p to %p \n",
-                       current_boxes[0].x1, current_boxes[0].y1,
-                       current_boxes[0].x2, current_boxes[0].y2,
-                       dx, dy, src_pixmap, dst_pixmap);
-
-                ok = __glamor_copy_n_to_n(src, dst, gc, current_boxes,
-                                          n_current_boxes, dx, dy, reverse,
-                                          upsidedown, bitplane, closure);
-
-            }
-            RegionDestroy(clipped_dst_regions[i].region);
-        }
-        if (n_dst_region == 0)
-            ok = TRUE;
-        free(clipped_dst_regions);
-        RegionUninit(&region);
-    }
-    else {
-        ok = __glamor_copy_n_to_n(src, dst, gc, box, nbox, dx, dy,
-                                  reverse, upsidedown, bitplane, closure);
-    }
-
- fail:
-    glamor_get_context(glamor_priv);
-    glamor_set_alu(screen, GXcopy);
-    glamor_put_context(glamor_priv);
-
-    if (ok)
-        return TRUE;
- fall_back:
-    if (!fallback && glamor_ddx_fallback_check_pixmap(src)
-        && glamor_ddx_fallback_check_pixmap(dst))
-        goto done;
-
-    if (src_pixmap_priv->type == GLAMOR_DRM_ONLY
-        || dst_pixmap_priv->type == GLAMOR_DRM_ONLY) {
-        LogMessage(X_WARNING,
-                   "Access a DRM only pixmap is not allowed within glamor.\n");
-        return TRUE;
-    }
-    glamor_report_delayed_fallbacks(src->pScreen);
-    glamor_report_delayed_fallbacks(dst->pScreen);
-
-    glamor_fallback("from %p to %p (%c,%c)\n", src, dst,
-                    glamor_get_drawable_location(src),
-                    glamor_get_drawable_location(dst));
-
-    if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW) &&
-        glamor_prepare_access(src, GLAMOR_ACCESS_RO) &&
-        glamor_prepare_access_gc(gc)) {
-        fbCopyNtoN(src, dst, gc, box, nbox,
-                   dx, dy, reverse, upsidedown, bitplane, closure);
-    }
-    glamor_finish_access_gc(gc);
-    glamor_finish_access(src);
-    glamor_finish_access(dst);
-    ok = TRUE;
-
- done:
-    glamor_clear_delayed_fallbacks(src->pScreen);
-    glamor_clear_delayed_fallbacks(dst->pScreen);
-    return ok;
-}
-
-RegionPtr
-glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
-                 int srcx, int srcy, int width, int height, int dstx, int dsty)
-{
-    RegionPtr region;
-
-    region = miDoCopy(src, dst, gc,
-                      srcx, srcy, width, height,
-                      dstx, dsty, glamor_copy_n_to_n, 0, NULL);
-
-    return region;
-}
-
-void
-glamor_copy_n_to_n(DrawablePtr src,
-                   DrawablePtr dst,
-                   GCPtr gc,
-                   BoxPtr box,
-                   int nbox,
-                   int dx,
-                   int dy,
-                   Bool reverse, Bool upsidedown, Pixel bitplane, void *closure)
-{
-    _glamor_copy_n_to_n(src, dst, gc, box, nbox, dx,
-                        dy, reverse, upsidedown, bitplane, closure, TRUE);
-}
-
-Bool
-glamor_copy_n_to_n_nf(DrawablePtr src,
-                      DrawablePtr dst,
-                      GCPtr gc,
-                      BoxPtr box,
-                      int nbox,
-                      int dx,
-                      int dy,
-                      Bool reverse,
-                      Bool upsidedown, Pixel bitplane, void *closure)
-{
-    return _glamor_copy_n_to_n(src, dst, gc, box, nbox, dx,
-                               dy, reverse, upsidedown, bitplane, closure,
-                               FALSE);
-}
diff --git a/glamor/glamor_copyplane.c b/glamor/glamor_copyplane.c
deleted file mode 100644
index 2bd2de3..0000000
--- a/glamor/glamor_copyplane.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright © 2009 Intel Corporation
- * Copyright © 1998 Keith Packard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- *
- * Authors:
- *    Zhigang Gong <zhigang.gong at gmail.com>
- *
- */
-
-#include "glamor_priv.h"
-
-static Bool
-_glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
-                   int srcx, int srcy, int w, int h, int dstx, int dsty,
-                   unsigned long bitPlane, RegionPtr *pRegion, Bool fallback)
-{
-    if (!fallback && glamor_ddx_fallback_check_gc(pGC)
-        && glamor_ddx_fallback_check_pixmap(pSrc)
-        && glamor_ddx_fallback_check_pixmap(pDst))
-        goto fail;
-
-    if (glamor_prepare_access(pDst, GLAMOR_ACCESS_RW) &&
-        glamor_prepare_access(pSrc, GLAMOR_ACCESS_RO) &&
-        glamor_prepare_access_gc(pGC)) {
-        *pRegion = fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h,
-                               dstx, dsty, bitPlane);
-    }
-    glamor_finish_access_gc(pGC);
-    glamor_finish_access(pSrc);
-    glamor_finish_access(pDst);
-    return TRUE;
-
- fail:
-    return FALSE;
-}
-
-RegionPtr
-glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
-                  int srcx, int srcy, int w, int h, int dstx, int dsty,
-                  unsigned long bitPlane)
-{
-    RegionPtr ret;
-
-    _glamor_copy_plane(pSrc, pDst, pGC, srcx, srcy, w, h,
-                       dstx, dsty, bitPlane, &ret, TRUE);
-    return ret;
-}
-
-Bool
-glamor_copy_plane_nf(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
-                     int srcx, int srcy, int w, int h, int dstx, int dsty,
-                     unsigned long bitPlane, RegionPtr *pRegion)
-{
-    return _glamor_copy_plane(pSrc, pDst, pGC, srcx, srcy, w, h,
-                              dstx, dsty, bitPlane, pRegion, FALSE);
-}
diff --git a/glamor/glamor_copywindow.c b/glamor/glamor_copywindow.c
deleted file mode 100644
index 1ced4b3..0000000
--- a/glamor/glamor_copywindow.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright © 2008 Intel Corporation
- * Copyright © 1998 Keith Packard
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of Keith Packard not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Keith Packard makes no
- * representations about the suitability of this software for any purpose.  It
- * is provided "as is" without express or implied warranty.
- *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "glamor_priv.h"
-
-/** @file glamor_copywindow.c
- *
- * Screen CopyWindow implementation.
- */
-
-void
-glamor_copy_window(WindowPtr win, DDXPointRec old_origin, RegionPtr src_region)
-{
-    RegionRec dst_region;
-    int dx, dy;
-    PixmapPtr pixmap = win->drawable.pScreen->GetWindowPixmap(win);
-
-    dx = old_origin.x - win->drawable.x;
-    dy = old_origin.y - win->drawable.y;
-    REGION_TRANSLATE(win->drawable.pScreen, src_region, -dx, -dy);
-
-    REGION_INIT(win->drawable.pScreen, &dst_region, NullBox, 0);
-
-    REGION_INTERSECT(win->drawable.pScreen, &dst_region,
-                     &win->borderClip, src_region);
-#ifdef COMPOSITE
-    if (pixmap->screen_x || pixmap->screen_y)
-        REGION_TRANSLATE(win->drawable.pScreen, &dst_region,
-                         -pixmap->screen_x, -pixmap->screen_y);
-#endif
-
-    miCopyRegion(&pixmap->drawable, &pixmap->drawable,
-                 NULL, &dst_region, dx, dy, glamor_copy_n_to_n, 0, NULL);
-
-    REGION_UNINIT(win->drawable.pScreen, &dst_region);
-}
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index d8e05ee..6dc9f49 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -319,10 +319,10 @@ GCOps glamor_gc_ops = {
     .FillPolygon = miFillPolygon,
     .PolyFillRect = glamor_poly_fill_rect,
     .PolyFillArc = miPolyFillArc,
-    .PolyText8 = miPolyText8,
-    .PolyText16 = miPolyText16,
-    .ImageText8 = miImageText8,
-    .ImageText16 = miImageText16,
+    .PolyText8 = glamor_poly_text8,
+    .PolyText16 = glamor_poly_text16,
+    .ImageText8 = glamor_image_text8,
+    .ImageText16 = glamor_image_text16,
     .ImageGlyphBlt = miImageGlyphBlt,
     .PolyGlyphBlt = glamor_poly_glyph_blt,
     .PushPixels = glamor_push_pixels,
diff --git a/glamor/glamor_font.c b/glamor/glamor_font.c
new file mode 100644
index 0000000..47dfe2a
--- /dev/null
+++ b/glamor/glamor_font.c
@@ -0,0 +1,186 @@
+/*
+ * Copyright © 2014 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "glamor_priv.h"
+#include "glamor_font.h"
+#include <dixfontstr.h>
+
+static int glamor_font_generation;
+static int glamor_font_private_index;
+static int glamor_font_screen_count;
+
+glamor_font_t *
+glamor_font_get(ScreenPtr screen, FontPtr font)
+{
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+
+    glamor_font_t       *privates;
+    glamor_font_t       *glamor_font;
+    int                 overall_width, overall_height;
+    int                 num_rows;
+    int                 num_cols;
+    int                 glyph_width_pixels;
+    int                 glyph_width_bytes;
+    int                 glyph_height;
+    int                 row, col;
+    unsigned char       c[2];
+    CharInfoPtr         glyph;
+    unsigned long       count;
+
+
+    privates = FontGetPrivate(font, glamor_font_private_index);
+    if (!privates) {
+        privates = calloc(glamor_font_screen_count, sizeof (glamor_font_t));
+        if (!privates)
+            return NULL;
+        FontSetPrivate(font, glamor_font_private_index, privates);
+    }
+
+    glamor_font = &privates[screen->myNum];
+
+    if (glamor_font->realized)
+        return glamor_font;
+
+    glamor_font->realized = TRUE;
+
+    /* Figure out how many glyphs are in the font */
+    num_cols = font->info.lastCol - font->info.firstCol + 1;
+    num_rows = font->info.lastRow - font->info.firstRow + 1;
+
+    /* Figure out the size of each glyph */
+    glyph_width_pixels = font->info.maxbounds.rightSideBearing - font->info.minbounds.leftSideBearing;
+    glyph_height = font->info.maxbounds.ascent + font->info.maxbounds.descent;
+
+    glyph_width_bytes = (glyph_width_pixels + 7) >> 3;
+
+    glamor_font->glyph_width_pixels = glyph_width_pixels;
+    glamor_font->glyph_width_bytes = glyph_width_bytes;
+    glamor_font->glyph_height = glyph_height;
+
+    overall_width = glyph_width_bytes * num_cols;
+    overall_height = glyph_height * num_rows;
+
+    /* Check whether the font has a default character */
+    c[0] = font->info.lastRow + 1;
+    c[1] = font->info.lastCol + 1;
+    (*font->get_glyphs)(font, 1, c, TwoD16Bit, &count, &glyph);
+
+    glamor_font->default_char = count ? glyph : NULL;
+    glamor_font->default_row = font->info.defaultCh >> 8;
+    glamor_font->default_col = font->info.defaultCh;
+
+    glamor_priv = glamor_get_screen_private(screen);
+    glamor_get_context(glamor_priv);
+
+    glGenTextures(1, &glamor_font->texture_id);
+    glActiveTexture(GL_TEXTURE0);
+    glBindTexture(GL_TEXTURE_2D, glamor_font->texture_id);
+
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+    /* Allocate storage */
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_R8UI, overall_width, overall_height,
+                 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, NULL);
+
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+
+    /* Paint all of the glyphs */
+    for (row = 0; row < num_rows; row++) {
+        for (col = 0; col < num_cols; col++) {
+            c[0] = row + font->info.firstRow;
+            c[1] = col + font->info.firstCol;
+
+            (*font->get_glyphs)(font, 1, c, TwoD16Bit, &count, &glyph);
+
+            if (count)
+                glTexSubImage2D(GL_TEXTURE_2D, 0, col * glyph_width_bytes, row * glyph_height,
+                                GLYPHWIDTHBYTES(glyph), GLYPHHEIGHTPIXELS(glyph),
+                                GL_RED_INTEGER, GL_UNSIGNED_BYTE, glyph->bits);
+        }
+    }
+
+    glamor_put_context(glamor_priv);
+
+    return glamor_font;
+}
+
+static Bool
+glamor_realize_font(ScreenPtr screen, FontPtr font)
+{
+    return TRUE;
+}
+
+static Bool
+glamor_unrealize_font(ScreenPtr screen, FontPtr font)
+{
+    glamor_screen_private       *glamor_priv;
+    glamor_font_t               *privates = FontGetPrivate(font, glamor_font_private_index);
+    glamor_font_t               *glamor_font;
+    int                         s;
+
+    if (!privates)
+        return TRUE;
+
+    glamor_font = &privates[screen->myNum];
+
+    if (!glamor_font->realized)
+        return TRUE;
+
+    /* Unrealize the font, freeing the allocated texture */
+    glamor_font->realized = FALSE;
+
+    glamor_priv = glamor_get_screen_private(screen);
+    glamor_get_context(glamor_priv);
+    glDeleteTextures(1, &glamor_font->texture_id);
+    glamor_put_context(glamor_priv);
+
+    /* Check to see if all of the screens are  done with this font
+     * and free the private when that happens
+     */
+    for (s = 0; s < glamor_font_screen_count; s++)
+        if (privates[s].realized)
+            return TRUE;
+
+    free(privates);
+    FontSetPrivate(font, glamor_font_private_index, NULL);
+    return TRUE;
+}
+
+Bool
+glamor_font_init(ScreenPtr screen)
+{
+    if (glamor_font_generation != serverGeneration) {
+        glamor_font_private_index = AllocateFontPrivateIndex();
+        if (glamor_font_private_index == -1)
+            return FALSE;
+        glamor_font_screen_count = 0;
+        glamor_font_generation = serverGeneration;
+    }
+
+    if (screen->myNum >= glamor_font_screen_count)
+        glamor_font_screen_count = screen->myNum + 1;
+
+    screen->RealizeFont = glamor_realize_font;
+    screen->UnrealizeFont = glamor_unrealize_font;
+    return TRUE;
+}
diff --git a/glamor/glamor_font.h b/glamor/glamor_font.h
new file mode 100644
index 0000000..36d2062
--- /dev/null
+++ b/glamor/glamor_font.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright © 2014 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifndef _GLAMOR_FONT_H_
+#define _GLAMOR_FONT_H_
+
+typedef struct {
+    Bool        realized;
+    CharInfoPtr default_char;
+    CARD8       default_row;
+    CARD8       default_col;
+
+    GLuint      texture_id;
+
+    CARD16      glyph_width_bytes;
+    CARD16      glyph_width_pixels;
+    CARD16      glyph_height;
+
+} glamor_font_t;
+
+glamor_font_t *
+glamor_font_get(ScreenPtr screen, FontPtr font);
+
+Bool
+glamor_font_init(ScreenPtr screen);
+
+void
+glamor_fini_glyph_shader(ScreenPtr screen);
+
+#endif /* _GLAMOR_FONT_H_ */
diff --git a/glamor/glamor_glyphs.c b/glamor/glamor_glyphs.c
index a04ae82..dfeddc7 100644
--- a/glamor/glamor_glyphs.c
+++ b/glamor/glamor_glyphs.c
@@ -448,9 +448,9 @@ glamor_glyph_cache_upload_glyph(ScreenPtr screen,
     box.y1 = y;
     box.x2 = x + glyph->info.width;
     box.y2 = y + glyph->info.height;
-    glamor_copy_n_to_n_nf(&scratch->drawable,
-                          &pCachePixmap->drawable, NULL,
-                          &box, 1, -x, -y, FALSE, FALSE, 0, NULL);
+    glamor_copy(&scratch->drawable,
+                &pCachePixmap->drawable, NULL,
+                &box, 1, -x, -y, FALSE, FALSE, 0, NULL);
     if (scratch != pGlyphPixmap)
         screen->DestroyPixmap(scratch);
 
diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index b3a8d5d..5a4bec5 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -797,9 +797,9 @@ glamor_merge_clipped_regions(glamor_pixmap_private *pixmap_priv,
         copy_box.y2 = temp_extent->y2 - temp_extent->y1;
         dx = temp_extent->x1;
         dy = temp_extent->y1;
-        glamor_copy_n_to_n(&priv->base.pixmap->drawable,
-                           &temp_pixmap->drawable,
-                           NULL, &copy_box, 1, dx, dy, 0, 0, 0, NULL);
+        glamor_copy(&priv->base.pixmap->drawable,
+                    &temp_pixmap->drawable,
+                    NULL, &copy_box, 1, dx, dy, 0, 0, 0, NULL);
 //              glamor_solid(temp_pixmap, 0, 0, temp_pixmap->drawable.width,
 //                             temp_pixmap->drawable.height, GXcopy, 0xffffffff, 0xff00);
     }
@@ -829,9 +829,10 @@ glamor_merge_clipped_regions(glamor_pixmap_private *pixmap_priv,
                        copy_box.x1, copy_box.y1, copy_box.x2,
                        copy_box.y2, dx, dy);
 
-                glamor_copy_n_to_n(&priv->base.pixmap->drawable,
-                                   &temp_pixmap->drawable,
-                                   NULL, &copy_box, 1, dx, dy, 0, 0, 0, NULL);
+                glamor_copy(&priv->base.pixmap->drawable,
+                            &temp_pixmap->drawable,
+                            NULL, &copy_box, 1, dx, dy, 0, 0, 0, NULL);
+
                 box++;
             }
         }
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index d22d254..c017bc8 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -232,6 +232,15 @@ typedef struct glamor_screen_private {
     /* glamor glyphblt shaders */
     glamor_program_fill poly_glyph_blt_progs;
 
+    /* glamor text shaders */
+    glamor_program_fill poly_text_progs;
+    glamor_program      te_text_prog;
+    glamor_program      image_text_prog;
+
+    /* glamor copy shaders */
+    glamor_program      copy_area_prog;
+    glamor_program      copy_plane_prog;
+
     /* vertext/elment_index buffer object for render */
     GLuint vbo, ebo;
     /** Next offset within the VBO that glamor_get_vbo_space() will use. */
@@ -621,19 +630,6 @@ glamor_pixmap_fbo *glamor_create_fbo_array(glamor_screen_private *glamor_priv,
                                            int flag, int block_w, int block_h,
                                            glamor_pixmap_private *);
 
-/* glamor_copyarea.c */
-RegionPtr
-
-glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
-                 int srcx, int srcy, int width, int height, int dstx, int dsty);
-void glamor_copy_n_to_n(DrawablePtr src, DrawablePtr dst, GCPtr gc,
-                        BoxPtr box, int nbox, int dx, int dy, Bool reverse,
-                        Bool upsidedown, Pixel bitplane, void *closure);
-
-/* glamor_copywindow.c */
-void glamor_copy_window(WindowPtr win, DDXPointRec old_origin,
-                        RegionPtr src_region);
-
 /* glamor_core.c */
 void glamor_init_finish_access_shaders(ScreenPtr screen);
 void glamor_fini_finish_access_shaders(ScreenPtr screen);
@@ -947,10 +943,18 @@ void glamor_get_image(DrawablePtr pDrawable, int x, int y, int w, int h,
 void glamor_add_traps(PicturePtr pPicture,
                       INT16 x_off, INT16 y_off, int ntrap, xTrap *traps);
 
-RegionPtr glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
-                            int srcx, int srcy, int w, int h,
-                            int dstx, int dsty,
-                            unsigned long bitPlane);
+/* glamor_text.c */
+int glamor_poly_text8(DrawablePtr pDrawable, GCPtr pGC,
+                      int x, int y, int count, char *chars);
+
+int glamor_poly_text16(DrawablePtr pDrawable, GCPtr pGC,
+                       int x, int y, int count, unsigned short *chars);
+
+void glamor_image_text8(DrawablePtr pDrawable, GCPtr pGC,
+                        int x, int y, int count, char *chars);
+
+void glamor_image_text16(DrawablePtr pDrawable, GCPtr pGC,
+                         int x, int y, int count, unsigned short *chars);
 
 /* glamor_spans.c */
 void
@@ -971,6 +975,32 @@ void
 glamor_poly_fill_rect(DrawablePtr drawable,
                       GCPtr gc, int nrect, xRectangle *prect);
 
+/* glamor_copy.c */
+void
+glamor_copy(DrawablePtr src,
+            DrawablePtr dst,
+            GCPtr gc,
+            BoxPtr box,
+            int nbox,
+            int dx,
+            int dy,
+            Bool reverse,
+            Bool upsidedown,
+            Pixel bitplane,
+            void *closure);
+
+RegionPtr
+glamor_copy_area(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                 int srcx, int srcy, int width, int height, int dstx, int dsty);
+
+RegionPtr
+glamor_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
+                  int srcx, int srcy, int width, int height, int dstx, int dsty,
+                  unsigned long bitplane);
+
+void
+glamor_copy_window(WindowPtr window, DDXPointRec old_origin, RegionPtr src_region);
+
 /* glamor_glyphblt.c */
 void glamor_image_glyph_blt(DrawablePtr pDrawable, GCPtr pGC,
                             int x, int y, unsigned int nglyph,
@@ -1044,4 +1074,6 @@ void glamor_fini_xv_shader(ScreenPtr screen);
 //#define GLYPHS_NO_EDEGEMAP_OVERLAP_CHECK
 #define GLYPHS_EDEGE_OVERLAP_LOOSE_CHECK
 
+#include "glamor_font.h"
+
 #endif                          /* GLAMOR_PRIV_H */
diff --git a/glamor/glamor_program.c b/glamor/glamor_program.c
index e2e1434..ada8436 100644
--- a/glamor/glamor_program.c
+++ b/glamor/glamor_program.c
@@ -117,6 +117,11 @@ static glamor_location_var location_vars[] = {
         .location = glamor_program_location_font,
         .fs_vars = "uniform usampler2D font;\n",
     },
+    {
+        .location = glamor_program_location_bitplane,
+        .fs_vars = ("uniform uvec4 bitplane;\n"
+                    "uniform uvec4 bitmul;\n"),
+    },
 };
 
 #define NUM_LOCATION_VARS       (sizeof location_vars / sizeof location_vars[0])
@@ -196,6 +201,8 @@ static const glamor_facet facet_null_fill = {
     .name = ""
 };
 
+#define DBG 0
+
 static GLint
 glamor_get_uniform(glamor_program               *prog,
                    glamor_program_location      location,
@@ -289,7 +296,6 @@ glamor_build_program(ScreenPtr          screen,
     if (!vs_prog_string || !fs_prog_string)
         goto fail;
 
-#define DBG 0
 #if DBG
     ErrorF("\nPrograms for %s %s\nVertex shader:\n\n%s\n\nFragment Shader:\n\n%s",
            prim->name, fill->name, vs_prog_string, fs_prog_string);
@@ -326,6 +332,8 @@ glamor_build_program(ScreenPtr          screen,
     prog->fill_offset_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_offset");
     prog->fill_size_uniform = glamor_get_uniform(prog, glamor_program_location_fill, "fill_size");
     prog->font_uniform = glamor_get_uniform(prog, glamor_program_location_font, "font");
+    prog->bitplane_uniform = glamor_get_uniform(prog, glamor_program_location_bitplane, "bitplane");
+    prog->bitmul_uniform = glamor_get_uniform(prog, glamor_program_location_bitplane, "bitmul");
 
     if (glGetError() != GL_NO_ERROR)
         goto fail;
diff --git a/glamor/glamor_program.h b/glamor/glamor_program.h
index 88efc35..118f978 100644
--- a/glamor/glamor_program.h
+++ b/glamor/glamor_program.h
@@ -29,6 +29,7 @@ typedef enum {
     glamor_program_location_bg = 2,
     glamor_program_location_fill = 4,
     glamor_program_location_font = 8,
+    glamor_program_location_bitplane = 16,
 } glamor_program_location;
 
 typedef enum {
@@ -61,6 +62,8 @@ struct _glamor_program {
     GLint                       fill_size_uniform;
     GLint                       fill_offset_uniform;
     GLint                       font_uniform;
+    GLint                       bitplane_uniform;
+    GLint                       bitmul_uniform;
     glamor_program_location     locations;
     glamor_program_flag         flags;
     glamor_use                  prim_use;
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index fcdbf07..7f6ef9d 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -659,11 +659,12 @@ glamor_composite_with_copy(CARD8 op,
         if (region->extents.y2 + y_source - y_dest > source->pDrawable->height)
             goto cleanup_region;
     }
-    ret = glamor_copy_n_to_n_nf(source->pDrawable,
-                                dest->pDrawable, NULL,
-                                RegionRects(region), RegionNumRects(region),
-                                x_source - x_dest, y_source - y_dest,
-                                FALSE, FALSE, 0, NULL);
+    glamor_copy(source->pDrawable,
+                dest->pDrawable, NULL,
+                RegionRects(region), RegionNumRects(region),
+                x_source - x_dest, y_source - y_dest,
+                FALSE, FALSE, 0, NULL);
+    ret = TRUE;
  cleanup_region:
     return ret;
 }
diff --git a/glamor/glamor_text.c b/glamor/glamor_text.c
new file mode 100644
index 0000000..0e4b74c
--- /dev/null
+++ b/glamor/glamor_text.c
@@ -0,0 +1,526 @@
+/*
+ * Copyright © 2014 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "glamor_priv.h"
+#include <dixfontstr.h>
+#include "glamor_transform.h"
+
+/*
+ * Fill in the array of charinfo pointers for the provided characters. For
+ * missing characters, place a NULL in the array so that the charinfo array
+ * aligns exactly with chars
+ */
+
+static void
+glamor_get_glyphs(FontPtr font, glamor_font_t *glamor_font,
+                  int count, char *chars, Bool sixteen, CharInfoPtr *charinfo)
+{
+    unsigned long nglyphs;
+    FontEncoding encoding;
+    int char_step;
+
+    if (sixteen) {
+        char_step = 2;
+        if (FONTLASTROW(font) == 0)
+            encoding = Linear16Bit;
+        else
+            encoding = TwoD16Bit;
+    } else {
+        char_step = 1;
+        encoding = Linear8Bit;
+    }
+
+    /* If the font has a default character, then we don't have to
+     * worry about missing glyphs, so just get the whole string all at
+     * once. Otherwise, we have to fetch chars one at a time to notice
+     * missing ones.
+     */
+    if (glamor_font->default_char) {
+        GetGlyphs(font, (unsigned long) count, (unsigned char *) chars,
+                  encoding, &nglyphs, charinfo);
+    } else {
+        int c;
+        for (c = 0; c < count; c++) {
+            GetGlyphs(font, 1, (unsigned char *) chars,
+                      encoding, &nglyphs, &charinfo[c]);
+            if (!nglyphs)
+                charinfo[c] = NULL;
+            chars += char_step;
+        }
+    }
+}
+
+/*
+ * Construct quads for the provided list of characters and draw them
+ */
+
+static int
+glamor_text(DrawablePtr drawable, GCPtr gc,
+            glamor_font_t *glamor_font,
+            glamor_program *prog,
+            int x, int y,
+            int count, char *s_chars, CharInfoPtr *charinfo,
+            Bool sixteen)
+{
+    unsigned char *chars = (unsigned char *) s_chars;
+    FontPtr font = gc->font;
+    int off_x, off_y;
+    int c;
+    int nglyph;
+    GLshort *v;
+    char *vbo_offset;
+    CharInfoPtr ci;
+    int firstRow = font->info.firstRow;
+    int firstCol = font->info.firstCol;
+    int glyph_spacing_x = glamor_font->glyph_width_bytes * 8;
+    int glyph_spacing_y = glamor_font->glyph_height;
+    int box_x, box_y;
+    PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
+
+    /* Set the font as texture 1 */
+
+    glActiveTexture(GL_TEXTURE1);
+    glBindTexture(GL_TEXTURE_2D, glamor_font->texture_id);
+    glUniform1i(prog->font_uniform, 1);
+
+    /* Set up the vertex buffers for the font and destination */
+
+    v = glamor_get_vbo_space(drawable->pScreen, count * (6 * sizeof (GLshort)), &vbo_offset);
+
+    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
+    glVertexAttribDivisor(GLAMOR_VERTEX_POS, 1);
+    glVertexAttribPointer(GLAMOR_VERTEX_POS, 4, GL_SHORT, GL_FALSE,
+                          6 * sizeof (GLshort), vbo_offset);
+
+    glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+    glVertexAttribDivisor(GLAMOR_VERTEX_SOURCE, 1);
+    glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_SHORT, GL_FALSE,
+                          6 * sizeof (GLshort), vbo_offset + 4 * sizeof (GLshort));
+
+    /* Set the vertex coordinates */
+    nglyph = 0;
+
+    for (c = 0; c < count; c++) {
+        if ((ci = *charinfo++)) {
+            int     x1 = x + ci->metrics.leftSideBearing;
+            int     y1 = y - ci->metrics.ascent;
+            int     width = GLYPHWIDTHPIXELS(ci);
+            int     height = GLYPHHEIGHTPIXELS(ci);
+            int     tx, ty = 0;
+            int     row = 0, col;
+
+            x += ci->metrics.characterWidth;
+
+            if (sixteen) {
+                if (ci == glamor_font->default_char) {
+                    row = glamor_font->default_row;
+                    col = glamor_font->default_col;
+                } else {
+                    row = chars[0];
+                    col = chars[1];
+                }
+                if (FONTLASTROW(font) != 0)
+                    ty = (row - firstRow) * glyph_spacing_y;
+                else
+                    col += row << 8;
+            } else {
+                if (ci == glamor_font->default_char)
+                    col = glamor_font->default_col;
+                else
+                    col = chars[0];
+            }
+
+            tx = (col - firstCol) * glyph_spacing_x;
+
+            v[ 0] = x1;
+            v[ 1] = y1;
+            v[ 2] = width;
+            v[ 3] = height;
+            v[ 4] = tx;
+            v[ 5] = ty;
+
+            v += 6;
+            nglyph++;
+        }
+        chars += 1 + sixteen;
+    }
+    glamor_put_vbo_space(drawable->pScreen);
+
+    if (nglyph != 0) {
+
+        glEnable(GL_SCISSOR_TEST);
+
+        glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
+            BoxPtr box = RegionRects(gc->pCompositeClip);
+            int nbox = RegionNumRects(gc->pCompositeClip);
+
+            glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, FALSE, prog->matrix_uniform, &off_x, &off_y);
+
+            /* Run over the clip list, drawing the glyphs
+             * in each box
+             */
+
+            while (nbox--) {
+                glScissor(box->x1 + off_x,
+                          box->y1 + off_y,
+                          box->x2 - box->x1,
+                          box->y2 - box->y1);
+                box++;
+                glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, nglyph);
+            }
+        }
+        glDisable(GL_SCISSOR_TEST);
+    }
+
+    glVertexAttribDivisor(GLAMOR_VERTEX_SOURCE, 0);
+    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+    glVertexAttribDivisor(GLAMOR_VERTEX_POS, 0);
+    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
+    glDisable(GL_COLOR_LOGIC_OP);
+
+    return x;
+}
+
+static const char vs_vars_text[] =
+    "attribute vec4 primitive;\n"
+    "attribute vec2 source;\n"
+    "varying vec2 glyph_pos;\n";
+
+static const char vs_exec_text[] =
+    "       vec2 pos = primitive.zw * vec2(gl_VertexID&1, (gl_VertexID&2)>>1);\n"
+    GLAMOR_POS(gl_Position, (primitive.xy + pos))
+    "       glyph_pos = source + pos;\n";
+
+static const char fs_vars_text[] =
+    "varying vec2 glyph_pos;\n";
+
+static const char fs_exec_text[] =
+    "       ivec2 itile_texture = ivec2(glyph_pos);\n"
+    "       uint x = uint(itile_texture.x & 7);\n"
+    "       itile_texture.x >>= 3;\n"
+    "       uint texel = texelFetch(font, itile_texture, 0).x;\n"
+    "       uint bit = (texel >> x) & uint(1);\n"
+    "       if (bit == uint(0))\n"
+    "               discard;\n";
+
+static const char fs_exec_te[] =
+    "       ivec2 itile_texture = ivec2(glyph_pos);\n"
+    "       uint x = uint(itile_texture.x & 7);\n"
+    "       itile_texture.x >>= 3;\n"
+    "       uint texel = texelFetch(font, itile_texture, 0).x;\n"
+    "       uint bit = (texel >> x) & uint(1);\n"
+    "       if (bit == uint(0))\n"
+    "               gl_FragColor = bg;\n"
+    "       else\n"
+    "               gl_FragColor = fg;\n";
+
+static const glamor_facet glamor_facet_poly_text = {
+    .name = "poly_text",
+    .version = 130,
+    .vs_vars = vs_vars_text,
+    .vs_exec = vs_exec_text,
+    .fs_vars = fs_vars_text,
+    .fs_exec = fs_exec_text,
+    .source_name = "source",
+    .locations = glamor_program_location_font,
+};
+
+static Bool
+glamor_poly_text(DrawablePtr drawable, GCPtr gc,
+                 int x, int y, int count, char *chars, Bool sixteen, int *final_pos)
+{
+    ScreenPtr screen = drawable->pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
+    glamor_program *prog;
+    glamor_pixmap_private *pixmap_priv;
+    glamor_font_t *glamor_font;
+    CharInfoPtr charinfo[255];  /* encoding only has 1 byte for count */
+
+    glamor_font = glamor_font_get(drawable->pScreen, gc->font);
+    if (!glamor_font)
+        goto bail;
+
+    glamor_get_glyphs(gc->font, glamor_font, count, chars, sixteen, charinfo);
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
+        goto bail;
+
+    glamor_get_context(glamor_priv);
+
+    prog = glamor_use_program_fill(pixmap, gc, &glamor_priv->poly_text_progs, &glamor_facet_poly_text);
+
+    if (!prog)
+        goto bail_ctx;
+
+    x = glamor_text(drawable, gc, glamor_font, prog,
+                    x, y, count, chars, charinfo, sixteen);
+
+    glDisable(GL_COLOR_LOGIC_OP);
+
+    glamor_put_context(glamor_priv);
+
+    glamor_priv->state = RENDER_STATE;
+    glamor_priv->render_idle_cnt = 0;
+
+    *final_pos = x;
+    return TRUE;
+
+bail_ctx:
+    glDisable(GL_COLOR_LOGIC_OP);
+    glamor_put_context(glamor_priv);
+bail:
+    return FALSE;
+}
+
+Bool
+glamor_poly_text8_nf(DrawablePtr drawable, GCPtr gc,
+                     int x, int y, int count, char *chars, int *final_pos)
+{
+    if (glamor_poly_text(drawable, gc, x, y, count, chars, FALSE, final_pos))
+        return TRUE;
+    if (glamor_ddx_fallback_check_pixmap(drawable) && glamor_ddx_fallback_check_gc(gc))
+        return FALSE;
+    *final_pos = miPolyText8(drawable, gc, x, y, count, chars);
+    return TRUE;
+}
+
+int
+glamor_poly_text8(DrawablePtr drawable, GCPtr gc,
+                   int x, int y, int count, char *chars)
+{
+    int final_pos;
+
+    if (glamor_poly_text(drawable, gc, x, y, count, chars, FALSE, &final_pos))
+        return final_pos;
+    return miPolyText8(drawable, gc, x, y, count, chars);
+}
+
+Bool
+glamor_poly_text16_nf(DrawablePtr drawable, GCPtr gc,
+                      int x, int y, int count, unsigned short *chars, int *final_pos)
+{
+    if (glamor_poly_text(drawable, gc, x, y, count, (char *) chars, TRUE, final_pos))
+        return TRUE;
+
+    if (glamor_ddx_fallback_check_pixmap(drawable) && glamor_ddx_fallback_check_gc(gc))
+        return FALSE;
+    *final_pos = miPolyText16(drawable, gc, x, y, count, chars);
+    return TRUE;
+}
+
+int
+glamor_poly_text16(DrawablePtr drawable, GCPtr gc,
+                    int x, int y, int count, unsigned short *chars)
+{
+    int final_pos;
+
+    if (glamor_poly_text(drawable, gc, x, y, count, (char *) chars, TRUE, &final_pos))
+        return final_pos;
+    return miPolyText16(drawable, gc, x, y, count, chars);
+}
+
+/*
+ * Draw image text, which is always solid in copy mode and has the
+ * background cleared while painting the text. For fonts which have
+ * their bitmap metrics exactly equal to the area to clear, we can use
+ * the accelerated version which paints both fg and bg at the same
+ * time. Otherwise, clear the whole area and then paint the glyphs on
+ * top
+ */
+
+static const glamor_facet glamor_facet_image_text = {
+    .name = "image_text",
+    .version = 130,
+    .vs_vars = vs_vars_text,
+    .vs_exec = vs_exec_text,
+    .fs_vars = fs_vars_text,
+    .fs_exec = fs_exec_text,
+    .source_name = "source",
+    .locations = glamor_program_location_font,
+};
+
+static Bool
+use_image_solid(PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg)
+{
+    return glamor_set_solid(pixmap, gc, FALSE, prog->fg_uniform);
+}
+
+static const glamor_facet glamor_facet_image_fill = {
+    .name = "solid",
+    .fs_exec = "       gl_FragColor = fg;\n",
+    .locations = glamor_program_location_fg,
+    .use = use_image_solid,
+};
+
+static Bool
+glamor_te_text_use(PixmapPtr pixmap, GCPtr gc, glamor_program *prog, void *arg)
+{
+    if (!glamor_set_solid(pixmap, gc, FALSE, prog->fg_uniform))
+        return FALSE;
+    glamor_set_color(pixmap, gc->bgPixel, prog->bg_uniform);
+    return TRUE;
+}
+
+static const glamor_facet glamor_facet_te_text = {
+    .name = "te_text",
+    .version = 130,
+    .vs_vars = vs_vars_text,
+    .vs_exec = vs_exec_text,
+    .fs_vars = fs_vars_text,
+    .fs_exec = fs_exec_te,
+    .locations = glamor_program_location_fg | glamor_program_location_bg | glamor_program_location_font,
+    .source_name = "source",
+    .use = glamor_te_text_use,
+};
+
+static Bool
+glamor_image_text(DrawablePtr drawable, GCPtr gc,
+                  int x, int y, int count, char *chars,
+                  Bool sixteen)
+{
+    ScreenPtr screen = drawable->pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
+    glamor_program *prog;
+    glamor_pixmap_private *pixmap_priv;
+    glamor_font_t *glamor_font;
+    const glamor_facet *prim_facet;
+    const glamor_facet *fill_facet;
+    CharInfoPtr charinfo[255];  /* encoding only has 1 byte for count */
+
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
+    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
+        return FALSE;
+
+    glamor_font = glamor_font_get(drawable->pScreen, gc->font);
+    if (!glamor_font)
+        return FALSE;
+
+    glamor_get_glyphs(gc->font, glamor_font, count, chars, sixteen, charinfo);
+
+    glamor_get_context(glamor_priv);
+
+    if (TERMINALFONT(gc->font))
+        prog = &glamor_priv->te_text_prog;
+    else
+        prog = &glamor_priv->image_text_prog;
+
+    if (prog->failed)
+        goto bail;
+
+    if (!prog->prog) {
+        if (TERMINALFONT(gc->font)) {
+            prim_facet = &glamor_facet_te_text;
+            fill_facet = NULL;
+        } else {
+            prim_facet = &glamor_facet_image_text;
+            fill_facet = &glamor_facet_image_fill;
+        }
+
+        if (!glamor_build_program(screen, prog, prim_facet, fill_facet))
+            goto bail;
+    }
+
+    if (!TERMINALFONT(gc->font)) {
+        int width = 0;
+        int c;
+        RegionRec region;
+        BoxRec box;
+        int off_x, off_y;
+
+        /* Check planemask before drawing background to
+         * bail early if it's not OK
+         */
+        if (!glamor_set_planemask(pixmap, gc->planemask))
+            goto bail;
+        for (c = 0; c < count; c++)
+            if (charinfo[c])
+                width += charinfo[c]->metrics.characterWidth;
+
+        glamor_get_drawable_deltas(drawable, pixmap, &off_x, &off_y);
+
+        if (width >= 0) {
+            box.x1 = off_x + drawable->x + x;
+            box.x2 = off_x + drawable->x + x + width;
+        } else {
+            box.x1 = off_x + drawable->x + x + width;
+            box.x2 = off_x + drawable->x + x;
+        }
+        box.y1 = off_y + drawable->y + y - gc->font->info.fontAscent;
+        box.y2 = off_y + drawable->y + y + gc->font->info.fontDescent;
+        RegionInit(&region, &box, 1);
+        RegionIntersect(&region, &region, gc->pCompositeClip);
+        glamor_solid_boxes(pixmap, RegionRects(&region), RegionNumRects(&region), gc->bgPixel);
+        RegionUninit(&region);
+    }
+
+    if (!glamor_use_program(pixmap, gc, prog, NULL))
+        goto bail;
+
+    (void) glamor_text(drawable, gc, glamor_font, prog,
+                       x, y, count, chars, charinfo, sixteen);
+
+    glamor_put_context(glamor_priv);
+
+    glamor_priv->state = RENDER_STATE;
+    glamor_priv->render_idle_cnt = 0;
+
+    return TRUE;
+
+bail:
+    glDisable(GL_COLOR_LOGIC_OP);
+    glamor_put_context(glamor_priv);
+    return FALSE;
+}
+
+Bool
+glamor_image_text8_nf(DrawablePtr drawable, GCPtr gc,
+                   int x, int y, int count, char *chars)
+{
+    return glamor_image_text(drawable, gc, x, y, count, chars, FALSE);
+}
+
+void
+glamor_image_text8(DrawablePtr drawable, GCPtr gc,
+                   int x, int y, int count, char *chars)
+{
+    if (!glamor_image_text(drawable, gc, x, y, count, chars, FALSE))
+        miImageText8(drawable, gc, x, y, count, chars);
+}
+
+Bool
+glamor_image_text16_nf(DrawablePtr drawable, GCPtr gc,
+                       int x, int y, int count, unsigned short *chars)
+{
+    return glamor_image_text(drawable, gc, x, y, count, (char *) chars, FALSE);
+}
+
+void
+glamor_image_text16(DrawablePtr drawable, GCPtr gc,
+                    int x, int y, int count, unsigned short *chars)
+{
+    if (!glamor_image_text(drawable, gc, x, y, count, (char *) chars, TRUE))
+        miImageText16(drawable, gc, x, y, count, chars);
+}
-- 
1.9.0




More information about the xorg-devel mailing list