[Mesa-dev] [PATCH 06/11] meta: Do a massive unindent (and rename) of blitframebuffer_texture().

Eric Anholt eric at anholt.net
Wed Feb 5 17:20:09 PST 2014


This function is only handling the color case.  We can just unindent as
long as we're willing to do the check for the bit outside of the
function.
---
 src/mesa/drivers/common/meta_blit.c | 331 ++++++++++++++++++------------------
 1 file changed, 168 insertions(+), 163 deletions(-)

diff --git a/src/mesa/drivers/common/meta_blit.c b/src/mesa/drivers/common/meta_blit.c
index 5a0b2ca..3c6998f 100644
--- a/src/mesa/drivers/common/meta_blit.c
+++ b/src/mesa/drivers/common/meta_blit.c
@@ -267,181 +267,181 @@ setup_glsl_blit_framebuffer(struct gl_context *ctx,
  * Try to do a glBlitFramebuffer using no-copy texturing.
  * We can do this when the src renderbuffer is actually a texture.
  * But if the src buffer == dst buffer we cannot do this.
- *
- * \return new buffer mask indicating the buffers left to blit using the
- *         normal path.
  */
-static GLbitfield
+static bool
 blitframebuffer_texture(struct gl_context *ctx,
                         GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
                         GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
-                        GLbitfield mask, GLenum filter, GLint flipX,
-                        GLint flipY, GLboolean glsl_version)
+                        GLenum filter, GLint flipX, GLint flipY,
+                        GLboolean glsl_version)
 {
-   if (mask & GL_COLOR_BUFFER_BIT) {
-      const struct gl_framebuffer *drawFb = ctx->DrawBuffer;
-      const struct gl_framebuffer *readFb = ctx->ReadBuffer;
-      const struct gl_renderbuffer_attachment *drawAtt;
-      const struct gl_renderbuffer_attachment *readAtt =
-         &readFb->Attachment[readFb->_ColorReadBufferIndex];
-
-      if (readAtt && readAtt->Texture) {
-         struct blit_state *blit = &ctx->Meta->Blit;
-         const GLint dstX = MIN2(dstX0, dstX1);
-         const GLint dstY = MIN2(dstY0, dstY1);
-         const GLint dstW = abs(dstX1 - dstX0);
-         const GLint dstH = abs(dstY1 - dstY0);
-         const struct gl_texture_object *texObj = readAtt->Texture;
-         const GLuint srcLevel = readAtt->TextureLevel;
-         const GLint baseLevelSave = texObj->BaseLevel;
-         const GLint maxLevelSave = texObj->MaxLevel;
-         const GLenum target = texObj->Target;
-         GLuint sampler, samplerSave =
-            ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler ?
-            ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler->Name : 0;
-         int i;
-
-         /* Iterate through all draw buffers */
-         for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
-            int idx = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
-            if (idx == -1)
-               continue;
-            drawAtt = &drawFb->Attachment[idx];
-
-            if (drawAtt->Texture == readAtt->Texture) {
-               /* Can't use same texture as both the source and dest.  We need
-                * to handle overlapping blits and besides, some hw may not
-                * support this.
-                */
-               return mask;
-            }
-         }
-
-         if (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_ARB) {
-            /* Can't handle other texture types at this time */
-            return mask;
-         }
+   const struct gl_framebuffer *drawFb = ctx->DrawBuffer;
+   const struct gl_framebuffer *readFb = ctx->ReadBuffer;
+   const struct gl_renderbuffer_attachment *drawAtt;
+   const struct gl_renderbuffer_attachment *readAtt =
+      &readFb->Attachment[readFb->_ColorReadBufferIndex];
+   struct blit_state *blit = &ctx->Meta->Blit;
+   const GLint dstX = MIN2(dstX0, dstX1);
+   const GLint dstY = MIN2(dstY0, dstY1);
+   const GLint dstW = abs(dstX1 - dstX0);
+   const GLint dstH = abs(dstY1 - dstY0);
+   const struct gl_texture_object *texObj;
+   GLuint srcLevel;
+   GLint baseLevelSave;
+   GLint maxLevelSave;
+   GLenum target;
+   GLuint sampler, samplerSave =
+      ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler ?
+      ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler->Name : 0;
+   int i;
+
+   if (readAtt && readAtt->Texture) {
+      srcLevel = readAtt->TextureLevel;
+      texObj = readAtt->Texture;
+   } else {
+      return false;
+   }
 
-         /* Choose between glsl version and fixed function version of
-          * BlitFramebuffer function.
+   baseLevelSave = texObj->BaseLevel;
+   maxLevelSave = texObj->MaxLevel;
+   target = texObj->Target;
+
+   /* Iterate through all draw buffers */
+   for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
+      int idx = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
+      if (idx == -1)
+         continue;
+      drawAtt = &drawFb->Attachment[idx];
+
+      if (drawAtt->Texture == readAtt->Texture) {
+         /* Can't use same texture as both the source and dest.  We need
+          * to handle overlapping blits and besides, some hw may not
+          * support this.
           */
-         if (glsl_version) {
-            setup_glsl_blit_framebuffer(ctx, blit, target);
-            if (target == GL_TEXTURE_2D)
-               _mesa_UseProgram(blit->ShaderProg);
-            else
-               _mesa_UseProgram(blit->RectShaderProg);
-         }
-         else {
-            setup_ff_blit_framebuffer(&ctx->Meta->Blit);
-         }
+         return false;
+      }
+   }
 
-         _mesa_BindVertexArray(blit->VAO);
-         _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB, blit->VBO);
-
-         _mesa_GenSamplers(1, &sampler);
-         _mesa_BindSampler(ctx->Texture.CurrentUnit, sampler);
-
-         /*
-         printf("Blit from texture!\n");
-         printf("  srcAtt %p  dstAtt %p\n", readAtt, drawAtt);
-         printf("  srcTex %p  dstText %p\n", texObj, drawAtt->Texture);
-         */
-
-         /* Prepare src texture state */
-         _mesa_BindTexture(target, texObj->Name);
-         _mesa_SamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, filter);
-         _mesa_SamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, filter);
-         if (target != GL_TEXTURE_RECTANGLE_ARB) {
-            _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, srcLevel);
-            _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
-         }
-         _mesa_SamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-         _mesa_SamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+   if (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE_ARB) {
+      /* Can't handle other texture types at this time */
+      return false;
+   }
 
-	 /* Always do our blits with no sRGB decode or encode.  Note that
-          * GL_FRAMEBUFFER_SRGB has already been disabled by
-          * _mesa_meta_begin().
-          */
-	 if (ctx->Extensions.EXT_texture_sRGB_decode) {
-	    _mesa_SamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT,
-				GL_SKIP_DECODE_EXT);
-	 }
+   /* Choose between glsl version and fixed function version of
+    * BlitFramebuffer function.
+    */
+   if (glsl_version) {
+      setup_glsl_blit_framebuffer(ctx, blit, target);
+      if (target == GL_TEXTURE_2D)
+         _mesa_UseProgram(blit->ShaderProg);
+      else
+         _mesa_UseProgram(blit->RectShaderProg);
+   }
+   else {
+      setup_ff_blit_framebuffer(&ctx->Meta->Blit);
+   }
 
-         if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
-            _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
-            _mesa_set_enable(ctx, target, GL_TRUE);
-	 }
+   _mesa_BindVertexArray(blit->VAO);
+   _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB, blit->VBO);
 
-         /* Prepare vertex data (the VBO was previously created and bound) */
-         {
-            struct vertex {
-               GLfloat x, y, s, t;
-            };
-            struct vertex verts[4];
-            GLfloat s0, t0, s1, t1;
-
-            if (target == GL_TEXTURE_2D) {
-               const struct gl_texture_image *texImage
-                   = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
-               s0 = srcX0 / (float) texImage->Width;
-               s1 = srcX1 / (float) texImage->Width;
-               t0 = srcY0 / (float) texImage->Height;
-               t1 = srcY1 / (float) texImage->Height;
-            }
-            else {
-               assert(target == GL_TEXTURE_RECTANGLE_ARB);
-               s0 = (float) srcX0;
-               s1 = (float) srcX1;
-               t0 = (float) srcY0;
-               t1 = (float) srcY1;
-            }
-
-            /* setup vertex positions */
-            verts[0].x = -1.0F * flipX;
-            verts[0].y = -1.0F * flipY;
-            verts[1].x =  1.0F * flipX;
-            verts[1].y = -1.0F * flipY;
-            verts[2].x =  1.0F * flipX;
-            verts[2].y =  1.0F * flipY;
-            verts[3].x = -1.0F * flipX;
-            verts[3].y =  1.0F * flipY;
-
-            verts[0].s = s0;
-            verts[0].t = t0;
-            verts[1].s = s1;
-            verts[1].t = t0;
-            verts[2].s = s1;
-            verts[2].t = t1;
-            verts[3].s = s0;
-            verts[3].t = t1;
+   _mesa_GenSamplers(1, &sampler);
+   _mesa_BindSampler(ctx->Texture.CurrentUnit, sampler);
+
+   /*
+     printf("Blit from texture!\n");
+     printf("  srcAtt %p  dstAtt %p\n", readAtt, drawAtt);
+     printf("  srcTex %p  dstText %p\n", texObj, drawAtt->Texture);
+   */
+
+   /* Prepare src texture state */
+   _mesa_BindTexture(target, texObj->Name);
+   _mesa_SamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, filter);
+   _mesa_SamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, filter);
+   if (target != GL_TEXTURE_RECTANGLE_ARB) {
+      _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, srcLevel);
+      _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, srcLevel);
+   }
+   _mesa_SamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+   _mesa_SamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
-            _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
-         }
+   /* Always do our blits with no sRGB decode or encode.  Note that
+    * GL_FRAMEBUFFER_SRGB has already been disabled by
+    * _mesa_meta_begin().
+    */
+   if (ctx->Extensions.EXT_texture_sRGB_decode) {
+      _mesa_SamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT,
+                              GL_SKIP_DECODE_EXT);
+   }
 
-         /* setup viewport */
-         _mesa_set_viewport(ctx, 0, dstX, dstY, dstW, dstH);
-         _mesa_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-         _mesa_DepthMask(GL_FALSE);
-         _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+   if (ctx->API == API_OPENGL_COMPAT || ctx->API == API_OPENGLES) {
+      _mesa_TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+      _mesa_set_enable(ctx, target, GL_TRUE);
+   }
 
-         /* Restore texture object state, the texture binding will
-          * be restored by _mesa_meta_end().
-          */
-         if (target != GL_TEXTURE_RECTANGLE_ARB) {
-            _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave);
-            _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
-         }
+   /* Prepare vertex data (the VBO was previously created and bound) */
+   {
+      struct vertex {
+         GLfloat x, y, s, t;
+      };
+      struct vertex verts[4];
+      GLfloat s0, t0, s1, t1;
+
+      if (target == GL_TEXTURE_2D) {
+         const struct gl_texture_image *texImage
+            = _mesa_select_tex_image(ctx, texObj, target, srcLevel);
+         s0 = srcX0 / (float) texImage->Width;
+         s1 = srcX1 / (float) texImage->Width;
+         t0 = srcY0 / (float) texImage->Height;
+         t1 = srcY1 / (float) texImage->Height;
+      }
+      else {
+         assert(target == GL_TEXTURE_RECTANGLE_ARB);
+         s0 = (float) srcX0;
+         s1 = (float) srcX1;
+         t0 = (float) srcY0;
+         t1 = (float) srcY1;
+      }
 
-         _mesa_BindSampler(ctx->Texture.CurrentUnit, samplerSave);
-         _mesa_DeleteSamplers(1, &sampler);
+      /* setup vertex positions */
+      verts[0].x = -1.0F * flipX;
+      verts[0].y = -1.0F * flipY;
+      verts[1].x =  1.0F * flipX;
+      verts[1].y = -1.0F * flipY;
+      verts[2].x =  1.0F * flipX;
+      verts[2].y =  1.0F * flipY;
+      verts[3].x = -1.0F * flipX;
+      verts[3].y =  1.0F * flipY;
 
-         /* Done with color buffer */
-         mask &= ~GL_COLOR_BUFFER_BIT;
-      }
+      verts[0].s = s0;
+      verts[0].t = t0;
+      verts[1].s = s1;
+      verts[1].t = t0;
+      verts[2].s = s1;
+      verts[2].t = t1;
+      verts[3].s = s0;
+      verts[3].t = t1;
+
+      _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB, 0, sizeof(verts), verts);
+   }
+
+   /* setup viewport */
+   _mesa_set_viewport(ctx, 0, dstX, dstY, dstW, dstH);
+   _mesa_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+   _mesa_DepthMask(GL_FALSE);
+   _mesa_DrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+   /* Restore texture object state, the texture binding will
+    * be restored by _mesa_meta_end().
+    */
+   if (target != GL_TEXTURE_RECTANGLE_ARB) {
+      _mesa_TexParameteri(target, GL_TEXTURE_BASE_LEVEL, baseLevelSave);
+      _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
    }
 
-   return mask;
+   _mesa_BindSampler(ctx->Texture.CurrentUnit, samplerSave);
+   _mesa_DeleteSamplers(1, &sampler);
+
+   return true;
 }
 
 
@@ -499,12 +499,17 @@ _mesa_meta_BlitFramebuffer(struct gl_context *ctx,
    _mesa_meta_begin(ctx, ~MESA_META_SCISSOR);
 
    /* Try faster, direct texture approach first */
-   mask = blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1,
-                                  dstX0, dstY0, dstX1, dstY1, mask, filter,
-                                  dstFlipX, dstFlipY, use_glsl_version);
-   if (mask == 0x0) {
-      _mesa_meta_end(ctx);
-      return;
+   if (mask & GL_COLOR_BUFFER_BIT) {
+      if (blitframebuffer_texture(ctx, srcX0, srcY0, srcX1, srcY1,
+                                  dstX0, dstY0, dstX1, dstY1,
+                                  filter, dstFlipX, dstFlipY,
+                                  use_glsl_version)) {
+         mask &= ~GL_COLOR_BUFFER_BIT;
+         if (mask == 0x0) {
+            _mesa_meta_end(ctx);
+            return;
+         }
+      }
    }
 
    /* Choose between glsl version and fixed function version of
-- 
1.9.rc1



More information about the mesa-dev mailing list