dri/swrast: cosmetic, mainly generic vs. xorg terminology
authorGeorge Sapountzis <gsap7@yahoo.gr>
Fri, 23 May 2008 19:55:36 +0000 (22:55 +0300)
committerGeorge Sapountzis <gsap7@yahoo.gr>
Fri, 23 May 2008 19:55:36 +0000 (22:55 +0300)
src/mesa/drivers/dri/common/utils.h
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/drivers/dri/swrast/swrast_priv.h
src/mesa/drivers/dri/swrast/swrast_span.c
src/mesa/drivers/dri/swrast/swrast_spantemp.h

index 31a26ed..0c09a7e 100644 (file)
@@ -29,7 +29,8 @@
 #ifndef DRI_DEBUG_H
 #define DRI_DEBUG_H
 
-#include "GL/internal/dri_interface.h"
+#include <GL/gl.h>
+#include <GL/internal/dri_interface.h>
 #include "context.h"
 
 typedef struct __DRIutilversionRec2    __DRIutilversion2;
index 6a9eb15..c4dba59 100644 (file)
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
-#include <GL/gl.h>
-#include <GL/internal/dri_interface.h>
+/*
+ * DRI software rasterizer
+ *
+ * This is the mesa swrast module packaged into a DRI driver structure.
+ *
+ * The front-buffer is allocated by the loader. The loader provides read/write
+ * callbacks for access to the front-buffer. The driver uses a scratch row for
+ * front-buffer rendering to avoid repeated calls to the loader.
+ *
+ * The back-buffer is allocated by the driver and is private.
+ */
+
 #include "context.h"
 #include "extensions.h"
 #include "framebuffer.h"
@@ -96,6 +106,11 @@ const struct dri_extension card_extensions[] =
     { NULL,                            NULL }
 };
 
+
+/**
+ * Screen and config-related functions
+ */
+
 static void
 setupLoaderExtensions(__DRIscreen *psp,
                      const __DRIextension **extensions)
@@ -223,17 +238,14 @@ static const __DRIextension **driGetExtensions(__DRIscreen *psp)
 
 
 /**
- * swrast_buffer.c
+ * Framebuffer and renderbuffer-related functions.
  */
 
 static GLuint
 choose_pixel_format(const GLvisual *v)
 {
     if (v->rgbMode) {
-       /* XXX 24bpp packed, 8bpp, xmesa gets bitsPerPixel from xserver */
        int bpp = v->rgbBits;
-       if (bpp == 24)
-           bpp = 32;
 
        if (bpp == 32
            && v->redMask   == 0xff0000
@@ -275,6 +287,7 @@ swrast_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
 {
     struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
     int bpp;
+    unsigned mask = PITCH_ALIGN_BITS - 1;
 
     TRACE;
 
@@ -297,15 +310,15 @@ swrast_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
        return GL_FALSE;
     }
 
-    /* always pad to 32 bits */
-    xrb->pitch = ((width * bpp + 0x1f) & ~0x1f) / 8;
+    /* always pad to PITCH_ALIGN_BITS */
+    xrb->pitch = ((width * bpp + mask) & ~mask) / 8;
 
     return GL_TRUE;
 }
 
 static GLboolean
 swrast_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
-                       GLenum internalFormat, GLuint width, GLuint height)
+                         GLenum internalFormat, GLuint width, GLuint height)
 {
     struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
 
@@ -336,11 +349,11 @@ swrast_new_renderbuffer(const GLvisual *visual, GLboolean front)
        xrb->Base.Delete = swrast_delete_renderbuffer;
        if (front) {
            xrb->Base.AllocStorage = swrast_alloc_front_storage;
-           swrast_set_span_funcs_pixmap(xrb, pixel_format);
+           swrast_set_span_funcs_front(xrb, pixel_format);
        }
        else {
            xrb->Base.AllocStorage = swrast_alloc_back_storage;
-           swrast_set_span_funcs_ximage(xrb, pixel_format);
+           swrast_set_span_funcs_back(xrb, pixel_format);
        }
 
        switch (pixel_format) {
@@ -476,7 +489,7 @@ static void driSwapBuffers(__DRIdrawable *buf)
 
 
 /**
- * swrast_dd.c
+ * General device driver functions.
  */
 
 static void
@@ -510,7 +523,7 @@ get_string(GLcontext *ctx, GLenum pname)
        case GL_VENDOR:
            return (const GLubyte *) "Mesa Project";
        case GL_RENDERER:
-           return (const GLubyte *) "X.Org";
+           return (const GLubyte *) "Software Rasterizer";
        default:
            return NULL;
     }
@@ -547,7 +560,7 @@ swrast_init_driver_functions(struct dd_function_table *driver)
 
 
 /**
- * swrast_context.c
+ * Context-related functions.
  */
 
 static __DRIcontext *
@@ -645,10 +658,11 @@ static int driBindContext(__DRIcontext *ctx,
        if (!draw || !read)
            return GL_FALSE;
 
-       /* check for same context and buffer */
        mesaCtx = &ctx->Base;
        mesaDraw = &draw->Base;
        mesaRead = &read->Base;
+
+       /* check for same context and buffer */
        if (mesaCtx == _mesa_get_current_context()
            && mesaCtx->DrawBuffer == mesaDraw
            && mesaCtx->ReadBuffer == mesaRead) {
@@ -684,12 +698,12 @@ static int driUnbindContext(__DRIcontext *ctx)
 
 static const __DRIcoreExtension driCoreExtension = {
     { __DRI_CORE, __DRI_CORE_VERSION },
-    NULL,
+    NULL, /* driCreateNewScreen */
     driDestroyScreen,
     driGetExtensions,
     driGetConfigAttrib,
     driIndexConfigAttrib,
-    NULL,
+    NULL, /* driCreateNewDrawable */
     driDestroyDrawable,
     driSwapBuffers,
     driCreateNewContext,
@@ -702,7 +716,7 @@ static const __DRIcoreExtension driCoreExtension = {
 static const __DRIswrastExtension driSWRastExtension = {
     { __DRI_SWRAST, __DRI_SWRAST_VERSION },
     driCreateNewScreen,
-    driCreateNewDrawable,
+    driCreateNewDrawable
 };
 
 /* This is the table of extensions that the loader will dlsym() for. */
index e12743b..a3e3922 100644 (file)
 #include <GL/internal/dri_interface.h>
 #include "mtypes.h"
 
+
+/**
+ * Debugging
+ */
 #define DEBUG_CORE     0
-#define DEBUG_SPAN     1
+#define DEBUG_SPAN     0
 
 #if DEBUG_CORE
 #define TRACE _mesa_printf("--> %s\n", __FUNCTION__)
@@ -77,12 +81,14 @@ struct __DRIdrawableRec {
 
     __DRIscreen *driScreenPriv;
 
+    /* scratch row for optimized front-buffer rendering */
     char *row;
 };
 
 struct swrast_renderbuffer {
     struct gl_renderbuffer Base;
 
+    /* renderbuffer pitch (in bytes) */
     GLuint pitch;
 };
 
@@ -114,14 +120,23 @@ swrast_renderbuffer(struct gl_renderbuffer *rb)
 #define PF_R3G3B2     4                /**<  8-bit TrueColor:  3-R, 3-G, 2-B bits */
 
 
+/**
+ * Renderbuffer pitch alignment (in bits).
+ *
+ * The xorg loader requires padding images to 32 bits. However, this should
+ * become a screen/drawable parameter XXX
+ */
+#define PITCH_ALIGN_BITS 32
+
+
 /* swrast_span.c */
 
 extern void
-swrast_set_span_funcs_ximage(struct swrast_renderbuffer *xrb,
-                            GLuint pixel_format);
+swrast_set_span_funcs_back(struct swrast_renderbuffer *xrb,
+                          GLuint pixel_format);
 
 extern void
-swrast_set_span_funcs_pixmap(struct swrast_renderbuffer *xrb,
-                            GLuint pixel_format);
+swrast_set_span_funcs_front(struct swrast_renderbuffer *xrb,
+                           GLuint pixel_format);
 
 #endif /* _SWRAST_PRIV_H_ */
index 35b9ddf..5e99036 100644 (file)
@@ -118,7 +118,7 @@ static const GLubyte kernel[16] = {
 
 
 /*
- * Generate code for image span functions.
+ * Generate code for back-buffer span functions.
  */
 
 /* 32-bit BGRA */
@@ -189,11 +189,11 @@ static const GLubyte kernel[16] = {
 
 
 /*
- * Generate code for pixmap span functions.
+ * Generate code for front-buffer span functions.
  */
 
 /* 32-bit BGRA */
-#define NAME(FUNC) FUNC##_A8R8G8B8_pixmap
+#define NAME(FUNC) FUNC##_A8R8G8B8_front
 #define RB_TYPE GLubyte
 #define SPAN_VARS \
    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
@@ -211,7 +211,7 @@ static const GLubyte kernel[16] = {
 
 
 /* 16-bit BGR */
-#define NAME(FUNC) FUNC##_R5G6B5_pixmap
+#define NAME(FUNC) FUNC##_R5G6B5_front
 #define RB_TYPE GLubyte
 #define SPAN_VARS \
    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
@@ -227,7 +227,7 @@ static const GLubyte kernel[16] = {
 
 
 /* 8-bit BGR */
-#define NAME(FUNC) FUNC##_R3G3B2_pixmap
+#define NAME(FUNC) FUNC##_R3G3B2_front
 #define RB_TYPE GLubyte
 #define SPAN_VARS \
    struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
@@ -243,7 +243,7 @@ static const GLubyte kernel[16] = {
 
 
 /* 8-bit color index */
-#define NAME(FUNC) FUNC##_CI8_pixmap
+#define NAME(FUNC) FUNC##_CI8_front
 #define CI_MODE
 #define RB_TYPE GLubyte
 #define SPAN_VARS \
@@ -260,14 +260,14 @@ static const GLubyte kernel[16] = {
 
 
 /*
- * Images are malloced memory used for private back-buffers.
+ * Back-buffers are malloced memory and always private.
  *
  * BACK_PIXMAP (not supported)
  * BACK_XIMAGE
  */
 void
-swrast_set_span_funcs_ximage(struct swrast_renderbuffer *xrb,
-                            GLuint pixel_format)
+swrast_set_span_funcs_back(struct swrast_renderbuffer *xrb,
+                          GLuint pixel_format)
 {
     switch (pixel_format) {
     case PF_A8R8G8B8:
@@ -313,7 +313,7 @@ swrast_set_span_funcs_ximage(struct swrast_renderbuffer *xrb,
 
 
 /*
- * Pixmaps are used for front-buffers.
+ * Front-buffers are provided by the loader, the xorg loader uses pixmaps.
  *
  * WINDOW,          An X window
  * GLXWINDOW,       GLX window
@@ -321,44 +321,44 @@ swrast_set_span_funcs_ximage(struct swrast_renderbuffer *xrb,
  * PBUFFER          GLX Pbuffer
  */
 void
-swrast_set_span_funcs_pixmap(struct swrast_renderbuffer *xrb,
-                            GLuint pixel_format)
+swrast_set_span_funcs_front(struct swrast_renderbuffer *xrb,
+                           GLuint pixel_format)
 {
     switch (pixel_format) {
     case PF_A8R8G8B8:
-       xrb->Base.GetRow = get_row_A8R8G8B8_pixmap;
-       xrb->Base.GetValues = get_values_A8R8G8B8_pixmap;
-       xrb->Base.PutRow = put_row_A8R8G8B8_pixmap;
-       xrb->Base.PutRowRGB = put_row_rgb_A8R8G8B8_pixmap;
-       xrb->Base.PutMonoRow = put_mono_row_A8R8G8B8_pixmap;
-       xrb->Base.PutValues = put_values_A8R8G8B8_pixmap;
-       xrb->Base.PutMonoValues = put_mono_values_A8R8G8B8_pixmap;
+       xrb->Base.GetRow = get_row_A8R8G8B8_front;
+       xrb->Base.GetValues = get_values_A8R8G8B8_front;
+       xrb->Base.PutRow = put_row_A8R8G8B8_front;
+       xrb->Base.PutRowRGB = put_row_rgb_A8R8G8B8_front;
+       xrb->Base.PutMonoRow = put_mono_row_A8R8G8B8_front;
+       xrb->Base.PutValues = put_values_A8R8G8B8_front;
+       xrb->Base.PutMonoValues = put_mono_values_A8R8G8B8_front;
        break;
     case PF_R5G6B5:
-       xrb->Base.GetRow = get_row_R5G6B5_pixmap;
-       xrb->Base.GetValues = get_values_R5G6B5_pixmap;
-       xrb->Base.PutRow = put_row_R5G6B5_pixmap;
-       xrb->Base.PutRowRGB = put_row_rgb_R5G6B5_pixmap;
-       xrb->Base.PutMonoRow = put_mono_row_R5G6B5_pixmap;
-       xrb->Base.PutValues = put_values_R5G6B5_pixmap;
-       xrb->Base.PutMonoValues = put_mono_values_R5G6B5_pixmap;
+       xrb->Base.GetRow = get_row_R5G6B5_front;
+       xrb->Base.GetValues = get_values_R5G6B5_front;
+       xrb->Base.PutRow = put_row_R5G6B5_front;
+       xrb->Base.PutRowRGB = put_row_rgb_R5G6B5_front;
+       xrb->Base.PutMonoRow = put_mono_row_R5G6B5_front;
+       xrb->Base.PutValues = put_values_R5G6B5_front;
+       xrb->Base.PutMonoValues = put_mono_values_R5G6B5_front;
        break;
     case PF_R3G3B2:
-       xrb->Base.GetRow = get_row_R3G3B2_pixmap;
-       xrb->Base.GetValues = get_values_R3G3B2_pixmap;
-       xrb->Base.PutRow = put_row_R3G3B2_pixmap;
-       xrb->Base.PutRowRGB = put_row_rgb_R3G3B2_pixmap;
-       xrb->Base.PutMonoRow = put_mono_row_R3G3B2_pixmap;
-       xrb->Base.PutValues = put_values_R3G3B2_pixmap;
-       xrb->Base.PutMonoValues = put_mono_values_R3G3B2_pixmap;
+       xrb->Base.GetRow = get_row_R3G3B2_front;
+       xrb->Base.GetValues = get_values_R3G3B2_front;
+       xrb->Base.PutRow = put_row_R3G3B2_front;
+       xrb->Base.PutRowRGB = put_row_rgb_R3G3B2_front;
+       xrb->Base.PutMonoRow = put_mono_row_R3G3B2_front;
+       xrb->Base.PutValues = put_values_R3G3B2_front;
+       xrb->Base.PutMonoValues = put_mono_values_R3G3B2_front;
        break;
     case PF_CI8:
-       xrb->Base.GetRow = get_row_CI8_pixmap;
-       xrb->Base.GetValues = get_values_CI8_pixmap;
-       xrb->Base.PutRow = put_row_CI8_pixmap;
-       xrb->Base.PutMonoRow = put_mono_row_CI8_pixmap;
-       xrb->Base.PutValues = put_values_CI8_pixmap;
-       xrb->Base.PutMonoValues = put_mono_values_CI8_pixmap;
+       xrb->Base.GetRow = get_row_CI8_front;
+       xrb->Base.GetValues = get_values_CI8_front;
+       xrb->Base.PutRow = put_row_CI8_front;
+       xrb->Base.PutMonoRow = put_mono_row_CI8_front;
+       xrb->Base.PutValues = put_values_CI8_front;
+       xrb->Base.PutMonoValues = put_mono_values_CI8_front;
        break;
     default:
        assert(0);
index 7c60c15..e7a9c86 100644 (file)
 
 
 /*
- * This is a modified version of swrast/s_spantemp.h for rendering to X11
- * drawables. The no-mask paths use a scratch row to avoid repeated calls
- * to xserver.
+ * Modified version of swrast/s_spantemp.h for front-buffer rendering. The
+ * no-mask paths use a scratch row to avoid repeated calls to the loader.
  *
- * For the mask paths we always use an array of 4 elements of RB_TYPE because
- * we should pad "image" pitch to 32 bits. 
+ * For the mask paths we always use an array of 4 elements of RB_TYPE. This is
+ * to satisfy the xorg loader requirement of an image pitch of 32 bits and
+ * should be ok for other loaders also.
  */
 
 
@@ -54,12 +54,12 @@ static inline void
 GET_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p )
 {
     __DRIcontext *ctx = swrast_context(glCtx);
-    __DRIdrawable *draw = swrast_drawable(glCtx->ReadBuffer);
+    __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer);
 
     __DRIscreen *screen = ctx->driScreenPriv;
 
-    screen->swrast_loader->getImage(draw, x, y, 1, 1, (char *)p,
-                                   draw->loaderPrivate);
+    screen->swrast_loader->getImage(read, x, y, 1, 1, (char *)p,
+                                   read->loaderPrivate);
 }
 
 static inline void
@@ -79,12 +79,12 @@ static inline void
 GET_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row )
 {
     __DRIcontext *ctx = swrast_context(glCtx);
-    __DRIdrawable *draw = swrast_drawable(glCtx->ReadBuffer);
+    __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer);
 
     __DRIscreen *screen = ctx->driScreenPriv;
 
-    screen->swrast_loader->getImage(draw, x, y, n, 1, row,
-                                   draw->loaderPrivate);
+    screen->swrast_loader->getImage(read, x, y, n, 1, row,
+                                   read->loaderPrivate);
 }
 
 #endif /* _SWRAST_SPANTEMP_ONCE */
@@ -133,7 +133,7 @@ NAME(get_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
    RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
 #endif
    GLuint i;
-   char *row = swrast_drawable(ctx->DrawBuffer)->row;
+   char *row = swrast_drawable(ctx->ReadBuffer)->row;
    INIT_PIXEL_PTR(pixel, x, y);
    GET_ROW( ctx, x, YFLIP(xrb, y), count, row );
    for (i = 0; i < count; i++) {