Replace _mesa_malloc, _mesa_calloc and _mesa_free with plain libc versions
[mesa.git] / src / mesa / swrast / s_copypix.c
index 7385a9942c95c53b2a6753c35afc21198b327999..3f37c027e4a7be5eebfc8ac72f7e654341f9aa00 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.1
  *
  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
  *
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/colormac.h"
-#include "convolve.h"
-#include "histogram.h"
-#include "image.h"
+#include "main/condrender.h"
+#include "main/convolve.h"
+#include "main/image.h"
 #include "main/macros.h"
 #include "main/imports.h"
-#include "pixel.h"
 
 #include "s_context.h"
 #include "s_depth.h"
@@ -71,13 +70,20 @@ regions_overlap(GLint srcx, GLint srcy,
    }
    else {
       /* add one pixel of slop when zooming, just to be safe */
-      if ((srcx > dstx + (width * zoomX) + 1) || (srcx + width + 1 < dstx)) {
+      if (srcx > (dstx + ((zoomX > 0.0F) ? (width * zoomX + 1.0F) : 0.0F))) {
+         /* src is completely right of dest */
+         return GL_FALSE;
+      }
+      else if (srcx + width + 1.0F < dstx + ((zoomX > 0.0F) ? 0.0F : (width * zoomX))) {
+         /* src is completely left of dest */
          return GL_FALSE;
       }
       else if ((srcy < dsty) && (srcy + height < dsty + (height * zoomY))) {
+         /* src is completely below dest */
          return GL_FALSE;
       }
       else if ((srcy > dsty) && (srcy + height > dsty + (height * zoomY))) {
+         /* src is completely above dest */
          return GL_FALSE;
       }
       else {
@@ -108,14 +114,14 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    span.arrayAttribs = FRAG_BIT_COL0;
 
    /* allocate space for GLfloat image */
-   tmpImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
+   tmpImage = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
    if (!tmpImage) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
       return;
    }
-   convImage = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
+   convImage = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat));
    if (!convImage) {
-      _mesa_free(tmpImage);
+      free(tmpImage);
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
       return;
    }
@@ -144,7 +150,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       ASSERT(ctx->Pixel.Separable2DEnabled);
       _mesa_convolve_sep_image(ctx, &width, &height, tmpImage, convImage);
    }
-   _mesa_free(tmpImage);
+   free(tmpImage);
 
    /* do remaining post-convolution image transfer ops */
    for (row = 0; row < height; row++) {
@@ -161,7 +167,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
          GLfloat *rgba = (GLfloat *) span.array->attribs[FRAG_ATTRIB_COL0];
 
          /* copy convolved colors into span array */
-         _mesa_memcpy(rgba, src, width * 4 * sizeof(GLfloat));
+         memcpy(rgba, src, width * 4 * sizeof(GLfloat));
 
          /* write span */
          span.x = destx;
@@ -179,7 +185,7 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       span.array->ChanType = CHAN_TYPE;
    }
 
-   _mesa_free(convImage);
+   free(convImage);
 }
 
 
@@ -240,7 +246,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    span.arrayAttribs = FRAG_BIT_COL0; /* we'll fill in COL0 attrib values */
 
    if (overlapping) {
-      tmpImage = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat) * 4);
+      tmpImage = (GLfloat *) malloc(width * height * sizeof(GLfloat) * 4);
       if (!tmpImage) {
          _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
@@ -267,7 +273,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
       /* Get row/span of source pixels */
       if (overlapping) {
          /* get from buffered image */
-         _mesa_memcpy(rgba, p, width * sizeof(GLfloat) * 4);
+         memcpy(rgba, p, width * sizeof(GLfloat) * 4);
          p += width * 4;
       }
       else {
@@ -297,7 +303,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
    span.array->ChanType = CHAN_TYPE; /* restore */
 
    if (overlapping)
-      _mesa_free(tmpImage);
+      free(tmpImage);
 }
 
 
@@ -346,7 +352,7 @@ copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
    if (overlapping) {
       GLint ssy = sy;
-      tmpImage = (GLuint *) _mesa_malloc(width * height * sizeof(GLuint));
+      tmpImage = (GLuint *) malloc(width * height * sizeof(GLuint));
       if (!tmpImage) {
          _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
@@ -368,7 +374,7 @@ copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    for (j = 0; j < height; j++, sy += stepy, dy += stepy) {
       /* Get color indexes */
       if (overlapping) {
-         _mesa_memcpy(span.array->index, p, width * sizeof(GLuint));
+         memcpy(span.array->index, p, width * sizeof(GLuint));
          p += width;
       }
       else {
@@ -391,7 +397,7 @@ copy_ci_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    }
 
    if (overlapping)
-      _mesa_free(tmpImage);
+      free(tmpImage);
 }
 
 
@@ -481,7 +487,7 @@ copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
    if (overlapping) {
       GLint ssy = sy;
-      tmpImage = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat));
+      tmpImage = (GLfloat *) malloc(width * height * sizeof(GLfloat));
       if (!tmpImage) {
          _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
@@ -502,7 +508,7 @@ copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
       GLfloat depth[MAX_WIDTH];
       /* get depth values */
       if (overlapping) {
-         _mesa_memcpy(depth, p, width * sizeof(GLfloat));
+         memcpy(depth, p, width * sizeof(GLfloat));
          p += width;
       }
       else {
@@ -531,7 +537,7 @@ copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    }
 
    if (overlapping)
-      _mesa_free(tmpImage);
+      free(tmpImage);
 }
 
 
@@ -578,7 +584,7 @@ copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
    if (overlapping) {
       GLint ssy = sy;
-      tmpImage = (GLstencil *) _mesa_malloc(width * height * sizeof(GLstencil));
+      tmpImage = (GLstencil *) malloc(width * height * sizeof(GLstencil));
       if (!tmpImage) {
          _mesa_error( ctx, GL_OUT_OF_MEMORY, "glCopyPixels" );
          return;
@@ -600,7 +606,7 @@ copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
 
       /* Get stencil values */
       if (overlapping) {
-         _mesa_memcpy(stencil, p, width * sizeof(GLstencil));
+         memcpy(stencil, p, width * sizeof(GLstencil));
          p += width;
       }
       else {
@@ -620,7 +626,7 @@ copy_stencil_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
    }
 
    if (overlapping)
-      _mesa_free(tmpImage);
+      free(tmpImage);
 }
 
 
@@ -682,7 +688,7 @@ copy_depth_stencil_pixels(GLcontext *ctx,
 
       if (stencilMask != 0x0) {
          tempStencilImage
-            = (GLstencil *) _mesa_malloc(width * height * sizeof(GLstencil));
+            = (GLstencil *) malloc(width * height * sizeof(GLstencil));
          if (!tempStencilImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
             return;
@@ -700,10 +706,10 @@ copy_depth_stencil_pixels(GLcontext *ctx,
 
       if (ctx->Depth.Mask) {
          tempDepthImage
-            = (GLfloat *) _mesa_malloc(width * height * sizeof(GLfloat));
+            = (GLfloat *) malloc(width * height * sizeof(GLfloat));
          if (!tempDepthImage) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCopyPixels");
-            _mesa_free(tempStencilImage);
+            free(tempStencilImage);
             return;
          }
 
@@ -724,7 +730,7 @@ copy_depth_stencil_pixels(GLcontext *ctx,
 
          /* Get stencil values */
          if (overlapping) {
-            _mesa_memcpy(stencil, stencilPtr, width * sizeof(GLstencil));
+            memcpy(stencil, stencilPtr, width * sizeof(GLstencil));
             stencilPtr += width;
          }
          else {
@@ -753,7 +759,7 @@ copy_depth_stencil_pixels(GLcontext *ctx,
 
          /* get depth values */
          if (overlapping) {
-            _mesa_memcpy(depth, depthPtr, width * sizeof(GLfloat));
+            memcpy(depth, depthPtr, width * sizeof(GLfloat));
             depthPtr += width;
          }
          else {
@@ -793,10 +799,10 @@ copy_depth_stencil_pixels(GLcontext *ctx,
    }
 
    if (tempStencilImage)
-      _mesa_free(tempStencilImage);
+      free(tempStencilImage);
 
    if (tempDepthImage)
-      _mesa_free(tempDepthImage);
+      free(tempDepthImage);
 }
 
 
@@ -823,10 +829,10 @@ fast_copy_pixels(GLcontext *ctx,
    }
 
    if (type == GL_COLOR) {
-      if (dstFb->_NumColorDrawBuffers[0] != 1)
+      if (dstFb->_NumColorDrawBuffers != 1)
          return GL_FALSE;
       srcRb = srcFb->_ColorReadBuffer;
-      dstRb = dstFb->_ColorDrawBuffers[0][0];
+      dstRb = dstFb->_ColorDrawBuffers[0];
    }
    else if (type == GL_STENCIL) {
       srcRb = srcFb->_StencilBuffer;
@@ -892,8 +898,11 @@ _swrast_CopyPixels( GLcontext *ctx,
                    GLint destx, GLint desty, GLenum type )
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
-   RENDER_START(swrast,ctx);
+   swrast_render_start(ctx);
       
+   if (!_mesa_check_conditional_render(ctx))
+      return; /* don't copy */
+
    if (swrast->NewState)
       _swrast_validate_derived( ctx );
 
@@ -921,5 +930,5 @@ _swrast_CopyPixels( GLcontext *ctx,
       }
    }
 
-   RENDER_FINISH(swrast,ctx);
+   swrast_render_finish(ctx);
 }