gallium: Fix memory leak.
[mesa.git] / src / mesa / swrast / s_drawpix.c
index 46dd79702396e9b758a13ac00d92e20c634ad991..0cf425e1c62a588e270b4cdede692661678512ef 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.2
+ * Version:  7.1
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -70,13 +70,10 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
       return GL_FALSE;
    }
 
-   INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_RGBA);
-   if (ctx->Depth.Test)
-      _swrast_span_default_z(ctx, &span);
-   if (swrast->_FogEnabled)
-      _swrast_span_default_fog(ctx, &span);
-   if (ctx->Texture._EnabledCoordUnits)
-      _swrast_span_default_texcoords(ctx, &span);
+   INIT_SPAN(span, GL_BITMAP);
+   span.arrayMask = SPAN_RGBA;
+   span.arrayAttribs = FRAG_BIT_COL0;
+   _swrast_span_default_attribs(ctx, &span);
 
    /* copy input params since clipping may change them */
    unpack = *userUnpack;
@@ -110,8 +107,9 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
     */
 
    if (format == GL_RGBA && type == rbType) {
-      const GLubyte *src = _mesa_image_address2d(&unpack, pixels, width,
-                                                 height, format, type, 0, 0);
+      const GLubyte *src
+         = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
+                                                   height, format, type, 0, 0);
       const GLint srcStride = _mesa_image_row_stride(&unpack, width,
                                                      format, type);
       if (simpleZoom) {
@@ -139,8 +137,9 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
    }
 
    if (format == GL_RGB && type == rbType) {
-      const GLubyte *src = _mesa_image_address2d(&unpack, pixels, width,
-                                                 height, format, type, 0, 0);
+      const GLubyte *src
+         = (const GLubyte *) _mesa_image_address2d(&unpack, pixels, width,
+                                                   height, format, type, 0, 0);
       const GLint srcStride = _mesa_image_row_stride(&unpack, width,
                                                      format, type);
       if (simpleZoom) {
@@ -261,33 +260,35 @@ fast_draw_rgba_pixels(GLcontext *ctx, GLint x, GLint y,
       return GL_TRUE;
    }
 
-   if (format==GL_COLOR_INDEX && type==GL_UNSIGNED_BYTE) {
+   if (format == GL_COLOR_INDEX && type == GL_UNSIGNED_BYTE) {
       const GLubyte *src = (const GLubyte *) pixels
          + unpack.SkipRows * unpack.RowLength + unpack.SkipPixels;
-      if (ctx->Visual.rgbMode && rbType == CHAN_TYPE) {
-         /* convert CI data to RGBA */
+      if (ctx->Visual.rgbMode && rbType == GL_UNSIGNED_BYTE) {
+         /* convert ubyte/CI data to ubyte/RGBA */
          if (simpleZoom) {
             GLint row;
             for (row = 0; row < drawHeight; row++) {
                ASSERT(drawWidth <= MAX_WIDTH);
-               _mesa_map_ci8_to_rgba(ctx, drawWidth, src, span.array->rgba);
+               _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
+                                      span.array->rgba8);
                rb->PutRow(ctx, rb, drawWidth, destX, destY,
-                          span.array->rgba, NULL);
+                          span.array->rgba8, NULL);
                src += unpack.RowLength;
                destY += yStep;
             }
          }
          else {
-            /* with zooming */
+            /* ubyte/CI to ubyte/RGBA with zooming */
             GLint row;
             for (row = 0; row < drawHeight; row++) {
                ASSERT(drawWidth <= MAX_WIDTH);
-               _mesa_map_ci8_to_rgba(ctx, drawWidth, src, span.array->rgba);
+               _mesa_map_ci8_to_rgba8(ctx, drawWidth, src,
+                                      span.array->rgba8);
                span.x = destX;
                span.y = destY;
                span.end = drawWidth;
                _swrast_write_zoomed_rgba_span(ctx, imgX, imgY, &span,
-                                              span.array->rgba);
+                                              span.array->rgba8);
                src += unpack.RowLength;
                destY++;
             }
@@ -328,18 +329,14 @@ draw_index_pixels( GLcontext *ctx, GLint x, GLint y,
                    const struct gl_pixelstore_attrib *unpack,
                    const GLvoid *pixels )
 {
-   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const GLint imgX = x, imgY = y;
    const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
    GLint row, skipPixels;
    SWspan span;
 
-   INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_INDEX);
-
-   if (ctx->Depth.Test)
-      _swrast_span_default_z(ctx, &span);
-   if (swrast->_FogEnabled)
-      _swrast_span_default_fog(ctx, &span);
+   INIT_SPAN(span, GL_BITMAP);
+   span.arrayMask = SPAN_INDEX;
+   _swrast_span_default_attribs(ctx, &span);
 
    /*
     * General solution
@@ -401,16 +398,9 @@ draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y,
                                                       width, height,
                                                       GL_COLOR_INDEX, type,
                                                       row, skipPixels);
-         _mesa_unpack_index_span(ctx, spanWidth, destType, values,
-                                 type, source, unpack,
-                                 ctx->_ImageTransferState);
-         if (ctx->_ImageTransferState & IMAGE_SHIFT_OFFSET_BIT) {
-            _mesa_shift_and_offset_stencil(ctx, spanWidth, values);
-         }
-         if (ctx->Pixel.MapStencilFlag) {
-            _mesa_map_stencil(ctx, spanWidth, values);
-         }
-
+         _mesa_unpack_stencil_span(ctx, spanWidth, destType, values,
+                                   type, source, unpack,
+                                   ctx->_ImageTransferState);
          if (zoom) {
             _swrast_write_zoomed_stencil_span(ctx, x, y, spanWidth,
                                               spanX, spanY, values);
@@ -434,27 +424,22 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y,
                    const struct gl_pixelstore_attrib *unpack,
                    const GLvoid *pixels )
 {
-   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const GLboolean scaleOrBias
       = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
    const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0;
    SWspan span;
 
-   INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_Z);
-
-   _swrast_span_default_color(ctx, &span);
-
-   if (swrast->_FogEnabled)
-      _swrast_span_default_fog(ctx, &span);
-   if (ctx->Texture._EnabledCoordUnits)
-      _swrast_span_default_texcoords(ctx, &span);
+   INIT_SPAN(span, GL_BITMAP);
+   span.arrayMask = SPAN_Z;
+   _swrast_span_default_attribs(ctx, &span);
 
    if (type == GL_UNSIGNED_SHORT
        && ctx->DrawBuffer->Visual.depthBits == 16
        && !scaleOrBias
        && !zoom
        && ctx->Visual.rgbMode
-       && width <= MAX_WIDTH) {
+       && width <= MAX_WIDTH
+       && !unpack->SwapBytes) {
       /* Special case: directly write 16-bit depth values */
       GLint row;
       for (row = 0; row < height; row++) {
@@ -474,7 +459,8 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y,
             && !scaleOrBias
             && !zoom
             && ctx->Visual.rgbMode
-            && width <= MAX_WIDTH) {
+            && width <= MAX_WIDTH
+            && !unpack->SwapBytes) {
       /* Special case: shift 32-bit values down to Visual.depthBits */
       const GLint shift = 32 - ctx->DrawBuffer->Visual.depthBits;
       GLint row;
@@ -498,7 +484,7 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y,
    }
    else {
       /* General case */
-      const GLfloat depthMax = ctx->DrawBuffer->_DepthMaxF;
+      const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
       GLint skipPixels = 0;
 
       /* in case width > MAX_WIDTH do the copy in chunks */
@@ -549,25 +535,22 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
                   const struct gl_pixelstore_attrib *unpack,
                   const GLvoid *pixels )
 {
-   SWcontext *swrast = SWRAST_CONTEXT(ctx);
    const GLint imgX = x, imgY = y;
    const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0;
    GLfloat *convImage = NULL;
-   GLuint transferOps = ctx->_ImageTransferState;
+   GLbitfield transferOps = ctx->_ImageTransferState;
    SWspan span;
 
    /* Try an optimized glDrawPixels first */
    if (fast_draw_rgba_pixels(ctx, x, y, width, height, format, type,
-                             unpack, pixels))
+                             unpack, pixels)) {
       return;
+   }
 
-   INIT_SPAN(span, GL_BITMAP, 0, 0, SPAN_RGBA);
-   if (ctx->Depth.Test)
-      _swrast_span_default_z(ctx, &span);
-   if (swrast->_FogEnabled)
-      _swrast_span_default_fog(ctx, &span);
-   if (ctx->Texture._EnabledCoordUnits)
-      _swrast_span_default_texcoords(ctx, &span);
+   INIT_SPAN(span, GL_BITMAP);
+   _swrast_span_default_attribs(ctx, &span);
+   span.arrayMask = SPAN_RGBA;
+   span.arrayAttribs = FRAG_BIT_COL0; /* we're fill in COL0 attrib values */
 
    if (ctx->Pixel.Convolution2DEnabled || ctx->Pixel.Separable2DEnabled) {
       /* Convolution has to be handled specially.  We'll create an
@@ -619,6 +602,11 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
       type = GL_FLOAT;
       transferOps &= IMAGE_POST_CONVOLUTION_BITS;
    }
+   else if (ctx->Pixel.Convolution1DEnabled) {
+      /* we only want to apply 1D convolution to glTexImage1D */
+      transferOps &= ~(IMAGE_CONVOLUTION_BIT |
+                       IMAGE_POST_CONVOLUTION_SCALE_BIAS);
+   }
 
    if (ctx->DrawBuffer->_NumColorDrawBuffers[0] > 0 &&
        ctx->DrawBuffer->_ColorDrawBuffers[0][0]->DataType != GL_FLOAT &&
@@ -639,13 +627,15 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
          = _mesa_image_row_stride(unpack, width, format, type);
       GLint skipPixels = 0;
       /* use span array for temp color storage */
-      GLfloat *rgba = (GLfloat *) span.array->color.sz4.rgba;
+      GLfloat *rgba = (GLfloat *) span.array->attribs[FRAG_ATTRIB_COL0];
 
       /* if the span is wider than MAX_WIDTH we have to do it in chunks */
       while (skipPixels < width) {
          const GLint spanWidth = MIN2(width - skipPixels, MAX_WIDTH);
-         const GLubyte *source = _mesa_image_address2d(unpack, pixels,
-                               width, height, format, type, 0, skipPixels);
+         const GLubyte *source
+            = (const GLubyte *) _mesa_image_address2d(unpack, pixels,
+                                                      width, height, format,
+                                                      type, 0, skipPixels);
          GLint row;
 
          for (row = 0; row < height; row++) {
@@ -705,7 +695,7 @@ draw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
    const GLint imgX = x, imgY = y;
    const GLboolean scaleOrBias
       = ctx->Pixel.DepthScale != 1.0 || ctx->Pixel.DepthBias != 0.0;
-   const GLfloat depthScale = ctx->DrawBuffer->_DepthMaxF;
+   const GLuint depthMax = ctx->DrawBuffer->_DepthMax;
    const GLuint stencilMask = ctx->Stencil.WriteMask[0];
    const GLuint stencilType = (STENCIL_BITS == 8) ? 
       GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
@@ -793,7 +783,7 @@ draw_depth_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
                /* general case */
                GLuint zValues[MAX_WIDTH];  /* 16 or 32-bit Z value storage */
                _mesa_unpack_depth_span(ctx, width,
-                                       depthRb->DataType, zValues, depthScale,
+                                       depthRb->DataType, zValues, depthMax,
                                        type, depthStencilSrc, &clippedUnpack);
                if (zoom) {
                   _swrast_write_zoomed_z_span(ctx, imgX, imgY, width, x,