xserver: Branch 'master' - 12 commits

Adam Jackson ajax at kemper.freedesktop.org
Thu Mar 10 17:06:29 UTC 2016


 glamor/glamor.c                    |    9 
 glamor/glamor_core.c               |  168 ------
 glamor/glamor_fbo.c                |   12 
 glamor/glamor_picture.c            | 1003 ++++++++-----------------------------
 glamor/glamor_priv.h               |   27 
 glamor/glamor_render.c             |   38 -
 glamor/glamor_utils.h              |   11 
 hw/kdrive/ephyr/ephyr_glamor_glx.c |    4 
 8 files changed, 267 insertions(+), 1005 deletions(-)

New commits:
commit c01094c5312fbd84146dd83122e5256a8e57d092
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:15 2016 -0800

    ephyr: Fix redisplay with glamor on GLES.
    
    glamor_transfer.c is still totally broken, though.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/ephyr_glamor_glx.c b/hw/kdrive/ephyr/ephyr_glamor_glx.c
index 636150d..2f21914 100644
--- a/hw/kdrive/ephyr/ephyr_glamor_glx.c
+++ b/hw/kdrive/ephyr/ephyr_glamor_glx.c
@@ -225,8 +225,10 @@ ephyr_glamor_damage_redisplay(struct ephyr_glamor *glamor,
     if (glamor->vao) {
         glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &old_vao);
         glBindVertexArray(glamor->vao);
-    } else
+    } else {
+        glBindBuffer(GL_ARRAY_BUFFER, glamor->vbo);
         ephyr_glamor_set_vertices(glamor);
+    }
 
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
     glUseProgram(glamor->texture_shader);
commit 0b4c0c75d06f3dbe92be1a26a637e9f05529cb3d
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:14 2016 -0800

    glamor: Replace "finish access" shader with texture swizzling.
    
    For pictures without alpha, and for most other formats for GLES2, we
    would make a temporary FBO, make another temporary texture, upload our
    GLAMOR_MEMORY pixmap to the texture, then run the "finish access" shader
    across it to swizzle its values around into the temporary FBO (which we
    would use for a single Render operation and then throw away).
    
    We can simplify everything by using GL_ARB_texture_swizzle (or its
    GLES3 counterpart).  It's just not worth the complexity to try to
    improve the performance of this already low-performance path (SHM
    pixmaps + Render) on GLES2.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index e9c1d9e..efe5953 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -605,9 +605,15 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_priv->max_fbo_size = MAX_FBO_SIZE;
 #endif
 
+    glamor_priv->has_texture_swizzle =
+        (epoxy_has_gl_extension("GL_ARB_texture_swizzle") ||
+         (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP && gl_version >= 30));
+
     glamor_priv->one_channel_format = GL_ALPHA;
-    if (epoxy_has_gl_extension("GL_ARB_texture_rg") && epoxy_has_gl_extension("GL_ARB_texture_swizzle"))
+    if (epoxy_has_gl_extension("GL_ARB_texture_rg") &&
+        glamor_priv->has_texture_swizzle) {
         glamor_priv->one_channel_format = GL_RED;
+    }
 
     glamor_set_debug_level(&glamor_debug_level);
 
@@ -668,7 +674,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_init_vbo(screen);
     glamor_init_pixmap_fbo(screen);
-    glamor_init_finish_access_shaders(screen);
 
 #ifdef GLAMOR_GRADIENT_SHADER
     glamor_init_gradient_shader(screen);
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index a8768f4..7b2b396 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -113,164 +113,6 @@ glamor_link_glsl_prog(ScreenPtr screen, GLint prog, const char *format, ...)
     }
 }
 
-/*
- *  When downloading a unsupported color format to CPU memory,
-    we need to shuffle the color elements and then use a supported
-    color format to read it back to CPU memory.
-
-    For an example, the picture's format is PICT_b8g8r8a8,
-    Then the expecting color layout is as below (little endian):
-    0	1	2	3   : address
-    a	r	g	b
-
-    Now the in GLES2 the supported color format is GL_RGBA, type is
-    GL_UNSIGNED_TYPE, then we need to shuffle the fragment
-    color as :
-	frag_color = sample(texture).argb;
-    before we use glReadPixel to get it back.
-
-    For the uploading process, the shuffle is a revert shuffle.
-    We still use GL_RGBA, GL_UNSIGNED_BYTE to upload the color
-    to a texture, then let's see
-    0	1	2	3   : address
-    a	r	g	b   : correct colors
-    R	G	B	A   : GL_RGBA with GL_UNSIGNED_BYTE
-
-    Now we need to shuffle again, the mapping rule is
-    r = G, g = B, b = A, a = R. Then the uploading shuffle is as
-    below:
-	frag_color = sample(texture).gbar;
-*/
-
-void
-glamor_init_finish_access_shaders(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-    const char *vs_source =
-        "attribute vec4 v_position;\n"
-        "attribute vec4 v_texcoord0;\n"
-        "varying vec2 source_texture;\n"
-        "void main()\n"
-        "{\n"
-        "	gl_Position = v_position;\n"
-        "	source_texture = v_texcoord0.xy;\n"
-        "}\n";
-
-    const char *common_source =
-        GLAMOR_DEFAULT_PRECISION
-        "varying vec2 source_texture;\n"
-        "uniform sampler2D sampler;\n"
-        "uniform int revert;\n"
-        "uniform int swap_rb;\n"
-        "#define REVERT_NONE       			0\n"
-        "#define REVERT_NORMAL     			1\n"
-        "#define SWAP_UPLOADING	  		2\n"
-        "#define SWAP_NONE_UPLOADING		3\n";
-
-    const char *fs_source =
-        "void main()\n"
-        "{\n"
-        "   vec4 color = texture2D(sampler, source_texture);\n"
-        "   if (revert == REVERT_NONE) \n"
-        "    { \n"
-        "     if ((swap_rb != SWAP_NONE_UPLOADING))   \n"
-        "		gl_FragColor = color.bgra;\n"
-        "     else \n"
-        "		gl_FragColor = color.rgba;\n"
-        "    } \n"
-        "   else \n"
-        "    { \n"
-        "     if (swap_rb == SWAP_UPLOADING)\n"
-        "		gl_FragColor = color.gbar;\n"
-        "     else if (swap_rb == SWAP_NONE_UPLOADING)\n"
-        "		gl_FragColor = color.abgr;\n"
-        "    } \n"
-        "}\n";
-
-    const char *set_alpha_source =
-        "void main()\n"
-        "{\n"
-        "   vec4 color = texture2D(sampler, source_texture);\n"
-        "   if (revert == REVERT_NONE) \n"
-        "    { \n"
-        "     if (swap_rb != SWAP_NONE_UPLOADING)   \n"
-        "		gl_FragColor = vec4(color.bgr, 1);\n"
-        "     else \n"
-        "		gl_FragColor = vec4(color.rgb, 1);\n"
-        "    } \n"
-        "   else \n"
-        "    { \n"
-        "     if (swap_rb == SWAP_UPLOADING)\n"
-        "		gl_FragColor = vec4(color.gba, 1);\n"
-        "     else if (swap_rb == SWAP_NONE_UPLOADING)\n"
-        "		gl_FragColor = vec4(color.abg, 1);\n"
-        "    } \n"
-        "}\n";
-    GLint fs_prog, vs_prog, avs_prog, set_alpha_prog;
-    GLint sampler_uniform_location;
-    char *source;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-    glamor_priv->finish_access_prog[0] = glCreateProgram();
-    glamor_priv->finish_access_prog[1] = glCreateProgram();
-
-    vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
-
-    XNFasprintf(&source, "%s%s", common_source, fs_source);
-    fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, source);
-    free(source);
-
-    glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
-    glAttachShader(glamor_priv->finish_access_prog[0], fs_prog);
-
-    avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
-
-    XNFasprintf(&source, "%s%s", common_source, set_alpha_source);
-    set_alpha_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER,
-                                              source);
-    free(source);
-
-    glAttachShader(glamor_priv->finish_access_prog[1], avs_prog);
-    glAttachShader(glamor_priv->finish_access_prog[1], set_alpha_prog);
-
-    glBindAttribLocation(glamor_priv->finish_access_prog[0],
-                         GLAMOR_VERTEX_POS, "v_position");
-    glBindAttribLocation(glamor_priv->finish_access_prog[0],
-                         GLAMOR_VERTEX_SOURCE, "v_texcoord0");
-    glamor_link_glsl_prog(screen, glamor_priv->finish_access_prog[0],
-                          "finish access 0");
-
-    glBindAttribLocation(glamor_priv->finish_access_prog[1],
-                         GLAMOR_VERTEX_POS, "v_position");
-    glBindAttribLocation(glamor_priv->finish_access_prog[1],
-                         GLAMOR_VERTEX_SOURCE, "v_texcoord0");
-    glamor_link_glsl_prog(screen, glamor_priv->finish_access_prog[1],
-                          "finish access 1");
-
-    glamor_priv->finish_access_revert[0] =
-        glGetUniformLocation(glamor_priv->finish_access_prog[0], "revert");
-
-    glamor_priv->finish_access_swap_rb[0] =
-        glGetUniformLocation(glamor_priv->finish_access_prog[0], "swap_rb");
-    sampler_uniform_location =
-        glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler");
-    glUseProgram(glamor_priv->finish_access_prog[0]);
-    glUniform1i(sampler_uniform_location, 0);
-    glUniform1i(glamor_priv->finish_access_revert[0], 0);
-    glUniform1i(glamor_priv->finish_access_swap_rb[0], 0);
-
-    glamor_priv->finish_access_revert[1] =
-        glGetUniformLocation(glamor_priv->finish_access_prog[1], "revert");
-    glamor_priv->finish_access_swap_rb[1] =
-        glGetUniformLocation(glamor_priv->finish_access_prog[1], "swap_rb");
-    sampler_uniform_location =
-        glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler");
-    glUseProgram(glamor_priv->finish_access_prog[1]);
-    glUniform1i(glamor_priv->finish_access_revert[1], 0);
-    glUniform1i(sampler_uniform_location, 0);
-    glUniform1i(glamor_priv->finish_access_swap_rb[1], 0);
-}
 
 static GCOps glamor_gc_ops = {
     .FillSpans = glamor_fill_spans,
diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 0bfc1dd..d5311a9 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -170,6 +170,17 @@ glamor_pixmap_fbo_cache_put(glamor_screen_private *glamor_priv,
         ("Put cache entry %p to cache %p w %d h %d format %x fbo %d tex %d \n",
          fbo, cache, fbo->width, fbo->height, fbo->format, fbo->fb, fbo->tex);
 
+    /* Reset the texture swizzle that may have been set by
+     * glamor_picture.c.  Don't reset GL_RED -> GL_ALPHA swizzle, though
+     */
+    if (glamor_priv->has_texture_swizzle && n_format != 2) {
+        glBindTexture(GL_TEXTURE_2D, fbo->tex);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_RED);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_GREEN);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_BLUE);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA);
+    }
+
     glamor_priv->fbo_cache_watermark += fbo->width * fbo->height;
     xorg_list_add(&fbo->list, cache);
     fbo->expire = glamor_priv->tick + GLAMOR_CACHE_EXPIRE_MAX;
diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 42fee1b..84a33ad 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -1,4 +1,5 @@
 /*
+ * Copyright © 2016 Broadcom
  * Copyright © 2009 Intel Corporation
  * Copyright © 1998 Keith Packard
  *
@@ -20,10 +21,19 @@
  * 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.
+ */
+
+/**
+ * @file glamor_picture.c
  *
- * Authors:
- *    Zhigang Gong <zhigang.gong at gmail.com>
+ * Implements temporary uploads of GL_MEMORY Pixmaps to a texture that
+ * is swizzled appropriately for a given Render picture format.
+ * laid *
  *
+ * This is important because GTK likes to use SHM Pixmaps for Render
+ * blending operations, and we don't want a blend operation to fall
+ * back to software (readback is more expensive than the upload we do
+ * here, and you'd have to re-upload the fallback output anyway).
  */
 
 #include <stdlib.h>
@@ -31,40 +41,54 @@
 #include "glamor_priv.h"
 #include "mipict.h"
 
-/*
- * Map picture's format to the correct gl texture format and type.
- * no_alpha is used to indicate whehter we need to wire alpha to 1.
- *
- * Although opengl support A1/GL_BITMAP, we still don't use it
- * here, it seems that mesa has bugs when uploading a A1 bitmap.
+static void byte_swap_swizzle(GLenum *swizzle)
+{
+    GLenum temp;
+
+    temp = swizzle[0];
+    swizzle[0] = swizzle[3];
+    swizzle[3] = temp;
+
+    temp = swizzle[1];
+    swizzle[1] = swizzle[2];
+    swizzle[2] = temp;
+}
+
+/**
+ * Returns the GL format and type for uploading our bits to a given PictFormat.
  *
- * Return 0 if find a matched texture type. Otherwise return -1.
- **/
+ * We may need to tell the caller to translate the bits to another
+ * format, as in PICT_a1 (which GL doesn't support).  We may also need
+ * to tell the GL to swizzle the texture on sampling, because GLES3
+ * doesn't support the GL_UNSIGNED_INT_8_8_8_8{,_REV} types, so we
+ * don't have enough channel reordering options at upload time without
+ * it.
+ */
 static Bool
 glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
                                            PictFormatShort format,
+                                           PictFormatShort *temp_format,
                                            GLenum *tex_format,
                                            GLenum *tex_type,
-                                           int *no_alpha,
-                                           int *revert,
-                                           int *swap_rb)
+                                           GLenum *swizzle)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
     Bool is_little_endian = IMAGE_BYTE_ORDER == LSBFirst;
 
-    *no_alpha = 0;
-    *revert = REVERT_NONE;
-    *swap_rb = SWAP_NONE_UPLOADING;
+    *temp_format = format;
+    swizzle[0] = GL_RED;
+    swizzle[1] = GL_GREEN;
+    swizzle[2] = GL_BLUE;
+    swizzle[3] = GL_ALPHA;
 
     switch (format) {
     case PICT_a1:
         *tex_format = glamor_priv->one_channel_format;
         *tex_type = GL_UNSIGNED_BYTE;
-        *revert = REVERT_UPLOADING_A1;
+        *temp_format = PICT_a8;
         break;
 
     case PICT_b8g8r8x8:
-        *no_alpha = 1;
     case PICT_b8g8r8a8:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_BGRA;
@@ -72,13 +96,18 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
         } else {
             *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_BYTE;
-            *swap_rb = SWAP_UPLOADING;
-            *revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
+
+            swizzle[0] = GL_GREEN;
+            swizzle[1] = GL_BLUE;
+            swizzle[2] = GL_ALPHA;
+            swizzle[3] = GL_RED;
+
+            if (!is_little_endian)
+                byte_swap_swizzle(swizzle);
         }
         break;
 
     case PICT_x8r8g8b8:
-        *no_alpha = 1;
     case PICT_a8r8g8b8:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_BGRA;
@@ -86,26 +115,31 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
         } else {
             *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_BYTE;
-            *swap_rb = SWAP_UPLOADING;
-            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
+
+            swizzle[0] = GL_BLUE;
+            swizzle[2] = GL_RED;
+
+            if (!is_little_endian)
+                byte_swap_swizzle(swizzle);
             break;
         }
         break;
 
     case PICT_x8b8g8r8:
-        *no_alpha = 1;
     case PICT_a8b8g8r8:
         *tex_format = GL_RGBA;
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
         } else {
+            *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_BYTE;
-            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
+
+            if (!is_little_endian)
+                byte_swap_swizzle(swizzle);
         }
         break;
 
     case PICT_x2r10g10b10:
-        *no_alpha = 1;
     case PICT_a2r10g10b10:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_BGRA;
@@ -116,7 +150,6 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
         break;
 
     case PICT_x2b10g10r10:
-        *no_alpha = 1;
     case PICT_a2b10g10r10:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_RGBA;
@@ -129,8 +162,6 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
     case PICT_r5g6b5:
         *tex_format = GL_RGB;
         *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP)
-            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
         break;
     case PICT_b5g6r5:
         *tex_format = GL_RGB;
@@ -138,14 +169,12 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
             *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
         } else {
             *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-            if (is_little_endian)
-                *swap_rb = SWAP_UPLOADING;
-            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
+            swizzle[0] = GL_BLUE;
+            swizzle[2] = GL_RED;
         }
         break;
 
     case PICT_x1b5g5r5:
-        *no_alpha = 1;
     case PICT_a1b5g5r5:
         *tex_format = GL_RGBA;
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
@@ -156,7 +185,6 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
         break;
 
     case PICT_x1r5g5b5:
-        *no_alpha = 1;
     case PICT_a1r5g5b5:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_BGRA;
@@ -172,35 +200,36 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
         break;
 
     case PICT_x4r4g4b4:
-        *no_alpha = 1;
     case PICT_a4r4g4b4:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_BGRA;
             *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
         } else {
+            /* XXX */
             *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-            *revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
-            *swap_rb = SWAP_UPLOADING;
         }
         break;
 
     case PICT_x4b4g4r4:
-        *no_alpha = 1;
     case PICT_a4b4g4r4:
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
         } else {
+            /* XXX */
             *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-            *revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
         }
         break;
 
     default:
         return FALSE;
     }
+
+    if (!PICT_FORMAT_A(format))
+        swizzle[3] = GL_ONE;
+
     return TRUE;
 }
 
@@ -238,194 +267,6 @@ glamor_get_converted_image(PictFormatShort dst_format,
 }
 
 /**
- * Upload pixmap to a specified texture.
- * This texture may not be the one attached to it.
- **/
-static Bool
-__glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex,
-                                  GLenum format,
-                                  GLenum type,
-                                  int x, int y, int w, int h,
-                                  void *bits)
-{
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-    int non_sub = 0;
-    unsigned int iformat = 0;
-
-    glamor_make_current(glamor_priv);
-    if (*tex == 0) {
-        glGenTextures(1, tex);
-        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
-            iformat = gl_iformat_for_pixmap(pixmap);
-        else
-            iformat = format;
-        non_sub = 1;
-        assert(x == 0 && y == 0);
-    }
-
-    glBindTexture(GL_TEXTURE_2D, *tex);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-
-    glamor_priv->suppress_gl_out_of_memory_logging = true;
-    if (non_sub)
-        glTexImage2D(GL_TEXTURE_2D, 0, iformat, w, h, 0, format, type, bits);
-    else
-        glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, format, type, bits);
-    glamor_priv->suppress_gl_out_of_memory_logging = false;
-    if (glGetError() == GL_OUT_OF_MEMORY) {
-        if (non_sub) {
-            glDeleteTextures(1, tex);
-            *tex = 0;
-        }
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-static Bool
-_glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
-                                      GLenum type, int no_alpha, int revert,
-                                      int swap_rb, int x, int y, int w, int h,
-                                      int stride, void *bits)
-{
-    ScreenPtr screen = pixmap->drawable.pScreen;
-    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-    float dst_xscale, dst_yscale;
-    GLuint tex = 0;
-    pixman_image_t *converted_image = NULL;
-
-    if (revert == REVERT_UPLOADING_A1) {
-        converted_image = glamor_get_converted_image(PICT_a8,
-                                                     PICT_a1,
-                                                     bits,
-                                                     PixmapBytePad(w, 1),
-                                                     w, h);
-        if (!converted_image)
-            return FALSE;
-
-        bits = pixman_image_get_data(converted_image);
-    }
-
-    /* Try fast path firstly, upload the pixmap to the texture attached
-     * to the fbo directly. */
-    if (no_alpha == 0
-        && revert == REVERT_NONE && swap_rb == SWAP_NONE_UPLOADING) {
-        int fbo_x_off, fbo_y_off;
-
-        assert(pixmap_priv->fbo->tex);
-        pixmap_priv_get_fbo_off(pixmap_priv, &fbo_x_off, &fbo_y_off);
-
-        assert(x + fbo_x_off >= 0 && y + fbo_y_off >= 0);
-        assert(x + fbo_x_off + w <= pixmap_priv->fbo->width);
-        assert(y + fbo_y_off + h <= pixmap_priv->fbo->height);
-        if (!__glamor_upload_pixmap_to_texture(pixmap, &pixmap_priv->fbo->tex,
-                                               format, type,
-                                               x + fbo_x_off, y + fbo_y_off,
-                                               w, h,
-                                               bits)) {
-            if (converted_image)
-                pixman_image_unref(bits);
-            return FALSE;
-        }
-    } else {
-        static const float texcoords_inv[8] = { 0, 0,
-                                                1, 0,
-                                                1, 1,
-                                                0, 1
-        };
-        GLfloat *v;
-        char *vbo_offset;
-
-        v = glamor_get_vbo_space(screen, 16 * sizeof(GLfloat), &vbo_offset);
-
-        pixmap_priv_get_dest_scale(pixmap, pixmap_priv, &dst_xscale, &dst_yscale);
-        glamor_set_normalize_vcoords(pixmap_priv, dst_xscale,
-                                     dst_yscale,
-                                     x, y,
-                                     x + w, y + h,
-                                     v);
-        /* Slow path, we need to flip y or wire alpha to 1. */
-        glamor_make_current(glamor_priv);
-
-        if (!__glamor_upload_pixmap_to_texture(pixmap, &tex,
-                                               format, type, 0, 0, w, h, bits)) {
-            if (converted_image)
-                pixman_image_unref(bits);
-            return FALSE;
-        }
-
-        memcpy(&v[8], texcoords_inv, 8 * sizeof(GLfloat));
-
-        glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
-                              GL_FALSE, 2 * sizeof(float), vbo_offset);
-        glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
-        glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
-                              GL_FALSE, 2 * sizeof(float), vbo_offset + 8 * sizeof(GLfloat));
-        glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-
-        glamor_put_vbo_space(screen);
-        glamor_set_destination_pixmap_priv_nc(glamor_priv, pixmap, pixmap_priv);
-        glamor_set_alu(screen, GXcopy);
-        glActiveTexture(GL_TEXTURE0);
-        glBindTexture(GL_TEXTURE_2D, tex);
-
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-        glUseProgram(glamor_priv->finish_access_prog[no_alpha]);
-        glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert);
-        glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb);
-
-        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-        glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-        glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-        glDeleteTextures(1, &tex);
-        glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    }
-
-    if (converted_image)
-        pixman_image_unref(bits);
-    return TRUE;
-}
-
-/*
- * Prepare to upload a pixmap to texture memory.
- * no_alpha equals 1 means the format needs to wire alpha to 1.
- */
-static int
-glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
-                             int revert, int swap_rb)
-{
-    int flag = 0;
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-    GLenum iformat;
-
-    if (!(no_alpha || (revert == REVERT_NORMAL)
-          || (swap_rb != SWAP_NONE_UPLOADING))) {
-        /* We don't need a fbo, a simple texture uploading should work. */
-
-        flag = GLAMOR_CREATE_FBO_NO_FBO;
-    }
-
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
-        iformat = gl_iformat_for_pixmap(pixmap);
-    else
-        iformat = format;
-
-    if (!glamor_pixmap_ensure_fbo(pixmap, iformat, flag))
-        return -1;
-
-    return 0;
-}
-
-/**
  * Uploads a picture based on a GLAMOR_MEMORY pixmap to a texture in a
  * temporary FBO.
  */
@@ -433,17 +274,24 @@ Bool
 glamor_upload_picture_to_texture(PicturePtr picture)
 {
     PixmapPtr pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-    void *bits = pixmap->devPrivate.ptr;
-    int stride = pixmap->devKind;
     ScreenPtr screen = pixmap->drawable.pScreen;
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    GLenum format, type;
-    int no_alpha, revert, swap_rb;
     glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
+    PictFormatShort converted_format;
+    void *bits = pixmap->devPrivate.ptr;
+    int stride = pixmap->devKind;
+    GLenum format, type;
+    GLenum swizzle[4];
+    GLenum iformat;
+    Bool ret = TRUE;
+    Bool needs_swizzle;
+    pixman_image_t *converted_image = NULL;
 
     assert(glamor_pixmap_is_memory(pixmap));
     assert(!pixmap_priv->fbo);
 
+    glamor_make_current(glamor_priv);
+
     /* No handling of large pixmap pictures here (would need to make
      * an FBO array and split the uploads across it).
      */
@@ -455,20 +303,73 @@ glamor_upload_picture_to_texture(PicturePtr picture)
 
     if (!glamor_get_tex_format_type_from_pictformat(screen,
                                                     picture->format,
+                                                    &converted_format,
                                                     &format,
                                                     &type,
-                                                    &no_alpha,
-                                                    &revert, &swap_rb)) {
+                                                    swizzle)) {
         glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
         return FALSE;
     }
-    if (glamor_pixmap_upload_prepare(pixmap, format, no_alpha, revert, swap_rb))
+
+    needs_swizzle = (swizzle[0] != GL_RED ||
+                     swizzle[1] != GL_GREEN ||
+                     swizzle[2] != GL_BLUE ||
+                     swizzle[3] != GL_ALPHA);
+
+    if (!glamor_priv->has_texture_swizzle && needs_swizzle) {
+        glamor_fallback("Couldn't upload temporary picture due to missing "
+                        "GL_ARB_texture_swizzle.\n");
         return FALSE;
+    }
+
+    if (converted_format != picture->format) {
+        converted_image = glamor_get_converted_image(converted_format,
+                                                     picture->format,
+                                                     bits, stride,
+                                                     pixmap->drawable.width,
+                                                     pixmap->drawable.height);
+        if (!converted_image)
+            return FALSE;
+
+        bits = pixman_image_get_data(converted_image);
+        stride = pixman_image_get_stride(converted_image);
+    }
+
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
+        iformat = gl_iformat_for_pixmap(pixmap);
+    else
+        iformat = format;
+
+    if (!glamor_pixmap_ensure_fbo(pixmap, iformat, GLAMOR_CREATE_FBO_NO_FBO))
+        goto fail;
+
+    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+
+    glamor_priv->suppress_gl_out_of_memory_logging = true;
+
+    /* We can't use glamor_pixmap_loop() because GLAMOR_MEMORY pixmaps
+     * don't have initialized boxes.
+     */
+    glBindTexture(GL_TEXTURE_2D, pixmap_priv->fbo->tex);
+    glTexImage2D(GL_TEXTURE_2D, 0, iformat,
+                 pixmap->drawable.width, pixmap->drawable.height, 0,
+                 format, type, bits);
+
+    if (needs_swizzle) {
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, swizzle[0]);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, swizzle[1]);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, swizzle[2]);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, swizzle[3]);
+    }
+
+    glamor_priv->suppress_gl_out_of_memory_logging = false;
+    if (glGetError() == GL_OUT_OF_MEMORY) {
+        ret = FALSE;
+    }
+
+fail:
+    if (converted_image)
+        pixman_image_unref(converted_image);
 
-    return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
-                                                 no_alpha, revert, swap_rb,
-                                                 0, 0,
-                                                 pixmap->drawable.width,
-                                                 pixmap->drawable.height,
-                                                 stride, bits);
+    return ret;
 }
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 6656b28..8f994ea 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -208,6 +208,7 @@ typedef struct glamor_screen_private {
     Bool use_quads;
     Bool has_vertex_array_object;
     Bool has_dual_blend;
+    Bool has_texture_swizzle;
     Bool is_core_profile;
     int max_fbo_size;
 
@@ -286,11 +287,6 @@ typedef struct glamor_screen_private {
         [glamor_program_alpha_count]
         [SHADER_DEST_SWIZZLE_COUNT];
 
-    /* shaders to restore a texture to another texture. */
-    GLint finish_access_prog[2];
-    GLint finish_access_revert[2];
-    GLint finish_access_swap_rb[2];
-
     /* glamor gradient, 0 for small nstops, 1 for
        large nstops and 2 for dynamic generate. */
     GLint gradient_prog[SHADER_GRADIENT_COUNT][3];
@@ -586,8 +582,6 @@ void glamor_gldrawarrays_quads_using_indices(glamor_screen_private *glamor_priv,
                                              unsigned count);
 
 /* glamor_core.c */
-void glamor_init_finish_access_shaders(ScreenPtr screen);
-
 Bool glamor_get_drawable_location(const DrawablePtr drawable);
 void glamor_get_drawable_deltas(DrawablePtr drawable, PixmapPtr pixmap,
                                 int *x, int *y);
commit b0cc04992ced5d96bb5c52fc1e5c868797cc0a17
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:13 2016 -0800

    glamor: Drop dead large-pixmap handling code in temp picture uploads.
    
    The glamor_pixmap_ensure_fbo() in glamor_pixmap_upload_prepare() will
    always fail on a large pixmap, so we can just be explicit about
    bailing out here and then dump the rest of this garbage.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index e0458a6..42fee1b 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -315,11 +315,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
     /* Try fast path firstly, upload the pixmap to the texture attached
      * to the fbo directly. */
     if (no_alpha == 0
-        && revert == REVERT_NONE && swap_rb == SWAP_NONE_UPLOADING
-#ifdef WALKAROUND_LARGE_TEXTURE_MAP
-        && glamor_pixmap_priv_is_small(pixmap_priv)
-#endif
-        ) {
+        && revert == REVERT_NONE && swap_rb == SWAP_NONE_UPLOADING) {
         int fbo_x_off, fbo_y_off;
 
         assert(pixmap_priv->fbo->tex);
@@ -429,26 +425,6 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
     return 0;
 }
 
-/*
- * upload sub region to a large region.
- * */
-static void
-glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
-                int src_stride, int bpp, int x, int y, int w, int h)
-{
-    int j;
-    int byte_per_pixel;
-
-    byte_per_pixel = bpp / 8;
-    src_bits += y * src_stride + (x * byte_per_pixel);
-
-    for (j = y; j < y + h; j++) {
-        memcpy(dst_bits, src_bits, w * byte_per_pixel);
-        src_bits += src_stride;
-        dst_bits += dst_stride;
-    }
-}
-
 /**
  * Uploads a picture based on a GLAMOR_MEMORY pixmap to a texture in a
  * temporary FBO.
@@ -464,11 +440,19 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     GLenum format, type;
     int no_alpha, revert, swap_rb;
     glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
-    Bool force_clip;
 
     assert(glamor_pixmap_is_memory(pixmap));
     assert(!pixmap_priv->fbo);
 
+    /* No handling of large pixmap pictures here (would need to make
+     * an FBO array and split the uploads across it).
+     */
+    if (!glamor_check_fbo_size(glamor_priv,
+                               pixmap->drawable.width,
+                               pixmap->drawable.height)) {
+        return FALSE;
+    }
+
     if (!glamor_get_tex_format_type_from_pictformat(screen,
                                                     picture->format,
                                                     &format,
@@ -481,89 +465,10 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     if (glamor_pixmap_upload_prepare(pixmap, format, no_alpha, revert, swap_rb))
         return FALSE;
 
-    force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP;
-
-    if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) {
-        RegionRec region;
-        BoxRec box;
-        int n_region;
-        glamor_pixmap_clipped_regions *clipped_regions;
-        void *sub_bits;
-        int i, j;
-
-        sub_bits = xallocarray(pixmap->drawable.height, stride);
-        if (sub_bits == NULL)
-            return FALSE;
-        box.x1 = 0;
-        box.y1 = 0;
-        box.x2 = pixmap->drawable.width;
-        box.y2 = pixmap->drawable.height;
-        RegionInitBoxes(&region, &box, 1);
-        if (!force_clip)
-            clipped_regions =
-                glamor_compute_clipped_regions(pixmap, &region, &n_region,
-                                               0, 0, 0);
-        else
-            clipped_regions =
-                glamor_compute_clipped_regions_ext(pixmap, &region,
-                                                   &n_region,
-                                                   pixmap_priv->block_w,
-                                                   pixmap_priv->block_h,
-                                                   0,
-                                                   0);
-        DEBUGF("prepare upload %dx%d to a large pixmap %p\n", w, h, pixmap);
-        for (i = 0; i < n_region; i++) {
-            BoxPtr boxes;
-            int nbox;
-            int temp_stride;
-            void *temp_bits;
-
-            glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx);
-
-            boxes = RegionRects(clipped_regions[i].region);
-            nbox = RegionNumRects(clipped_regions[i].region);
-            DEBUGF("split to %d boxes\n", nbox);
-            for (j = 0; j < nbox; j++) {
-                temp_stride = PixmapBytePad(boxes[j].x2 - boxes[j].x1,
-                                            pixmap->drawable.depth);
-
-                if (boxes[j].x1 == 0 && temp_stride == stride) {
-                    temp_bits = (char *) bits + boxes[j].y1 * stride;
-                }
-                else {
-                    temp_bits = sub_bits;
-                    glamor_put_bits(temp_bits, temp_stride, bits, stride,
-                                    pixmap->drawable.bitsPerPixel,
-                                    boxes[j].x1, boxes[j].y1,
-                                    boxes[j].x2 - boxes[j].x1,
-                                    boxes[j].y2 - boxes[j].y1);
-                }
-                DEBUGF("upload x %d y %d w %d h %d temp stride %d \n",
-                       boxes[j].x1, boxes[j].y1,
-                       boxes[j].x2 - boxes[j].x1,
-                       boxes[j].y2 - boxes[j].y1, temp_stride);
-                if (!_glamor_upload_bits_to_pixmap_texture
-                    (pixmap, format, type, no_alpha, revert, swap_rb,
-                     boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1,
-                     boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits)) {
-                    RegionUninit(&region);
-                    free(sub_bits);
-                    assert(0);
-                    return FALSE;
-                }
-            }
-            RegionDestroy(clipped_regions[i].region);
-        }
-        free(sub_bits);
-        free(clipped_regions);
-        RegionUninit(&region);
-        return TRUE;
-    }
-    else
-        return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
-                                                     no_alpha, revert, swap_rb,
-                                                     0, 0,
-                                                     pixmap->drawable.width,
-                                                     pixmap->drawable.height,
-                                                     stride, bits);
+    return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
+                                                 no_alpha, revert, swap_rb,
+                                                 0, 0,
+                                                 pixmap->drawable.width,
+                                                 pixmap->drawable.height,
+                                                 stride, bits);
 }
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 422b0fd..6656b28 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -926,7 +926,6 @@ void glamor_xv_render(glamor_port_private *port_priv);
 #define GLAMOR_PIXMAP_DYNAMIC_UPLOAD
 #define GLAMOR_GRADIENT_SHADER
 #define GLAMOR_TEXTURED_LARGE_PIXMAP 1
-#define WALKAROUND_LARGE_TEXTURE_MAP
 #if 0
 #define MAX_FBO_SIZE 32         /* For test purpose only. */
 #endif
commit 094b1bea8bd08eec029e4d61ba40d81441c37905
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:12 2016 -0800

    glamor: Drop unused PBO code in temporary picture uploading.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index e0f5828..e0458a6 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -246,7 +246,7 @@ __glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex,
                                   GLenum format,
                                   GLenum type,
                                   int x, int y, int w, int h,
-                                  void *bits, int pbo)
+                                  void *bits)
 {
     glamor_screen_private *glamor_priv =
         glamor_get_screen_private(pixmap->drawable.pScreen);
@@ -269,11 +269,6 @@ __glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex,
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 
-    assert(pbo || bits != 0);
-    if (bits == NULL) {
-        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
-        glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
-    }
     glamor_priv->suppress_gl_out_of_memory_logging = true;
     if (non_sub)
         glTexImage2D(GL_TEXTURE_2D, 0, iformat, w, h, 0, format, type, bits);
@@ -288,9 +283,6 @@ __glamor_upload_pixmap_to_texture(PixmapPtr pixmap, unsigned int *tex,
         return FALSE;
     }
 
-    if (bits == NULL)
-        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
-
     return TRUE;
 }
 
@@ -298,7 +290,7 @@ static Bool
 _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
                                       GLenum type, int no_alpha, int revert,
                                       int swap_rb, int x, int y, int w, int h,
-                                      int stride, void *bits, int pbo)
+                                      int stride, void *bits)
 {
     ScreenPtr screen = pixmap->drawable.pScreen;
     glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
@@ -308,9 +300,6 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
     GLuint tex = 0;
     pixman_image_t *converted_image = NULL;
 
-    if (bits == NULL)
-        goto ready_to_upload;
-
     if (revert == REVERT_UPLOADING_A1) {
         converted_image = glamor_get_converted_image(PICT_a8,
                                                      PICT_a1,
@@ -323,8 +312,6 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
         bits = pixman_image_get_data(converted_image);
     }
 
- ready_to_upload:
-
     /* Try fast path firstly, upload the pixmap to the texture attached
      * to the fbo directly. */
     if (no_alpha == 0
@@ -345,7 +332,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
                                                format, type,
                                                x + fbo_x_off, y + fbo_y_off,
                                                w, h,
-                                               bits, pbo)) {
+                                               bits)) {
             if (converted_image)
                 pixman_image_unref(bits);
             return FALSE;
@@ -371,8 +358,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
         glamor_make_current(glamor_priv);
 
         if (!__glamor_upload_pixmap_to_texture(pixmap, &tex,
-                                               format, type, 0, 0, w, h, bits,
-                                               pbo)) {
+                                               format, type, 0, 0, w, h, bits)) {
             if (converted_image)
                 pixman_image_unref(bits);
             return FALSE;
@@ -556,11 +542,10 @@ glamor_upload_picture_to_texture(PicturePtr picture)
                        boxes[j].x1, boxes[j].y1,
                        boxes[j].x2 - boxes[j].x1,
                        boxes[j].y2 - boxes[j].y1, temp_stride);
-                if (_glamor_upload_bits_to_pixmap_texture
+                if (!_glamor_upload_bits_to_pixmap_texture
                     (pixmap, format, type, no_alpha, revert, swap_rb,
                      boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1,
-                     boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits,
-                     0) == FALSE) {
+                     boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits)) {
                     RegionUninit(&region);
                     free(sub_bits);
                     assert(0);
@@ -580,6 +565,5 @@ glamor_upload_picture_to_texture(PicturePtr picture)
                                                      0, 0,
                                                      pixmap->drawable.width,
                                                      pixmap->drawable.height,
-                                                     stride, bits,
-                                                     0);
+                                                     stride, bits);
 }
commit 6112fecc3a4fd7dfb0ef77a98cfd1f7c91ccea0c
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:11 2016 -0800

    glamor: Generalize the a1-to-a8 conversion path.
    
    Pixman is quite qualified to allocate our temporary memory, and all we
    need to do is decide what formats to convert from and to.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 63d4365..e0f5828 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -204,21 +204,26 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
     return TRUE;
 }
 
-static void *
-glamor_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h, int stride)
+/**
+ * Takes a set of source bits with a given format and returns an
+ * in-memory pixman image of those bits in a destination format.
+ */
+static pixman_image_t *
+glamor_get_converted_image(PictFormatShort dst_format,
+                           PictFormatShort src_format,
+                           void *src_bits,
+                           int src_stride,
+                           int w, int h)
 {
-    PictFormatShort dst_format = PICT_a8, src_format = PICT_a1;
     pixman_image_t *dst_image;
     pixman_image_t *src_image;
-    int src_stride = PixmapBytePad(w, 1);
 
-    dst_image = pixman_image_create_bits(dst_format, w, h, dst_bits, stride);
+    dst_image = pixman_image_create_bits(dst_format, w, h, NULL, 0);
     if (dst_image == NULL) {
         return NULL;
     }
 
-    src_image = pixman_image_create_bits(src_format,
-                                         w, h, src_bits, src_stride);
+    src_image = pixman_image_create_bits(src_format, w, h, src_bits, src_stride);
 
     if (src_image == NULL) {
         pixman_image_unref(dst_image);
@@ -229,8 +234,7 @@ glamor_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h, int stride)
                            0, 0, 0, 0, 0, 0, w, h);
 
     pixman_image_unref(src_image);
-    pixman_image_unref(dst_image);
-    return dst_bits;
+    return dst_image;
 }
 
 /**
@@ -302,34 +306,21 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
         glamor_get_screen_private(pixmap->drawable.pScreen);
     float dst_xscale, dst_yscale;
     GLuint tex = 0;
-    int need_free_bits = 0;
+    pixman_image_t *converted_image = NULL;
 
     if (bits == NULL)
         goto ready_to_upload;
 
     if (revert == REVERT_UPLOADING_A1) {
-        /* XXX if we are restoring the pixmap, then we may not need to allocate
-         * new buffer */
-        void *converted_bits;
-
-        if (pixmap->drawable.depth == 1)
-            stride = (((w * 8 + 7) / 8) + 3) & ~3;
-
-        converted_bits = xallocarray(h, stride);
-
-        if (converted_bits == NULL)
-            return FALSE;
-        bits = glamor_convert_a1_a8(bits, converted_bits, w, h, stride);
-        if (bits == NULL) {
-            free(converted_bits);
-            ErrorF("Failed to convert pixmap no_alpha %d,"
-                   "revert mode %d, swap mode %d\n", no_alpha, revert, swap_rb);
+        converted_image = glamor_get_converted_image(PICT_a8,
+                                                     PICT_a1,
+                                                     bits,
+                                                     PixmapBytePad(w, 1),
+                                                     w, h);
+        if (!converted_image)
             return FALSE;
-        }
-        no_alpha = 0;
-        revert = REVERT_NONE;
-        swap_rb = SWAP_NONE_UPLOADING;
-        need_free_bits = TRUE;
+
+        bits = pixman_image_get_data(converted_image);
     }
 
  ready_to_upload:
@@ -355,8 +346,8 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
                                                x + fbo_x_off, y + fbo_y_off,
                                                w, h,
                                                bits, pbo)) {
-            if (need_free_bits)
-                free(bits);
+            if (converted_image)
+                pixman_image_unref(bits);
             return FALSE;
         }
     } else {
@@ -382,8 +373,8 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
         if (!__glamor_upload_pixmap_to_texture(pixmap, &tex,
                                                format, type, 0, 0, w, h, bits,
                                                pbo)) {
-            if (need_free_bits)
-                free(bits);
+            if (converted_image)
+                pixman_image_unref(bits);
             return FALSE;
         }
 
@@ -416,8 +407,8 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
         glBindFramebuffer(GL_FRAMEBUFFER, 0);
     }
 
-    if (need_free_bits)
-        free(bits);
+    if (converted_image)
+        pixman_image_unref(bits);
     return TRUE;
 }
 
commit 8f1411c3847a742f84ff07c4a0bb610801f5bfee
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:10 2016 -0800

    glamor: Drop the REVERT_UPLOADING_1_5_5_5 path.
    
    There was only a pretty special case that could have even worked --
    you've got a GLES2 renderer, you've got a SHM pixmap, it's 1555 (not
    the usual 565 for 16-bit), and you're little endian (BE was broken,
    since GL's 5_5_5_1 picks the 1 bit from the lowest bit of the short,
    and on BE we weren't doing the conversion path that swaps around the
    channels).  This is just not worth the complexity.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 5c6a1a5..63d4365 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -151,11 +151,7 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
         if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
             *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
         } else {
-            *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-            if (is_little_endian)
-                *revert = REVERT_UPLOADING_1_5_5_5;
-            else
-                *revert = REVERT_NONE;
+            return FALSE;
         }
         break;
 
@@ -166,13 +162,7 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
             *tex_format = GL_BGRA;
             *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
         } else {
-            *tex_format = GL_RGBA;
-            *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-            if (is_little_endian)
-                *revert = REVERT_UPLOADING_1_5_5_5;
-            else
-                *revert = REVERT_NONE;
-            *swap_rb = SWAP_UPLOADING;
+            return FALSE;
         }
         break;
 
@@ -215,8 +205,7 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
 }
 
 static void *
-_glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
-                            int stride)
+glamor_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h, int stride)
 {
     PictFormatShort dst_format = PICT_a8, src_format = PICT_a1;
     pixman_image_t *dst_image;
@@ -244,107 +233,6 @@ _glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
     return dst_bits;
 }
 
-#define ADJUST_BITS(d, src_bits, dst_bits)	(((dst_bits) == (src_bits)) ? (d) : 				\
-							(((dst_bits) > (src_bits)) ? 				\
-							  (((d) << ((dst_bits) - (src_bits))) 			\
-								   + (( 1 << ((dst_bits) - (src_bits))) >> 1))	\
-								:  ((d) >> ((src_bits) - (dst_bits)))))
-
-#define GLAMOR_DO_CONVERT(src, dst, no_alpha, swap,		\
-			  a_shift_src, a_bits_src,		\
-			  b_shift_src, b_bits_src,		\
-			  g_shift_src, g_bits_src,		\
-			  r_shift_src, r_bits_src,		\
-			  a_shift, a_bits,			\
-			  b_shift, b_bits,			\
-			  g_shift, g_bits,			\
-			  r_shift, r_bits)			\
-	do {								\
-		typeof(src) a,b,g,r;					\
-		typeof(src) a_mask_src, b_mask_src, g_mask_src, r_mask_src;\
-		a_mask_src = (((1 << (a_bits_src)) - 1) << a_shift_src);\
-		b_mask_src = (((1 << (b_bits_src)) - 1) << b_shift_src);\
-		g_mask_src = (((1 << (g_bits_src)) - 1) << g_shift_src);\
-		r_mask_src = (((1 << (r_bits_src)) - 1) << r_shift_src);\
-		if (no_alpha)						\
-			a = (a_mask_src) >> (a_shift_src);			\
-		else							\
-			a = ((src) & (a_mask_src)) >> (a_shift_src);	\
-		b = ((src) & (b_mask_src)) >> (b_shift_src);		\
-		g = ((src) & (g_mask_src)) >> (g_shift_src);		\
-		r = ((src) & (r_mask_src)) >> (r_shift_src);		\
-		a = ADJUST_BITS(a, a_bits_src, a_bits);			\
-		b = ADJUST_BITS(b, b_bits_src, b_bits);			\
-		g = ADJUST_BITS(g, g_bits_src, g_bits);			\
-		r = ADJUST_BITS(r, r_bits_src, r_bits);			\
-		if (swap == 0)						\
-			(*dst) = ((a) << (a_shift)) | ((b) << (b_shift)) | ((g) << (g_shift)) | ((r) << (r_shift)); \
-		else 												    \
-			(*dst) = ((a) << (a_shift)) | ((r) << (b_shift)) | ((g) << (g_shift)) | ((b) << (r_shift)); \
-	} while (0)
-
-
-static void *
-_glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
-                              int stride, int no_alpha, int swap_rb)
-{
-    int x, y;
-    unsigned short *words, *saved_words, *source_words;
-    int swap = swap_rb != SWAP_NONE_UPLOADING;
-
-    words = dst_bits;
-    source_words = src_bits;
-    saved_words = words;
-
-    for (y = 0; y < h; y++) {
-        DEBUGF("Line %d :  ", y);
-        for (x = 0; x < w; x++) {
-            unsigned short pixel = source_words[x];
-
-            GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                              15, 1, 10, 5, 5, 5, 0, 5,
-                              0, 1, 1, 5, 6, 5, 11, 5);
-            DEBUGF("%04x:%04x ", pixel, words[x]);
-        }
-        DEBUGF("\n");
-        words += stride / sizeof(*words);
-        source_words += stride / sizeof(*words);
-    }
-    DEBUGF("\n");
-    return saved_words;
-}
-
-/*
- * This function is to convert an unsupported color format to/from a
- * supported GL format.
- * Here are the current scenarios:
- *
- * @no_alpha:
- * 	If it is set, then we need to wire the alpha value to 1.
- * @revert:
-	REVERT_UPLOADING_A1		: convert an A1 buffer to an Alpha8 buffer
-	REVERT_UPLOADING_1_5_5_5    	: convert X1R5G5B5 to B5G5R5X1
-   @swap_rb: if we have the swap_rb set, then we need to swap the R and B's position.
- *
- */
-
-static void *
-glamor_color_convert_to_bits(void *src_bits, void *dst_bits, int w, int h,
-                             int stride, int no_alpha, int revert, int swap_rb)
-{
-    if (revert == REVERT_UPLOADING_A1) {
-        return _glamor_color_convert_a1_a8(src_bits, dst_bits, w, h, stride);
-    }
-    else if (revert == REVERT_UPLOADING_1_5_5_5) {
-        return _glamor_color_revert_x1b5g5r5(src_bits, dst_bits, w, h, stride,
-                                             no_alpha, swap_rb);
-    }
-    else
-        ErrorF("convert a non-supported mode %x.\n", revert);
-
-    return NULL;
-}
-
 /**
  * Upload pixmap to a specified texture.
  * This texture may not be the one attached to it.
@@ -419,7 +307,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
     if (bits == NULL)
         goto ready_to_upload;
 
-    if (revert > REVERT_NORMAL) {
+    if (revert == REVERT_UPLOADING_A1) {
         /* XXX if we are restoring the pixmap, then we may not need to allocate
          * new buffer */
         void *converted_bits;
@@ -431,8 +319,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
 
         if (converted_bits == NULL)
             return FALSE;
-        bits = glamor_color_convert_to_bits(bits, converted_bits, w, h,
-                                            stride, no_alpha, revert, swap_rb);
+        bits = glamor_convert_a1_a8(bits, converted_bits, w, h, stride);
         if (bits == NULL) {
             free(converted_bits);
             ErrorF("Failed to convert pixmap no_alpha %d,"
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index fc33995..5617611 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -768,7 +768,6 @@ format_for_pixmap(PixmapPtr pixmap)
 #define REVERT_NONE       		0
 #define REVERT_NORMAL     		1
 #define REVERT_UPLOADING_A1		3
-#define REVERT_UPLOADING_1_5_5_5    	8
 
 #define SWAP_UPLOADING	  	2
 #define SWAP_NONE_UPLOADING	3
commit 2cc7a0815e5e2c2b1b1267cae9c348a8e95b1082
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:09 2016 -0800

    glamor: Drop the GLES2 REVERT_UPLOADING_2_10_10_10 paths.
    
    These just smash your 2_10_10_10 data into 8888, despite what the
    comments said.  That's not valid rendering, so just ditch this path
    and fall back to software.  One might also note in the code being
    removed here that the REVERT_UPLOADING_10_10_10_2 path wasn't even
    connected.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index e11280f..5c6a1a5 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -111,18 +111,7 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
             *tex_format = GL_BGRA;
             *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
         } else {
-            /* glReadPixmap doesn't support
-             * GL_UNSIGNED_INT_10_10_10_2.  We have to use
-             * GL_UNSIGNED_BYTE and do the conversion in a shader
-             * later.
-             */
-            *tex_format = GL_RGBA;
-            *tex_type = GL_UNSIGNED_BYTE;
-            if (!is_little_endian)
-                *revert = REVERT_UPLOADING_10_10_10_2;
-            else
-                *revert = REVERT_UPLOADING_2_10_10_10;
-            *swap_rb = SWAP_UPLOADING;
+            return FALSE;
         }
         break;
 
@@ -133,13 +122,7 @@ glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
             *tex_format = GL_RGBA;
             *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
         } else {
-            *tex_format = GL_RGBA;
-            *tex_type = GL_UNSIGNED_BYTE;
-            if (!is_little_endian)
-                *revert = REVERT_UPLOADING_10_10_10_2;
-            else
-                *revert = REVERT_UPLOADING_2_10_10_10;
-            break;
+            return FALSE;
         }
         break;
 
@@ -300,37 +283,6 @@ _glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
 			(*dst) = ((a) << (a_shift)) | ((r) << (b_shift)) | ((g) << (g_shift)) | ((b) << (r_shift)); \
 	} while (0)
 
-static void *
-_glamor_color_revert_x2b10g10r10(void *src_bits, void *dst_bits, int w, int h,
-                                 int stride, int no_alpha,
-                                 int swap_rb)
-{
-    int x, y;
-    unsigned int *words, *saved_words, *source_words;
-    int swap = swap_rb != SWAP_NONE_UPLOADING;
-
-    source_words = src_bits;
-    words = dst_bits;
-    saved_words = words;
-
-    for (y = 0; y < h; y++) {
-        DEBUGF("Line %d :  ", y);
-        for (x = 0; x < w; x++) {
-            unsigned int pixel = source_words[x];
-
-            GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                              30, 2, 20, 10, 10, 10, 0, 10,
-                              24, 8, 16, 8, 8, 8, 0, 8);
-            DEBUGF("%x:%x ", pixel, words[x]);
-        }
-        DEBUGF("\n");
-        words += stride / sizeof(*words);
-        source_words += stride / sizeof(*words);
-    }
-    DEBUGF("\n");
-    return saved_words;
-
-}
 
 static void *
 _glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
@@ -371,7 +323,6 @@ _glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
  * 	If it is set, then we need to wire the alpha value to 1.
  * @revert:
 	REVERT_UPLOADING_A1		: convert an A1 buffer to an Alpha8 buffer
-	REVERT_UPLOADING_2_10_10_10 	: convert X2B10G10R10 to R10G10B10X2
 	REVERT_UPLOADING_1_5_5_5    	: convert X1R5G5B5 to B5G5R5X1
    @swap_rb: if we have the swap_rb set, then we need to swap the R and B's position.
  *
@@ -384,10 +335,6 @@ glamor_color_convert_to_bits(void *src_bits, void *dst_bits, int w, int h,
     if (revert == REVERT_UPLOADING_A1) {
         return _glamor_color_convert_a1_a8(src_bits, dst_bits, w, h, stride);
     }
-    else if (revert == REVERT_UPLOADING_2_10_10_10) {
-        return _glamor_color_revert_x2b10g10r10(src_bits, dst_bits, w, h,
-                                                stride, no_alpha, swap_rb);
-    }
     else if (revert == REVERT_UPLOADING_1_5_5_5) {
         return _glamor_color_revert_x1b5g5r5(src_bits, dst_bits, w, h, stride,
                                              no_alpha, swap_rb);
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index e23de86..fc33995 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -768,9 +768,7 @@ format_for_pixmap(PixmapPtr pixmap)
 #define REVERT_NONE       		0
 #define REVERT_NORMAL     		1
 #define REVERT_UPLOADING_A1		3
-#define REVERT_UPLOADING_2_10_10_10 	5
 #define REVERT_UPLOADING_1_5_5_5    	8
-#define REVERT_UPLOADING_10_10_10_2 	10
 
 #define SWAP_UPLOADING	  	2
 #define SWAP_NONE_UPLOADING	3
commit f667d5177024d3fdfb1b51694bdaeba6cee67962
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:08 2016 -0800

    glamor: Merge the two GL-type-from-pictformat paths.
    
    It clarifies what the difference is between the two paths, and would
    potentially encourage us to handle GLES extensions that expose
    additional types.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 34cf4a3..e11280f 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -40,275 +40,195 @@
  *
  * Return 0 if find a matched texture type. Otherwise return -1.
  **/
-static int
-glamor_get_tex_format_type_from_pictformat_gl(ScreenPtr pScreen,
-                                              PictFormatShort format,
-                                              GLenum *tex_format,
-                                              GLenum *tex_type,
-                                              int *no_alpha,
-                                              int *revert,
-                                              int *swap_rb)
+static Bool
+glamor_get_tex_format_type_from_pictformat(ScreenPtr pScreen,
+                                           PictFormatShort format,
+                                           GLenum *tex_format,
+                                           GLenum *tex_type,
+                                           int *no_alpha,
+                                           int *revert,
+                                           int *swap_rb)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
+    Bool is_little_endian = IMAGE_BYTE_ORDER == LSBFirst;
+
     *no_alpha = 0;
     *revert = REVERT_NONE;
     *swap_rb = SWAP_NONE_UPLOADING;
+
     switch (format) {
     case PICT_a1:
         *tex_format = glamor_priv->one_channel_format;
         *tex_type = GL_UNSIGNED_BYTE;
         *revert = REVERT_UPLOADING_A1;
         break;
-    case PICT_b8g8r8x8:
-        *no_alpha = 1;
-    case PICT_b8g8r8a8:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_INT_8_8_8_8;
-        break;
-
-    case PICT_x8r8g8b8:
-        *no_alpha = 1;
-    case PICT_a8r8g8b8:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-        break;
-    case PICT_x8b8g8r8:
-        *no_alpha = 1;
-    case PICT_a8b8g8r8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-        break;
-    case PICT_x2r10g10b10:
-        *no_alpha = 1;
-    case PICT_a2r10g10b10:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
-        break;
-    case PICT_x2b10g10r10:
-        *no_alpha = 1;
-    case PICT_a2b10g10r10:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
-        break;
-
-    case PICT_r5g6b5:
-        *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        break;
-    case PICT_b5g6r5:
-        *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
-        break;
-    case PICT_x1b5g5r5:
-        *no_alpha = 1;
-    case PICT_a1b5g5r5:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
-        break;
-
-    case PICT_x1r5g5b5:
-        *no_alpha = 1;
-    case PICT_a1r5g5b5:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
-        break;
-    case PICT_a8:
-        *tex_format = glamor_priv->one_channel_format;
-        *tex_type = GL_UNSIGNED_BYTE;
-        break;
-    case PICT_x4r4g4b4:
-        *no_alpha = 1;
-    case PICT_a4r4g4b4:
-        *tex_format = GL_BGRA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
-        break;
-
-    case PICT_x4b4g4r4:
-        *no_alpha = 1;
-    case PICT_a4b4g4r4:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
-        break;
-
-    default:
-        return -1;
-    }
-    return 0;
-}
-
-#define IS_LITTLE_ENDIAN  (IMAGE_BYTE_ORDER == LSBFirst)
-
-static int
-glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
-                                                 PictFormatShort format,
-                                                 GLenum *tex_format,
-                                                 GLenum *tex_type,
-                                                 int *no_alpha,
-                                                 int *revert,
-                                                 int *swap_rb)
-{
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
-    int need_swap_rb = 0;
 
-    *no_alpha = 0;
-    *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
-
-    switch (format) {
     case PICT_b8g8r8x8:
         *no_alpha = 1;
     case PICT_b8g8r8a8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        need_swap_rb = 1;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_BGRA;
+            *tex_type = GL_UNSIGNED_INT_8_8_8_8;
+        } else {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_BYTE;
+            *swap_rb = SWAP_UPLOADING;
+            *revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
+        }
         break;
 
     case PICT_x8r8g8b8:
         *no_alpha = 1;
     case PICT_a8r8g8b8:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        need_swap_rb = 1;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_BGRA;
+            *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+        } else {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_BYTE;
+            *swap_rb = SWAP_UPLOADING;
+            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
+            break;
+        }
         break;
 
     case PICT_x8b8g8r8:
         *no_alpha = 1;
     case PICT_a8b8g8r8:
         *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+        } else {
+            *tex_type = GL_UNSIGNED_BYTE;
+            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
+        }
         break;
 
     case PICT_x2r10g10b10:
         *no_alpha = 1;
     case PICT_a2r10g10b10:
-        *tex_format = GL_RGBA;
-        /* glReadPixmap doesn't support GL_UNSIGNED_INT_10_10_10_2.
-         * we have to use GL_UNSIGNED_BYTE and do the conversion in
-         * shader latter.*/
-        *tex_type = GL_UNSIGNED_BYTE;
-        if (!IS_LITTLE_ENDIAN)
-            *revert = REVERT_UPLOADING_10_10_10_2;
-        else
-            *revert = REVERT_UPLOADING_2_10_10_10;
-        need_swap_rb = 1;
-
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_BGRA;
+            *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+        } else {
+            /* glReadPixmap doesn't support
+             * GL_UNSIGNED_INT_10_10_10_2.  We have to use
+             * GL_UNSIGNED_BYTE and do the conversion in a shader
+             * later.
+             */
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_BYTE;
+            if (!is_little_endian)
+                *revert = REVERT_UPLOADING_10_10_10_2;
+            else
+                *revert = REVERT_UPLOADING_2_10_10_10;
+            *swap_rb = SWAP_UPLOADING;
+        }
         break;
 
     case PICT_x2b10g10r10:
         *no_alpha = 1;
     case PICT_a2b10g10r10:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_BYTE;
-        if (!IS_LITTLE_ENDIAN)
-            *revert = REVERT_UPLOADING_10_10_10_2;
-        else
-            *revert = REVERT_UPLOADING_2_10_10_10;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_INT_2_10_10_10_REV;
+        } else {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_BYTE;
+            if (!is_little_endian)
+                *revert = REVERT_UPLOADING_10_10_10_2;
+            else
+                *revert = REVERT_UPLOADING_2_10_10_10;
+            break;
+        }
         break;
 
     case PICT_r5g6b5:
         *tex_format = GL_RGB;
         *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NONE : REVERT_NORMAL;
-
+        if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP)
+            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
         break;
-
     case PICT_b5g6r5:
         *tex_format = GL_RGB;
-        *tex_type = GL_UNSIGNED_SHORT_5_6_5;
-        need_swap_rb = IS_LITTLE_ENDIAN ? 1 : 0;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_type = GL_UNSIGNED_SHORT_5_6_5_REV;
+        } else {
+            *tex_type = GL_UNSIGNED_SHORT_5_6_5;
+            if (is_little_endian)
+                *swap_rb = SWAP_UPLOADING;
+            *revert = is_little_endian ? REVERT_NONE : REVERT_NORMAL;
+        }
         break;
 
     case PICT_x1b5g5r5:
         *no_alpha = 1;
     case PICT_a1b5g5r5:
         *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-        if (IS_LITTLE_ENDIAN)
-            *revert = REVERT_UPLOADING_1_5_5_5;
-        else
-            *revert = REVERT_NONE;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+        } else {
+            *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
+            if (is_little_endian)
+                *revert = REVERT_UPLOADING_1_5_5_5;
+            else
+                *revert = REVERT_NONE;
+        }
         break;
 
     case PICT_x1r5g5b5:
         *no_alpha = 1;
     case PICT_a1r5g5b5:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-        if (IS_LITTLE_ENDIAN)
-            *revert = REVERT_UPLOADING_1_5_5_5;
-        else
-            *revert = REVERT_NONE;
-        need_swap_rb = 1;
-        break;
-
-    case PICT_a1:
-        *tex_format = glamor_priv->one_channel_format;
-        *tex_type = GL_UNSIGNED_BYTE;
-        *revert = REVERT_UPLOADING_A1;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_BGRA;
+            *tex_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
+        } else {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
+            if (is_little_endian)
+                *revert = REVERT_UPLOADING_1_5_5_5;
+            else
+                *revert = REVERT_NONE;
+            *swap_rb = SWAP_UPLOADING;
+        }
         break;
 
     case PICT_a8:
         *tex_format = glamor_priv->one_channel_format;
         *tex_type = GL_UNSIGNED_BYTE;
-        *revert = REVERT_NONE;
         break;
 
     case PICT_x4r4g4b4:
         *no_alpha = 1;
     case PICT_a4r4g4b4:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
-        need_swap_rb = 1;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_BGRA;
+            *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+        } else {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
+            *revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
+            *swap_rb = SWAP_UPLOADING;
+        }
         break;
 
     case PICT_x4b4g4r4:
         *no_alpha = 1;
     case PICT_a4b4g4r4:
-        *tex_format = GL_RGBA;
-        *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
-        *revert = IS_LITTLE_ENDIAN ? REVERT_NORMAL : REVERT_NONE;
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
+        } else {
+            *tex_format = GL_RGBA;
+            *tex_type = GL_UNSIGNED_SHORT_4_4_4_4;
+            *revert = is_little_endian ? REVERT_NORMAL : REVERT_NONE;
+        }
         break;
 
     default:
-        LogMessageVerb(X_INFO, 0,
-                       "fail to get matched format for %x \n", format);
-        return -1;
-    }
-
-    if (need_swap_rb)
-        *swap_rb = SWAP_UPLOADING;
-    else
-        *swap_rb = SWAP_NONE_UPLOADING;
-    return 0;
-}
-
-static int
-glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
-                                       PictFormatShort pict_format,
-                                       GLenum *format,
-                                       GLenum *type,
-                                       int *no_alpha,
-                                       int *revert, int *swap_rb)
-{
-    glamor_screen_private *glamor_priv =
-        glamor_get_screen_private(pixmap->drawable.pScreen);
-
-    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
-        return glamor_get_tex_format_type_from_pictformat_gl(pixmap->drawable.pScreen,
-                                                             pict_format,
-                                                             format, type,
-                                                             no_alpha,
-                                                             revert,
-                                                             swap_rb);
-    } else {
-        return glamor_get_tex_format_type_from_pictformat_gles2(pixmap->drawable.pScreen,
-                                                                pict_format,
-                                                                format, type,
-                                                                no_alpha,
-                                                                revert,
-                                                                swap_rb);
+        return FALSE;
     }
+    return TRUE;
 }
 
 static void *
@@ -738,12 +658,12 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     assert(glamor_pixmap_is_memory(pixmap));
     assert(!pixmap_priv->fbo);
 
-    if (glamor_get_tex_format_type_from_pixmap(pixmap,
-                                               picture->format,
-                                               &format,
-                                               &type,
-                                               &no_alpha,
-                                               &revert, &swap_rb)) {
+    if (!glamor_get_tex_format_type_from_pictformat(screen,
+                                                    picture->format,
+                                                    &format,
+                                                    &type,
+                                                    &no_alpha,
+                                                    &revert, &swap_rb)) {
         glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
         return FALSE;
     }
commit c7574c63c618d3a017105c380542eb04341b04a2
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:07 2016 -0800

    glamor: Propagate that is_upload is always true.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index b9948b5..a8768f4 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -164,8 +164,6 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
         "uniform int swap_rb;\n"
         "#define REVERT_NONE       			0\n"
         "#define REVERT_NORMAL     			1\n"
-        "#define SWAP_NONE_DOWNLOADING  		0\n"
-        "#define SWAP_DOWNLOADING  			1\n"
         "#define SWAP_UPLOADING	  		2\n"
         "#define SWAP_NONE_UPLOADING		3\n";
 
@@ -175,18 +173,14 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
         "   vec4 color = texture2D(sampler, source_texture);\n"
         "   if (revert == REVERT_NONE) \n"
         "    { \n"
-        "     if ((swap_rb != SWAP_NONE_DOWNLOADING) && (swap_rb != SWAP_NONE_UPLOADING))   \n"
+        "     if ((swap_rb != SWAP_NONE_UPLOADING))   \n"
         "		gl_FragColor = color.bgra;\n"
         "     else \n"
         "		gl_FragColor = color.rgba;\n"
         "    } \n"
         "   else \n"
         "    { \n"
-        "     if (swap_rb == SWAP_DOWNLOADING)   \n"
-        "		gl_FragColor = color.argb;\n"
-        "     else if (swap_rb == SWAP_NONE_DOWNLOADING)\n"
-        "		gl_FragColor = color.abgr;\n"
-        "     else if (swap_rb == SWAP_UPLOADING)\n"
+        "     if (swap_rb == SWAP_UPLOADING)\n"
         "		gl_FragColor = color.gbar;\n"
         "     else if (swap_rb == SWAP_NONE_UPLOADING)\n"
         "		gl_FragColor = color.abgr;\n"
@@ -199,18 +193,14 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
         "   vec4 color = texture2D(sampler, source_texture);\n"
         "   if (revert == REVERT_NONE) \n"
         "    { \n"
-        "     if ((swap_rb != SWAP_NONE_DOWNLOADING) && (swap_rb != SWAP_NONE_UPLOADING))   \n"
+        "     if (swap_rb != SWAP_NONE_UPLOADING)   \n"
         "		gl_FragColor = vec4(color.bgr, 1);\n"
         "     else \n"
         "		gl_FragColor = vec4(color.rgb, 1);\n"
         "    } \n"
         "   else \n"
         "    { \n"
-        "     if (swap_rb == SWAP_DOWNLOADING)   \n"
-        "		gl_FragColor = vec4(1, color.rgb);\n"
-        "     else if (swap_rb == SWAP_NONE_DOWNLOADING)\n"
-        "		gl_FragColor = vec4(1, color.bgr);\n"
-        "     else if (swap_rb == SWAP_UPLOADING)\n"
+        "     if (swap_rb == SWAP_UPLOADING)\n"
         "		gl_FragColor = vec4(color.gba, 1);\n"
         "     else if (swap_rb == SWAP_NONE_UPLOADING)\n"
         "		gl_FragColor = vec4(color.abg, 1);\n"
diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index a032ed0..34cf4a3 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -47,17 +47,17 @@ glamor_get_tex_format_type_from_pictformat_gl(ScreenPtr pScreen,
                                               GLenum *tex_type,
                                               int *no_alpha,
                                               int *revert,
-                                              int *swap_rb, int is_upload)
+                                              int *swap_rb)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
     *no_alpha = 0;
     *revert = REVERT_NONE;
-    *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
+    *swap_rb = SWAP_NONE_UPLOADING;
     switch (format) {
     case PICT_a1:
         *tex_format = glamor_priv->one_channel_format;
         *tex_type = GL_UNSIGNED_BYTE;
-        *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
+        *revert = REVERT_UPLOADING_A1;
         break;
     case PICT_b8g8r8x8:
         *no_alpha = 1;
@@ -145,7 +145,7 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
                                                  GLenum *tex_type,
                                                  int *no_alpha,
                                                  int *revert,
-                                                 int *swap_rb, int is_upload)
+                                                 int *swap_rb)
 {
     glamor_screen_private *glamor_priv = glamor_get_screen_private(pScreen);
     int need_swap_rb = 0;
@@ -186,20 +186,10 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
          * we have to use GL_UNSIGNED_BYTE and do the conversion in
          * shader latter.*/
         *tex_type = GL_UNSIGNED_BYTE;
-        if (is_upload == 1) {
-            if (!IS_LITTLE_ENDIAN)
-                *revert = REVERT_UPLOADING_10_10_10_2;
-            else
-                *revert = REVERT_UPLOADING_2_10_10_10;
-        }
-        else {
-            if (!IS_LITTLE_ENDIAN) {
-                *revert = REVERT_DOWNLOADING_10_10_10_2;
-            }
-            else {
-                *revert = REVERT_DOWNLOADING_2_10_10_10;
-            }
-        }
+        if (!IS_LITTLE_ENDIAN)
+            *revert = REVERT_UPLOADING_10_10_10_2;
+        else
+            *revert = REVERT_UPLOADING_2_10_10_10;
         need_swap_rb = 1;
 
         break;
@@ -209,20 +199,10 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
     case PICT_a2b10g10r10:
         *tex_format = GL_RGBA;
         *tex_type = GL_UNSIGNED_BYTE;
-        if (is_upload == 1) {
-            if (!IS_LITTLE_ENDIAN)
-                *revert = REVERT_UPLOADING_10_10_10_2;
-            else
-                *revert = REVERT_UPLOADING_2_10_10_10;
-        }
-        else {
-            if (!IS_LITTLE_ENDIAN) {
-                *revert = REVERT_DOWNLOADING_10_10_10_2;
-            }
-            else {
-                *revert = REVERT_DOWNLOADING_2_10_10_10;
-            }
-        }
+        if (!IS_LITTLE_ENDIAN)
+            *revert = REVERT_UPLOADING_10_10_10_2;
+        else
+            *revert = REVERT_UPLOADING_2_10_10_10;
         break;
 
     case PICT_r5g6b5:
@@ -243,11 +223,8 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
     case PICT_a1b5g5r5:
         *tex_format = GL_RGBA;
         *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-        if (IS_LITTLE_ENDIAN) {
-            *revert =
-                is_upload ? REVERT_UPLOADING_1_5_5_5 :
-                REVERT_DOWNLOADING_1_5_5_5;
-        }
+        if (IS_LITTLE_ENDIAN)
+            *revert = REVERT_UPLOADING_1_5_5_5;
         else
             *revert = REVERT_NONE;
         break;
@@ -257,11 +234,8 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
     case PICT_a1r5g5b5:
         *tex_format = GL_RGBA;
         *tex_type = GL_UNSIGNED_SHORT_5_5_5_1;
-        if (IS_LITTLE_ENDIAN) {
-            *revert =
-                is_upload ? REVERT_UPLOADING_1_5_5_5 :
-                REVERT_DOWNLOADING_1_5_5_5;
-        }
+        if (IS_LITTLE_ENDIAN)
+            *revert = REVERT_UPLOADING_1_5_5_5;
         else
             *revert = REVERT_NONE;
         need_swap_rb = 1;
@@ -270,7 +244,7 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
     case PICT_a1:
         *tex_format = glamor_priv->one_channel_format;
         *tex_type = GL_UNSIGNED_BYTE;
-        *revert = is_upload ? REVERT_UPLOADING_A1 : REVERT_DOWNLOADING_A1;
+        *revert = REVERT_UPLOADING_A1;
         break;
 
     case PICT_a8:
@@ -303,9 +277,9 @@ glamor_get_tex_format_type_from_pictformat_gles2(ScreenPtr pScreen,
     }
 
     if (need_swap_rb)
-        *swap_rb = is_upload ? SWAP_UPLOADING : SWAP_DOWNLOADING;
+        *swap_rb = SWAP_UPLOADING;
     else
-        *swap_rb = is_upload ? SWAP_NONE_UPLOADING : SWAP_NONE_DOWNLOADING;
+        *swap_rb = SWAP_NONE_UPLOADING;
     return 0;
 }
 
@@ -315,7 +289,7 @@ glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
                                        GLenum *format,
                                        GLenum *type,
                                        int *no_alpha,
-                                       int *revert, int *swap_rb, int is_upload)
+                                       int *revert, int *swap_rb)
 {
     glamor_screen_private *glamor_priv =
         glamor_get_screen_private(pixmap->drawable.pScreen);
@@ -326,38 +300,25 @@ glamor_get_tex_format_type_from_pixmap(PixmapPtr pixmap,
                                                              format, type,
                                                              no_alpha,
                                                              revert,
-                                                             swap_rb,
-                                                             is_upload);
+                                                             swap_rb);
     } else {
         return glamor_get_tex_format_type_from_pictformat_gles2(pixmap->drawable.pScreen,
                                                                 pict_format,
                                                                 format, type,
                                                                 no_alpha,
                                                                 revert,
-                                                                swap_rb,
-                                                                is_upload);
+                                                                swap_rb);
     }
 }
 
 static void *
 _glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
-                            int stride, int revert)
+                            int stride)
 {
-    PictFormatShort dst_format, src_format;
+    PictFormatShort dst_format = PICT_a8, src_format = PICT_a1;
     pixman_image_t *dst_image;
     pixman_image_t *src_image;
-    int src_stride;
-
-    if (revert == REVERT_UPLOADING_A1) {
-        src_format = PICT_a1;
-        dst_format = PICT_a8;
-        src_stride = PixmapBytePad(w, 1);
-    }
-    else {
-        dst_format = PICT_a1;
-        src_format = PICT_a8;
-        src_stride = (((w * 8 + 7) / 8) + 3) & ~3;
-    }
+    int src_stride = PixmapBytePad(w, 1);
 
     dst_image = pixman_image_create_bits(dst_format, w, h, dst_bits, stride);
     if (dst_image == NULL) {
@@ -421,13 +382,12 @@ _glamor_color_convert_a1_a8(void *src_bits, void *dst_bits, int w, int h,
 
 static void *
 _glamor_color_revert_x2b10g10r10(void *src_bits, void *dst_bits, int w, int h,
-                                 int stride, int no_alpha, int revert,
+                                 int stride, int no_alpha,
                                  int swap_rb)
 {
     int x, y;
     unsigned int *words, *saved_words, *source_words;
-    int swap = !(swap_rb == SWAP_NONE_DOWNLOADING ||
-                 swap_rb == SWAP_NONE_UPLOADING);
+    int swap = swap_rb != SWAP_NONE_UPLOADING;
 
     source_words = src_bits;
     words = dst_bits;
@@ -438,14 +398,9 @@ _glamor_color_revert_x2b10g10r10(void *src_bits, void *dst_bits, int w, int h,
         for (x = 0; x < w; x++) {
             unsigned int pixel = source_words[x];
 
-            if (revert == REVERT_DOWNLOADING_2_10_10_10)
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  24, 8, 16, 8, 8, 8, 0, 8,
-                                  30, 2, 20, 10, 10, 10, 0, 10);
-            else
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  30, 2, 20, 10, 10, 10, 0, 10,
-                                  24, 8, 16, 8, 8, 8, 0, 8);
+            GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
+                              30, 2, 20, 10, 10, 10, 0, 10,
+                              24, 8, 16, 8, 8, 8, 0, 8);
             DEBUGF("%x:%x ", pixel, words[x]);
         }
         DEBUGF("\n");
@@ -459,12 +414,11 @@ _glamor_color_revert_x2b10g10r10(void *src_bits, void *dst_bits, int w, int h,
 
 static void *
 _glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
-                              int stride, int no_alpha, int revert, int swap_rb)
+                              int stride, int no_alpha, int swap_rb)
 {
     int x, y;
     unsigned short *words, *saved_words, *source_words;
-    int swap = !(swap_rb == SWAP_NONE_DOWNLOADING ||
-                 swap_rb == SWAP_NONE_UPLOADING);
+    int swap = swap_rb != SWAP_NONE_UPLOADING;
 
     words = dst_bits;
     source_words = src_bits;
@@ -475,14 +429,9 @@ _glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
         for (x = 0; x < w; x++) {
             unsigned short pixel = source_words[x];
 
-            if (revert == REVERT_DOWNLOADING_1_5_5_5)
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  0, 1, 1, 5, 6, 5, 11, 5,
-                                  15, 1, 10, 5, 5, 5, 0, 5);
-            else
-                GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
-                                  15, 1, 10, 5, 5, 5, 0, 5,
-                                  0, 1, 1, 5, 6, 5, 11, 5);
+            GLAMOR_DO_CONVERT(pixel, &words[x], no_alpha, swap,
+                              15, 1, 10, 5, 5, 5, 0, 5,
+                              0, 1, 1, 5, 6, 5, 11, 5);
             DEBUGF("%04x:%04x ", pixel, words[x]);
         }
         DEBUGF("\n");
@@ -501,11 +450,8 @@ _glamor_color_revert_x1b5g5r5(void *src_bits, void *dst_bits, int w, int h,
  * @no_alpha:
  * 	If it is set, then we need to wire the alpha value to 1.
  * @revert:
-	REVERT_DOWNLOADING_A1		: convert an Alpha8 buffer to a A1 buffer.
 	REVERT_UPLOADING_A1		: convert an A1 buffer to an Alpha8 buffer
-	REVERT_DOWNLOADING_2_10_10_10 	: convert r10G10b10X2 to X2B10G10R10
 	REVERT_UPLOADING_2_10_10_10 	: convert X2B10G10R10 to R10G10B10X2
-	REVERT_DOWNLOADING_1_5_5_5  	: convert B5G5R5X1 to X1R5G5B5
 	REVERT_UPLOADING_1_5_5_5    	: convert X1R5G5B5 to B5G5R5X1
    @swap_rb: if we have the swap_rb set, then we need to swap the R and B's position.
  *
@@ -515,20 +461,16 @@ static void *
 glamor_color_convert_to_bits(void *src_bits, void *dst_bits, int w, int h,
                              int stride, int no_alpha, int revert, int swap_rb)
 {
-    if (revert == REVERT_DOWNLOADING_A1 || revert == REVERT_UPLOADING_A1) {
-        return _glamor_color_convert_a1_a8(src_bits, dst_bits, w, h, stride,
-                                           revert);
+    if (revert == REVERT_UPLOADING_A1) {
+        return _glamor_color_convert_a1_a8(src_bits, dst_bits, w, h, stride);
     }
-    else if (revert == REVERT_DOWNLOADING_2_10_10_10 ||
-             revert == REVERT_UPLOADING_2_10_10_10) {
+    else if (revert == REVERT_UPLOADING_2_10_10_10) {
         return _glamor_color_revert_x2b10g10r10(src_bits, dst_bits, w, h,
-                                                stride, no_alpha, revert,
-                                                swap_rb);
+                                                stride, no_alpha, swap_rb);
     }
-    else if (revert == REVERT_DOWNLOADING_1_5_5_5 ||
-             revert == REVERT_UPLOADING_1_5_5_5) {
+    else if (revert == REVERT_UPLOADING_1_5_5_5) {
         return _glamor_color_revert_x1b5g5r5(src_bits, dst_bits, w, h, stride,
-                                             no_alpha, revert, swap_rb);
+                                             no_alpha, swap_rb);
     }
     else
         ErrorF("convert a non-supported mode %x.\n", revert);
@@ -801,7 +743,7 @@ glamor_upload_picture_to_texture(PicturePtr picture)
                                                &format,
                                                &type,
                                                &no_alpha,
-                                               &revert, &swap_rb, 1)) {
+                                               &revert, &swap_rb)) {
         glamor_fallback("Unknown pixmap depth %d.\n", pixmap->drawable.depth);
         return FALSE;
     }
diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h
index 5128a33..e23de86 100644
--- a/glamor/glamor_utils.h
+++ b/glamor/glamor_utils.h
@@ -767,17 +767,11 @@ format_for_pixmap(PixmapPtr pixmap)
 
 #define REVERT_NONE       		0
 #define REVERT_NORMAL     		1
-#define REVERT_DOWNLOADING_A1		2
 #define REVERT_UPLOADING_A1		3
-#define REVERT_DOWNLOADING_2_10_10_10 	4
 #define REVERT_UPLOADING_2_10_10_10 	5
-#define REVERT_DOWNLOADING_1_5_5_5  	7
 #define REVERT_UPLOADING_1_5_5_5    	8
-#define REVERT_DOWNLOADING_10_10_10_2 	9
 #define REVERT_UPLOADING_10_10_10_2 	10
 
-#define SWAP_NONE_DOWNLOADING  	0
-#define SWAP_DOWNLOADING  	1
 #define SWAP_UPLOADING	  	2
 #define SWAP_NONE_UPLOADING	3
 
commit 1bed5ef2b80c77c1bb9b62971367bea864fd8f66
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:06 2016 -0800

    glamor: Drop dead fbo handling from GLAMOR_MEMORY pict uploads.
    
    The previous commit asserts that we don't have one.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index 9bb2c74..a032ed0 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -734,27 +734,10 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
                              int revert, int swap_rb)
 {
     int flag = 0;
-    glamor_pixmap_private *pixmap_priv;
-    glamor_screen_private *glamor_priv;
-    glamor_pixmap_fbo *fbo;
+    glamor_screen_private *glamor_priv =
+        glamor_get_screen_private(pixmap->drawable.pScreen);
     GLenum iformat;
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-    glamor_priv = glamor_get_screen_private(pixmap->drawable.pScreen);
-
-    if (pixmap_priv->gl_fbo != GLAMOR_FBO_UNATTACHED)
-        return 0;
-
-    if (pixmap_priv->fbo
-        && (pixmap_priv->fbo->width < pixmap->drawable.width
-            || pixmap_priv->fbo->height < pixmap->drawable.height)) {
-        fbo = glamor_pixmap_detach_fbo(pixmap_priv);
-        glamor_destroy_fbo(glamor_priv, fbo);
-    }
-
-    if (pixmap_priv->fbo && pixmap_priv->fbo->fb)
-        return 0;
-
     if (!(no_alpha || (revert == REVERT_NORMAL)
           || (swap_rb != SWAP_NONE_UPLOADING))) {
         /* We don't need a fbo, a simple texture uploading should work. */
@@ -762,10 +745,6 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, GLenum format, int no_alpha,
         flag = GLAMOR_CREATE_FBO_NO_FBO;
     }
 
-    if ((flag == GLAMOR_CREATE_FBO_NO_FBO
-         && pixmap_priv->fbo && pixmap_priv->fbo->tex))
-        return 0;
-
     if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
         iformat = gl_iformat_for_pixmap(pixmap);
     else
commit ee7ca670b1695d64bc12cb37302913acc066a569
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:05 2016 -0800

    glamor: Make sure that GLAMOR_MEMORY pixmaps don't retain an FBO.
    
    glamor_composite_choose_shader() may upload our scratch pixmaps to get
    a Render operation completed.  We don't want to hang onto GL memory
    for our scratch pixmaps, since we'll just have to reallocate them at a
    new w/h next time around, and the contents will be updated as well.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 5bfffe5..0bfc1dd 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -510,6 +510,7 @@ glamor_pixmap_destroy_fbo(PixmapPtr pixmap)
         for (i = 0; i < priv->block_wcnt * priv->block_hcnt; i++)
             glamor_destroy_fbo(glamor_priv, priv->fbo_array[i]);
         free(priv->fbo_array);
+        priv->fbo_array = NULL;
     }
     else {
         fbo = glamor_pixmap_detach_fbo(priv);
diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index e91461c..9bb2c74 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -797,9 +797,10 @@ glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
     }
 }
 
-/* Upload picture to texture.  We may need to flip the y axis or
- * wire alpha to 1. So we may conditional create fbo for the picture.
- * */
+/**
+ * Uploads a picture based on a GLAMOR_MEMORY pixmap to a texture in a
+ * temporary FBO.
+ */
 Bool
 glamor_upload_picture_to_texture(PicturePtr picture)
 {
@@ -810,9 +811,12 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
     GLenum format, type;
     int no_alpha, revert, swap_rb;
-    glamor_pixmap_private *pixmap_priv;
+    glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
     Bool force_clip;
 
+    assert(glamor_pixmap_is_memory(pixmap));
+    assert(!pixmap_priv->fbo);
+
     if (glamor_get_tex_format_type_from_pixmap(pixmap,
                                                picture->format,
                                                &format,
@@ -825,7 +829,6 @@ glamor_upload_picture_to_texture(PicturePtr picture)
     if (glamor_pixmap_upload_prepare(pixmap, format, no_alpha, revert, swap_rb))
         return FALSE;
 
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
     force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP;
 
     if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) {
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index d47e7d7..65f7059 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -1125,7 +1125,7 @@ glamor_composite_with_shader(CARD8 op,
                                         &key, &shader, &op_info,
                                         &saved_source_format, ca_state)) {
         glamor_fallback("glamor_composite_choose_shader failed\n");
-        return ret;
+        goto fail;
     }
     if (ca_state == CA_TWO_PASS) {
         if (!glamor_composite_choose_shader(PictOpAdd, source, mask, dest,
@@ -1135,7 +1135,7 @@ glamor_composite_with_shader(CARD8 op,
                                             &key_ca, &shader_ca, &op_info_ca,
                                             &saved_source_format, ca_state)) {
             glamor_fallback("glamor_composite_choose_shader failed\n");
-            return ret;
+            goto fail;
         }
     }
 
@@ -1267,6 +1267,13 @@ glamor_composite_with_shader(CARD8 op,
         source->format = saved_source_format;
 
     ret = TRUE;
+
+fail:
+    if (mask_pixmap && glamor_pixmap_is_memory(mask_pixmap))
+        glamor_pixmap_destroy_fbo(mask_pixmap);
+    if (source_pixmap && glamor_pixmap_is_memory(source_pixmap))
+        glamor_pixmap_destroy_fbo(source_pixmap);
+
     return ret;
 }
 
commit a96c6d4658e3f386002f96eede660af3b01e5209
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Feb 1 13:58:04 2016 -0800

    glamor: Simplify temporary picture uploading call stack.
    
    glamor_upload_sub_pixmap_to_texture() only had the one caller, so we
    can merge it in, fix its silly return value, and propagate a bunch of
    constants.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_picture.c b/glamor/glamor_picture.c
index b069ce5..e91461c 100644
--- a/glamor/glamor_picture.c
+++ b/glamor/glamor_picture.c
@@ -797,11 +797,15 @@ glamor_put_bits(char *dst_bits, int dst_stride, char *src_bits,
     }
 }
 
-static Bool
-glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
-                                    int h, int stride, void *bits, int pbo,
-                                    PictFormatShort pict_format)
+/* Upload picture to texture.  We may need to flip the y axis or
+ * wire alpha to 1. So we may conditional create fbo for the picture.
+ * */
+Bool
+glamor_upload_picture_to_texture(PicturePtr picture)
 {
+    PixmapPtr pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
+    void *bits = pixmap->devPrivate.ptr;
+    int stride = pixmap->devKind;
     ScreenPtr screen = pixmap->drawable.pScreen;
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
     GLenum format, type;
@@ -810,7 +814,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
     Bool force_clip;
 
     if (glamor_get_tex_format_type_from_pixmap(pixmap,
-                                               pict_format,
+                                               picture->format,
                                                &format,
                                                &type,
                                                &no_alpha,
@@ -822,8 +826,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
         return FALSE;
 
     pixmap_priv = glamor_get_pixmap_private(pixmap);
-    force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP
-        && !glamor_check_fbo_size(glamor_priv, w, h);
+    force_clip = glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP;
 
     if (glamor_pixmap_priv_is_large(pixmap_priv) || force_clip) {
         RegionRec region;
@@ -833,13 +836,13 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
         void *sub_bits;
         int i, j;
 
-        sub_bits = xallocarray(h, stride);
+        sub_bits = xallocarray(pixmap->drawable.height, stride);
         if (sub_bits == NULL)
             return FALSE;
-        box.x1 = x;
-        box.y1 = y;
-        box.x2 = x + w;
-        box.y2 = y + h;
+        box.x1 = 0;
+        box.y1 = 0;
+        box.x2 = pixmap->drawable.width;
+        box.y2 = pixmap->drawable.height;
         RegionInitBoxes(&region, &box, 1);
         if (!force_clip)
             clipped_regions =
@@ -860,8 +863,6 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
             int temp_stride;
             void *temp_bits;
 
-            assert(pbo == 0);
-
             glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx);
 
             boxes = RegionRects(clipped_regions[i].region);
@@ -871,26 +872,26 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
                 temp_stride = PixmapBytePad(boxes[j].x2 - boxes[j].x1,
                                             pixmap->drawable.depth);
 
-                if (boxes[j].x1 == x && temp_stride == stride) {
-                    temp_bits = (char *) bits + (boxes[j].y1 - y) * stride;
+                if (boxes[j].x1 == 0 && temp_stride == stride) {
+                    temp_bits = (char *) bits + boxes[j].y1 * stride;
                 }
                 else {
                     temp_bits = sub_bits;
                     glamor_put_bits(temp_bits, temp_stride, bits, stride,
                                     pixmap->drawable.bitsPerPixel,
-                                    boxes[j].x1 - x, boxes[j].y1 - y,
+                                    boxes[j].x1, boxes[j].y1,
                                     boxes[j].x2 - boxes[j].x1,
                                     boxes[j].y2 - boxes[j].y1);
                 }
                 DEBUGF("upload x %d y %d w %d h %d temp stride %d \n",
-                       boxes[j].x1 - x, boxes[j].y1 - y,
+                       boxes[j].x1, boxes[j].y1,
                        boxes[j].x2 - boxes[j].x1,
                        boxes[j].y2 - boxes[j].y1, temp_stride);
                 if (_glamor_upload_bits_to_pixmap_texture
                     (pixmap, format, type, no_alpha, revert, swap_rb,
                      boxes[j].x1, boxes[j].y1, boxes[j].x2 - boxes[j].x1,
                      boxes[j].y2 - boxes[j].y1, temp_stride, temp_bits,
-                     pbo) == FALSE) {
+                     0) == FALSE) {
                     RegionUninit(&region);
                     free(sub_bits);
                     assert(0);
@@ -907,28 +908,9 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
     else
         return _glamor_upload_bits_to_pixmap_texture(pixmap, format, type,
                                                      no_alpha, revert, swap_rb,
-                                                     x, y, w, h, stride, bits,
-                                                     pbo);
-}
-
-/* Upload picture to texture.  We may need to flip the y axis or
- * wire alpha to 1. So we may conditional create fbo for the picture.
- * */
-enum glamor_pixmap_status
-glamor_upload_picture_to_texture(PicturePtr picture)
-{
-    PixmapPtr pixmap;
-
-    assert(picture->pDrawable);
-    pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-
-    if (glamor_upload_sub_pixmap_to_texture(pixmap, 0, 0,
-                                            pixmap->drawable.width,
-                                            pixmap->drawable.height,
-                                            pixmap->devKind,
-                                            pixmap->devPrivate.ptr, 0,
-                                            picture->format))
-        return GLAMOR_UPLOAD_DONE;
-    else
-        return GLAMOR_UPLOAD_FAILED;
+                                                     0, 0,
+                                                     pixmap->drawable.width,
+                                                     pixmap->drawable.height,
+                                                     stride, bits,
+                                                     0);
 }
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index a70f10e..422b0fd 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -514,22 +514,6 @@ glamor_pixmap_hcnt(glamor_pixmap_private *priv)
     for (box_index = 0; box_index < glamor_pixmap_hcnt(priv) *         \
              glamor_pixmap_wcnt(priv); box_index++)                    \
 
-/**
- * Pixmap upload status, used by glamor_render.c's support for
- * temporarily uploading pixmaps to GL textures to get a Composite
- * operation done.
- */
-typedef enum glamor_pixmap_status {
-    /** initial status, don't need to do anything. */
-    GLAMOR_NONE,
-    /** marked as need to be uploaded to gl texture. */
-    GLAMOR_UPLOAD_PENDING,
-    /** the pixmap has been uploaded successfully. */
-    GLAMOR_UPLOAD_DONE,
-    /** fail to upload the pixmap. */
-    GLAMOR_UPLOAD_FAILED
-} glamor_pixmap_status_t;
-
 /* GC private structure. Currently holds only any computed dash pixmap */
 
 typedef struct {
@@ -739,7 +723,7 @@ Bool glamor_composite_largepixmap_region(CARD8 op,
  * Upload a picture to gl texture. Similar to the
  * glamor_upload_pixmap_to_texture. Used in rendering.
  **/
-enum glamor_pixmap_status glamor_upload_picture_to_texture(PicturePtr picture);
+Bool glamor_upload_picture_to_texture(PicturePtr picture);
 
 void glamor_add_traps(PicturePtr pPicture,
                       INT16 x_off, INT16 y_off, int ntrap, xTrap *traps);
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index 73ac831..d47e7d7 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -788,8 +788,8 @@ glamor_composite_choose_shader(CARD8 op,
 {
     ScreenPtr screen = dest->pDrawable->pScreen;
     glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    enum glamor_pixmap_status source_status = GLAMOR_NONE;
-    enum glamor_pixmap_status mask_status = GLAMOR_NONE;
+    Bool source_needs_upload = FALSE;
+    Bool mask_needs_upload = FALSE;
     PictFormatShort saved_source_format = 0;
     struct shader_key key;
     GLfloat source_solid_color[4];
@@ -900,7 +900,7 @@ glamor_composite_choose_shader(CARD8 op,
         }
         if (source_pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED) {
 #ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
-            source_status = GLAMOR_UPLOAD_PENDING;
+            source_needs_upload = TRUE;
 #else
             glamor_fallback("no texture in source\n");
             goto fail;
@@ -916,7 +916,7 @@ glamor_composite_choose_shader(CARD8 op,
         }
         if (mask_pixmap_priv->gl_fbo == GLAMOR_FBO_UNATTACHED) {
 #ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
-            mask_status = GLAMOR_UPLOAD_PENDING;
+            mask_needs_upload = TRUE;
 #else
             glamor_fallback("no texture in mask\n");
             goto fail;
@@ -925,8 +925,7 @@ glamor_composite_choose_shader(CARD8 op,
     }
 
 #ifdef GLAMOR_PIXMAP_DYNAMIC_UPLOAD
-    if (source_status == GLAMOR_UPLOAD_PENDING
-        && mask_status == GLAMOR_UPLOAD_PENDING
+    if (source_needs_upload && mask_needs_upload
         && source_pixmap == mask_pixmap) {
 
         if (source->format != mask->format) {
@@ -962,20 +961,17 @@ glamor_composite_choose_shader(CARD8 op,
             if (!PICT_FORMAT_A(mask->format)
                 && PICT_FORMAT_A(saved_source_format))
                 key.mask = SHADER_MASK_TEXTURE;
-
-            mask_status = GLAMOR_NONE;
         }
 
-        source_status = glamor_upload_picture_to_texture(source);
-        if (source_status != GLAMOR_UPLOAD_DONE) {
+        if (!glamor_upload_picture_to_texture(source)) {
             glamor_fallback("Failed to upload source texture.\n");
             goto fail;
         }
+        mask_needs_upload = FALSE;
     }
     else {
-        if (source_status == GLAMOR_UPLOAD_PENDING) {
-            source_status = glamor_upload_picture_to_texture(source);
-            if (source_status != GLAMOR_UPLOAD_DONE) {
+        if (source_needs_upload) {
+            if (!glamor_upload_picture_to_texture(source)) {
                 glamor_fallback("Failed to upload source texture.\n");
                 goto fail;
             }
@@ -986,9 +982,8 @@ glamor_composite_choose_shader(CARD8 op,
             }
         }
 
-        if (mask_status == GLAMOR_UPLOAD_PENDING) {
-            mask_status = glamor_upload_picture_to_texture(mask);
-            if (mask_status != GLAMOR_UPLOAD_DONE) {
+        if (mask_needs_upload) {
+            if (!glamor_upload_picture_to_texture(mask)) {
                 glamor_fallback("Failed to upload mask texture.\n");
                 goto fail;
             }


More information about the xorg-commit mailing list