swrast: Fix memory leaks in blit_linear.
[mesa.git] / src / mesa / swrast / s_context.h
index 8357483a27f6b73dfe0bde59f1d06d6c1305f98a..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"
 
 
@@ -112,70 +113,84 @@ typedef void (*validate_texture_image_func)(struct gl_context *ctx,
 struct swrast_texture_image;
 
 
-typedef void (*FetchTexelFuncC)(const struct swrast_texture_image *texImage,
-                                GLint col, GLint row, GLint img,
-                                GLchan *texelOut);
-
 /**
- * As above, but returns floats.
- * Used for depth component images and for upcoming signed/float
- * texture images.
+ * Fetch a texel from texture image at given position.
  */
-typedef void (*FetchTexelFuncF)(const struct swrast_texture_image *texImage,
-                                GLint col, GLint row, GLint img,
-                                GLfloat *texelOut);
-
-
-typedef void (*StoreTexelFunc)(struct swrast_texture_image *texImage,
+typedef void (*FetchTexelFunc)(const struct swrast_texture_image *texImage,
                                GLint col, GLint row, GLint img,
-                               const void *texel);
+                               GLfloat *texelOut);
+
 
 /**
  * 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
 {
    struct gl_texture_image Base;
 
-#if 0
-   /** used for mipmap LOD computation */
-   GLfloat WidthScale, HeightScale, DepthScale;
    GLboolean _IsPowerOfTwo;  /**< Are all dimensions powers of two? */
 
-   GLubyte *Data;    /**< The actual texture data in malloc'd memory */
+   /** used for mipmap LOD computation */
+   GLfloat WidthScale, HeightScale, DepthScale;
 
-   GLint TexelSize;  /**< bytes per texel block */
-#endif
+   /** These fields only valid when texture memory is mapped */
+   GLint RowStride;            /**< Padded width in units of texels */
+   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
+                                     each 2D slice in 'Data', in texels */
+   GLubyte *Map;               /**< Pointer to mapped image memory */
 
-   FetchTexelFuncC FetchTexelc;
-   FetchTexelFuncF FetchTexelf;
-   StoreTexelFunc Store;
+   /** Malloc'd texture memory */
+   GLubyte *Buffer;
 
-#if 0
-   /** These fields only valid when texture memory is mapped */
-   GLubyte **SliceMaps;  /**< points to OneMap or a malloc'd array */
-   GLint RowStride;  /**< bytes per row of blocks */
-#endif
+   FetchTexelFunc FetchTexel;
 };
 
 
 /** cast wrapper */
-static INLINE struct swrast_texture_image *
+static inline struct swrast_texture_image *
 swrast_texture_image(struct gl_texture_image *img)
 {
    return (struct swrast_texture_image *) img;
 }
 
 /** cast wrapper */
-static INLINE const struct swrast_texture_image *
+static inline const struct swrast_texture_image *
 swrast_texture_image_const(const struct gl_texture_image *img)
 {
    return (const struct swrast_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.
@@ -205,18 +220,13 @@ typedef struct
 
    /** List/array of the fragment attributes to interpolate */
    GLuint _ActiveAttribs[FRAG_ATTRIB_MAX];
-   /** Same info, but as a bitmask */
-   GLbitfield _ActiveAttribMask;
+   /** Same info, but as a bitmask of FRAG_BIT_x bits */
+   GLbitfield64 _ActiveAttribMask;
    /** Number of fragment attributes to interpolate */
    GLuint _NumActiveAttribs;
    /** Indicates how each attrib is to be interpolated (lines/tris) */
    GLenum _InterpMode[FRAG_ATTRIB_MAX]; /* GL_FLAT or GL_SMOOTH (for now) */
 
-   /* Accum buffer temporaries.
-    */
-   GLboolean _IntegerAccumMode;        /**< Storing unscaled integers? */
-   GLfloat _IntegerAccumScaler;        /**< Implicit scale factor */
-
    /* Working values:
     */
    GLuint StippleCounter;    /**< Line stipple counter */
@@ -296,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;
 
 
@@ -307,14 +324,14 @@ _swrast_update_texture_samplers(struct gl_context *ctx);
 
 
 /** Return SWcontext for the given struct gl_context */
-static INLINE SWcontext *
+static inline SWcontext *
 SWRAST_CONTEXT(struct gl_context *ctx)
 {
    return (SWcontext *) ctx->swrast_context;
 }
 
 /** const version of above */
-static INLINE const SWcontext *
+static inline const SWcontext *
 CONST_SWRAST_CONTEXT(const struct gl_context *ctx)
 {
    return (const SWcontext *) ctx->swrast_context;
@@ -326,7 +343,7 @@ CONST_SWRAST_CONTEXT(const struct gl_context *ctx)
  * For drivers that rely on swrast for fallback rendering, this is the
  * driver's opportunity to map renderbuffers and textures.
  */
-static INLINE void
+static inline void
 swrast_render_start(struct gl_context *ctx)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
@@ -336,7 +353,7 @@ swrast_render_start(struct gl_context *ctx)
 
 
 /** Called after framebuffer reading/writing */
-static INLINE void
+static inline void
 swrast_render_finish(struct gl_context *ctx)
 {
    SWcontext *swrast = SWRAST_CONTEXT(ctx);
@@ -345,6 +362,31 @@ swrast_render_finish(struct gl_context *ctx)
 }
 
 
+extern void
+_swrast_span_render_start(struct gl_context *ctx);
+
+extern void
+_swrast_span_render_finish(struct gl_context *ctx);
+
+extern void
+_swrast_map_textures(struct gl_context *ctx);
+
+extern void
+_swrast_unmap_textures(struct gl_context *ctx);
+
+extern void
+_swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj);
+
+extern void
+_swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj);
+
+
+extern void
+_swrast_map_renderbuffers(struct gl_context *ctx);
+
+extern void
+_swrast_unmap_renderbuffers(struct gl_context *ctx);
+
 
 /**
  * Size of an RGBA pixel, in bytes, for given datatype.
@@ -411,5 +453,26 @@ swrast_render_finish(struct gl_context *ctx)
 #define ATTRIB_LOOP_END } }
 
 
+/**
+ * Return the address of a pixel value in a mapped renderbuffer.
+ */
+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 = srb->RowStride;
+   assert(x >= 0);
+   assert(y >= 0);
+   /* NOTE: using <= only because of s_tritemp.h which gets a pixel
+    * address but doesn't necessarily access it.
+    */
+   assert(x <= (GLint) rb->Width);
+   assert(y <= (GLint) rb->Height);
+   assert(srb->Map);
+   return (GLubyte *) srb->Map + y * rowStride + x * bpp;
+}
+
+
 
 #endif