#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;
* 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"
{ NULL, NULL }
};
+
+/**
+ * Screen and config-related functions
+ */
+
static void
setupLoaderExtensions(__DRIscreen *psp,
const __DRIextension **extensions)
/**
- * 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
{
struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
int bpp;
+ unsigned mask = PITCH_ALIGN_BITS - 1;
TRACE;
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);
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) {
/**
- * swrast_dd.c
+ * General device driver functions.
*/
static void
case GL_VENDOR:
return (const GLubyte *) "Mesa Project";
case GL_RENDERER:
- return (const GLubyte *) "X.Org";
+ return (const GLubyte *) "Software Rasterizer";
default:
return NULL;
}
/**
- * swrast_context.c
+ * Context-related functions.
*/
static __DRIcontext *
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) {
static const __DRIcoreExtension driCoreExtension = {
{ __DRI_CORE, __DRI_CORE_VERSION },
- NULL,
+ NULL, /* driCreateNewScreen */
driDestroyScreen,
driGetExtensions,
driGetConfigAttrib,
driIndexConfigAttrib,
- NULL,
+ NULL, /* driCreateNewDrawable */
driDestroyDrawable,
driSwapBuffers,
driCreateNewContext,
static const __DRIswrastExtension driSWRastExtension = {
{ __DRI_SWRAST, __DRI_SWRAST_VERSION },
driCreateNewScreen,
- driCreateNewDrawable,
+ driCreateNewDrawable
};
/* This is the table of extensions that the loader will dlsym() for. */
#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__)
__DRIscreen *driScreenPriv;
+ /* scratch row for optimized front-buffer rendering */
char *row;
};
struct swrast_renderbuffer {
struct gl_renderbuffer Base;
+ /* renderbuffer pitch (in bytes) */
GLuint pitch;
};
#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_ */
/*
- * Generate code for image span functions.
+ * Generate code for back-buffer span functions.
*/
/* 32-bit BGRA */
/*
- * 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);
/* 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);
/* 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);
/* 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 \
/*
- * 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:
/*
- * 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
* 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);
/*
- * 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.
*/
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
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 */
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++) {