swrast: Fix memory leaks in blit_linear.
[mesa.git] / src / mesa / swrast / s_context.h
index 7f1e4c78ee485cbf6fb8ac151986161a5102f30b..26b97f78decdfc322dd67d2ef8d8162ed9026e2c 100644 (file)
@@ -47,6 +47,7 @@
 #include "main/mtypes.h"
 #include "program/prog_execute.h"
 #include "swrast.h"
+#include "s_fragprog.h"
 #include "s_span.h"
 
 
@@ -120,14 +121,10 @@ typedef void (*FetchTexelFunc)(const struct swrast_texture_image *texImage,
                                GLfloat *texelOut);
 
 
-typedef void (*StoreTexelFunc)(struct swrast_texture_image *texImage,
-                               GLint col, GLint row, GLint img,
-                               const void *texel);
-
 /**
  * Subclass of gl_texture_image.
  * We need extra fields/info to keep tracking of mapped texture buffers,
- * strides and Fetch/Store functions.
+ * strides and Fetch functions.
  */
 struct swrast_texture_image
 {
@@ -148,7 +145,6 @@ struct swrast_texture_image
    GLubyte *Buffer;
 
    FetchTexelFunc FetchTexel;
-   StoreTexelFunc Store;
 };
 
 
@@ -167,6 +163,34 @@ swrast_texture_image_const(const struct gl_texture_image *img)
 }
 
 
+/**
+ * Subclass of gl_renderbuffer with extra fields needed for software
+ * rendering.
+ */
+struct swrast_renderbuffer
+{
+   struct gl_renderbuffer Base;
+
+   GLubyte *Buffer;     /**< The malloc'd memory for buffer */
+
+   /** These fields are only valid while buffer is mapped for rendering */
+   GLubyte *Map;
+   GLint RowStride;    /**< in bytes */
+
+   /** For span rendering */
+   GLenum ColorType;
+};
+
+
+/** cast wrapper */
+static inline struct swrast_renderbuffer *
+swrast_renderbuffer(struct gl_renderbuffer *img)
+{
+   return (struct swrast_renderbuffer *) img;
+}
+
+
+
 /**
  * \struct SWcontext
  * \brief  Per-context state that's private to the software rasterizer module.
@@ -282,6 +306,13 @@ typedef struct
    /** State used during execution of fragment programs */
    struct gl_program_machine FragProgMachine;
 
+   /** Temporary arrays for stencil operations.  To avoid large stack
+    * allocations.
+    */
+   struct {
+      GLubyte *buf1, *buf2, *buf3, *buf4;
+   } stencil_temp;
+
 } SWcontext;
 
 
@@ -428,8 +459,9 @@ _swrast_unmap_renderbuffers(struct gl_context *ctx);
 static inline GLubyte *
 _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
 {
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    const GLint bpp = _mesa_get_format_bytes(rb->Format);
-   const GLint rowStride = rb->RowStrideBytes;
+   const GLint rowStride = srb->RowStride;
    assert(x >= 0);
    assert(y >= 0);
    /* NOTE: using <= only because of s_tritemp.h which gets a pixel
@@ -437,8 +469,8 @@ _swrast_pixel_address(struct gl_renderbuffer *rb, GLint x, GLint y)
     */
    assert(x <= (GLint) rb->Width);
    assert(y <= (GLint) rb->Height);
-   assert(rb->Map);
-   return (GLubyte *) rb->Map + y * rowStride + x * bpp;
+   assert(srb->Map);
+   return (GLubyte *) srb->Map + y * rowStride + x * bpp;
 }