summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2005-09-07 23:28:41 +0000
committerBrian Paul <[email protected]>2005-09-07 23:28:41 +0000
commit692147ebf7f09d56a7de1659de2449478da4d1ba (patch)
tree66ea84bc75d49ba40a056604bf229354a2fcd659 /src
parent526242614fd5200def246e1bbb9dca78020abc32 (diff)
some clean-up and re-org for renderbuffers
Diffstat (limited to 'src')
-rw-r--r--src/mesa/drivers/x11/xm_api.c117
-rw-r--r--src/mesa/drivers/x11/xm_buffer.c53
-rw-r--r--src/mesa/drivers/x11/xm_dd.c53
-rw-r--r--src/mesa/drivers/x11/xmesaP.h22
4 files changed, 132 insertions, 113 deletions
diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c
index ad9756bb90c..86395b7778a 100644
--- a/src/mesa/drivers/x11/xm_api.c
+++ b/src/mesa/drivers/x11/xm_api.c
@@ -196,10 +196,11 @@ static int mesaHandleXError( XMesaDisplay *dpy, XErrorEvent *event )
* 1 = shared XImage support available
* 2 = shared Pixmap support available also
*/
-#ifndef XFree86Server
static int check_for_xshm( XMesaDisplay *display )
{
-#ifdef USE_XSHM
+#if defined(XFree86Server)
+ return 0;
+#elif defined(USE_XSHM)
int major, minor, ignore;
Bool pixmaps;
@@ -215,11 +216,10 @@ static int check_for_xshm( XMesaDisplay *display )
return 0;
}
#else
- /* Can't compile XSHM support */
+ /* No XSHM support */
return 0;
#endif
}
-#endif
/*
@@ -347,31 +347,24 @@ alloc_xmesa_buffer(XMesaVisual vis, BufferType type, XMesaColormap cmap)
_mesa_initialize_framebuffer(&b->mesa_buffer, &vis->mesa_visual);
- /* determine back buffer implementation */
- if (vis->mesa_visual.doubleBufferMode) {
- if (vis->ximage_flag) {
- b->db_state = BACK_XIMAGE;
- }
- else {
- b->db_state = BACK_PIXMAP;
- }
- }
- else {
- b->db_state = 0;
- }
-
/* Allocate the framebuffer's renderbuffers */
assert(!b->mesa_buffer.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
assert(!b->mesa_buffer.Attachment[BUFFER_BACK_LEFT].Renderbuffer);
/* front renderbuffer */
- b->frontxrb = xmesa_new_renderbuffer(NULL, 0, vis->mesa_visual.rgbMode);
+ b->frontxrb = xmesa_new_renderbuffer(NULL, 0, vis->mesa_visual.rgbMode,
+ GL_FALSE);
_mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_FRONT_LEFT,
&b->frontxrb->Base);
/* back renderbuffer */
if (vis->mesa_visual.doubleBufferMode) {
- b->backxrb =xmesa_new_renderbuffer(NULL, 0, vis->mesa_visual.rgbMode);
+ b->backxrb = xmesa_new_renderbuffer(NULL, 0,
+ vis->mesa_visual.rgbMode,
+ GL_TRUE);
+ /* determine back buffer implementation */
+ b->db_mode = vis->ximage_flag ? BACK_XIMAGE : BACK_PIXMAP;
+
_mesa_add_renderbuffer(&b->mesa_buffer, BUFFER_BACK_LEFT,
&b->backxrb->Base);
}
@@ -472,22 +465,6 @@ static void copy_colortable_info(XMesaBuffer dst, const XMesaBuffer src)
/**********************************************************************/
-/*
- * Return number of bits set in n.
- */
-static int bitcount( unsigned long n )
-{
- int bits;
- for (bits=0; n>0; n=n>>1) {
- if (n&1) {
- bits++;
- }
- }
- return bits;
-}
-
-
-
/**
* Allocate a shared memory XImage back buffer for the given XMesaBuffer.
* Return: GL_TRUE if success, GL_FALSE if error
@@ -605,7 +582,7 @@ xmesa_alloc_back_buffer( XMesaBuffer b, GLuint width, GLuint height )
if (width == 0 || height == 0)
return;
- if (b->db_state == BACK_XIMAGE) {
+ if (b->db_mode == BACK_XIMAGE) {
/* Deallocate the old backxrb->ximage, if any */
if (b->backxrb->ximage) {
#if defined(USE_XSHM) && !defined(XFree86Server)
@@ -622,10 +599,9 @@ xmesa_alloc_back_buffer( XMesaBuffer b, GLuint width, GLuint height )
/* Allocate new back buffer */
#ifdef XFree86Server
- {
- /* Allocate a regular XImage for the back buffer. */
- b->backxrb->ximage = XMesaCreateImage(b->xm_visual->BitsPerPixel,
- width, height, NULL);
+ /* Allocate a regular XImage for the back buffer. */
+ b->backxrb->ximage = XMesaCreateImage(b->xm_visual->BitsPerPixel,
+ width, height, NULL);
#else
if (b->shm == 0 || !alloc_shm_back_buffer(b, width, height)) {
/* Allocate a regular XImage for the back buffer. */
@@ -641,7 +617,7 @@ xmesa_alloc_back_buffer( XMesaBuffer b, GLuint width, GLuint height )
_mesa_warning(NULL, "alloc_back_buffer: XCreateImage failed.");
}
b->backxrb->ximage->data = (char *) MALLOC( b->backxrb->ximage->height
- * b->backxrb->ximage->bytes_per_line );
+ * b->backxrb->ximage->bytes_per_line );
if (!b->backxrb->ximage->data) {
_mesa_warning(NULL, "alloc_back_buffer: MALLOC failed.");
XMesaDestroyImage( b->backxrb->ximage );
@@ -651,7 +627,7 @@ xmesa_alloc_back_buffer( XMesaBuffer b, GLuint width, GLuint height )
b->backxrb->pixmap = None;
b->backxrb->ximage = b->backxrb->ximage;
}
- else if (b->db_state==BACK_PIXMAP) {
+ else if (b->db_mode == BACK_PIXMAP) {
if (!width)
width = 1;
if (!height)
@@ -662,9 +638,10 @@ xmesa_alloc_back_buffer( XMesaBuffer b, GLuint width, GLuint height )
XMesaFreePixmap( b->xm_visual->display, b->backxrb->pixmap );
}
/* Allocate new back pixmap */
- b->backxrb->pixmap = XMesaCreatePixmap( b->xm_visual->display, b->frontxrb->pixmap,
- width, height,
- GET_VISUAL_DEPTH(b->xm_visual) );
+ b->backxrb->pixmap = XMesaCreatePixmap( b->xm_visual->display,
+ b->frontxrb->pixmap,
+ width, height,
+ GET_VISUAL_DEPTH(b->xm_visual) );
b->backxrb->ximage = NULL;
}
}
@@ -1070,9 +1047,9 @@ static void setup_truecolor( XMesaVisual v, XMesaBuffer buffer,
3*16, 11*16, 1*16, 9*16,
15*16, 7*16, 13*16, 5*16,
};
- GLint rBits = bitcount(rmask);
- GLint gBits = bitcount(gmask);
- GLint bBits = bitcount(bmask);
+ GLint rBits = _mesa_bitcount(rmask);
+ GLint gBits = _mesa_bitcount(gmask);
+ GLint bBits = _mesa_bitcount(bmask);
GLint maxBits;
GLuint i;
@@ -1286,9 +1263,7 @@ static GLboolean initialize_visual_and_buffer( int client,
/* Setup for single/double buffering */
if (v->mesa_visual.doubleBufferMode) {
/* Double buffered */
-#ifndef XFree86Server
b->shm = check_for_xshm( v->display );
-#endif
xmesa_alloc_back_buffer(b, b->mesa_buffer.Width, b->mesa_buffer.Height);
}
@@ -1315,9 +1290,9 @@ static GLboolean initialize_visual_and_buffer( int client,
#ifdef XFree86Server
b->swapgc = CreateScratchGC(v->display, window->depth);
{
- CARD32 v[1];
- v[0] = FALSE;
- dixChangeGC(NullClient, b->swapgc, GCGraphicsExposures, v, NULL);
+ CARD32 v[1];
+ v[0] = FALSE;
+ dixChangeGC(NullClient, b->swapgc, GCGraphicsExposures, v, NULL);
}
#else
gcvalues.graphics_exposures = False;
@@ -1592,9 +1567,9 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display,
{
const int xclass = v->mesa_visual.visualType;
if (xclass==GLX_TRUE_COLOR || xclass==GLX_DIRECT_COLOR) {
- red_bits = bitcount(GET_REDMASK(v));
- green_bits = bitcount(GET_GREENMASK(v));
- blue_bits = bitcount(GET_BLUEMASK(v));
+ red_bits = _mesa_bitcount(GET_REDMASK(v));
+ green_bits = _mesa_bitcount(GET_GREENMASK(v));
+ blue_bits = _mesa_bitcount(GET_BLUEMASK(v));
alpha_bits = 0;
}
else {
@@ -1691,13 +1666,13 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
_mesa_enable_2_0_extensions(mesaCtx);
#if ENABLE_EXT_texure_compression_s3tc
if (c->Mesa_DXTn) {
- _mesa_enable_extension(c, "GL_EXT_texture_compression_s3tc");
- _mesa_enable_extension(c, "GL_S3_s3tc");
+ _mesa_enable_extension(mesaCtx, "GL_EXT_texture_compression_s3tc");
+ _mesa_enable_extension(mesaCtx, "GL_S3_s3tc");
}
- _mesa_enable_extension(c, "GL_3DFX_texture_compression_FXT1");
+ _mesa_enable_extension(mesaCtx, "GL_3DFX_texture_compression_FXT1");
#endif
#if ENABLE_EXT_timer_query
- _mesa_enable_extension(c, "GL_EXT_timer_query");
+ _mesa_enable_extension(mesaCtx, "GL_EXT_timer_query");
#endif
/* finish up xmesa context initializations */
@@ -2316,13 +2291,18 @@ void XMesaSwapBuffers( XMesaBuffer b )
{
GET_CURRENT_CONTEXT(ctx);
+ if (!b->backxrb) {
+ /* single buffered */
+ return;
+ }
+
/* If we're swapping the buffer associated with the current context
* we have to flush any pending rendering commands first.
*/
if (ctx && ctx->DrawBuffer == &(b->mesa_buffer))
_mesa_notifySwapBuffers(ctx);
- if (b->db_state) {
+ if (b->db_mode) {
#ifdef FX
if (b->FXctx) {
fxMesaSwapBuffers();
@@ -2389,7 +2369,12 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height )
if (ctx && ctx->DrawBuffer == &(b->mesa_buffer))
_mesa_notifySwapBuffers(ctx);
- if (b->db_state) {
+ if (!b->backxrb) {
+ /* single buffered */
+ return;
+ }
+
+ if (b->db_mode) {
int yTop = b->mesa_buffer.Height - y - height;
#ifdef FX
if (b->FXctx) {
@@ -2448,9 +2433,11 @@ GLboolean XMesaGetBackBuffer( XMesaBuffer b,
XMesaPixmap *pixmap,
XMesaImage **ximage )
{
- if (b->db_state) {
- if (pixmap) *pixmap = b->backxrb->pixmap;
- if (ximage) *ximage = b->backxrb->ximage;
+ if (b->db_mode) {
+ if (pixmap)
+ *pixmap = b->backxrb->pixmap;
+ if (ximage)
+ *ximage = b->backxrb->ximage;
return GL_TRUE;
}
else {
diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c
index 593ac2bb19c..5db0b496c73 100644
--- a/src/mesa/drivers/x11/xm_buffer.c
+++ b/src/mesa/drivers/x11/xm_buffer.c
@@ -42,16 +42,44 @@ xmesa_delete_renderbuffer(struct gl_renderbuffer *rb)
/**
- * Reallocate renderbuffer storage.
- * This is called when the window's resized. It'll get called once for
- * the front color renderbuffer and again for the back color renderbuffer.
+ * Reallocate renderbuffer storage for front color buffer.
*/
static GLboolean
-xmesa_alloc_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
- GLenum internalFormat, GLuint width, GLuint height)
+xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat, GLuint width, GLuint height)
{
struct xmesa_renderbuffer *xrb = (struct xmesa_renderbuffer *) rb;
+ /* just clear these to be sure we don't accidentally use them */
+ xrb->origin1 = NULL;
+ xrb->origin2 = NULL;
+ xrb->origin4 = NULL;
+
+ /* for the FLIP macro: */
+ xrb->bottom = height - 1;
+
+ rb->Width = width;
+ rb->Height = height;
+ rb->InternalFormat = internalFormat;
+
+ return GL_TRUE;
+}
+
+
+/**
+ * Reallocate renderbuffer storage for back color buffer.
+ * XXX we should resize the back pixmap/ximage here.
+ */
+static GLboolean
+xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
+ GLenum internalFormat, GLuint width, GLuint height)
+{
+ struct xmesa_renderbuffer *xrb = (struct xmesa_renderbuffer *) rb;
+
+ /* same as front buffer */
+ (void) xmesa_alloc_front_storage(ctx, rb, internalFormat, width, height);
+
+ /* plus... */
if (xrb->ximage) {
/* Needed by PIXELADDR1 macro */
xrb->width1 = xrb->ximage->bytes_per_line;
@@ -73,19 +101,13 @@ xmesa_alloc_storage(GLcontext *ctx, struct gl_renderbuffer *rb,
assert(xrb->pixmap);
}
- /* for the FLIP macro: */
- xrb->bottom = height - 1;
-
- rb->Width = width;
- rb->Height = height;
- rb->InternalFormat = internalFormat;
-
return GL_TRUE;
}
struct xmesa_renderbuffer *
-xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode)
+xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode,
+ GLboolean backBuffer)
{
struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer);
if (xrb) {
@@ -93,7 +115,10 @@ xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode)
_mesa_init_renderbuffer(&xrb->Base, name);
xrb->Base.Delete = xmesa_delete_renderbuffer;
- xrb->Base.AllocStorage = xmesa_alloc_storage;
+ if (backBuffer)
+ xrb->Base.AllocStorage = xmesa_alloc_back_storage;
+ else
+ xrb->Base.AllocStorage = xmesa_alloc_front_storage;
if (rgbMode) {
xrb->Base.InternalFormat = GL_RGBA;
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c
index 76dec19f531..fcfe32ed42f 100644
--- a/src/mesa/drivers/x11/xm_dd.c
+++ b/src/mesa/drivers/x11/xm_dd.c
@@ -114,8 +114,8 @@ get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
_glthread_LOCK_MUTEX(_xmesa_lock);
XSync(xmBuffer->xm_visual->display, 0); /* added for Chromium */
- XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontxrb->pixmap, &root,
- &winx, &winy, &winwidth, &winheight, &bw, &d );
+ XGetGeometry( xmBuffer->xm_visual->display, xmBuffer->frontxrb->pixmap,
+ &root, &winx, &winy, &winwidth, &winheight, &bw, &d );
_glthread_UNLOCK_MUTEX(_xmesa_lock);
#endif
@@ -1095,6 +1095,34 @@ choose_tex_format( GLcontext *ctx, GLint internalFormat,
/**
+ * Get the current drawing (and reading) window's size and update the
+ * corresponding gl_framebuffer(s) if needed.
+ */
+static void
+update_framebuffer_size(GLcontext *ctx)
+{
+ struct gl_framebuffer *fb = ctx->WinSysDrawBuffer;
+ GLuint newWidth, newHeight;
+ get_buffer_size(fb, &newWidth, &newHeight);
+ if (newWidth != fb->Width || newHeight != fb->Height) {
+ xmesa_resize_buffers(ctx, fb, newWidth, newHeight);
+ ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
+ }
+
+ if (ctx->WinSysReadBuffer != ctx->WinSysDrawBuffer) {
+ /* Update readbuffer's size */
+ struct gl_framebuffer *fb = ctx->WinSysReadBuffer;
+ GLuint newWidth, newHeight;
+ get_buffer_size(fb, &newWidth, &newHeight);
+ if (newWidth != fb->Width || newHeight != fb->Height) {
+ xmesa_resize_buffers(ctx, fb, newWidth, newHeight);
+ ctx->NewState |= _NEW_BUFFERS;
+ }
+ }
+}
+
+
+/**
* Called by glViewport.
* This is a good time for us to poll the current X window size and adjust
* our renderbuffers to match the current window size.
@@ -1107,26 +1135,7 @@ choose_tex_format( GLcontext *ctx, GLint internalFormat,
static void
xmesa_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
{
-#if 1
- struct gl_framebuffer *fb = ctx->WinSysDrawBuffer;
- GLuint newWidth, newHeight;
-
- /*
- printf("%s before %d x %d\n", __FUNCTION__, fb->Width, fb->Height);
- */
-
- get_buffer_size(fb, &newWidth, &newHeight);
- if (newWidth != fb->Width || newHeight != fb->Height) {
- xmesa_resize_buffers(ctx, fb, newWidth, newHeight);
- ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */
- }
- /*
- printf("%s after %d x %d\n", __FUNCTION__, fb->Width, fb->Height);
- */
-#else
- /* This also works: */
- _mesa_ResizeBuffersMESA();
-#endif
+ update_framebuffer_size(ctx);
}
diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h
index 7030afaa119..5f4e3d4cf29 100644
--- a/src/mesa/drivers/x11/xmesaP.h
+++ b/src/mesa/drivers/x11/xmesaP.h
@@ -156,6 +156,11 @@ typedef enum {
} BufferType;
+/* Values for db_mode: */
+#define BACK_PIXMAP 1
+#define BACK_XIMAGE 2
+
+
struct xmesa_renderbuffer
{
struct gl_renderbuffer Base; /* Base class */
@@ -174,7 +179,7 @@ struct xmesa_renderbuffer
GLuint *origin4; /* used for PIXEL_ADDR4 macro */
GLint width4;
- GLint bottom; /* used for FLIP macro */
+ GLint bottom; /* used for FLIP macro, equals height - 1 */
ClearFunc clearFunc;
};
@@ -199,19 +204,17 @@ struct xmesa_buffer {
unsigned long selectedEvents;/* for pbuffers only */
- GLint db_state; /* 0 = single buffered */
+ GLint db_mode; /* 0 = single buffered */
/* BACK_PIXMAP = use Pixmap for back buffer */
/* BACK_XIMAGE = use XImage for back buffer */
-#ifndef XFree86Server
GLuint shm; /* X Shared Memory extension status: */
/* 0 = not available */
/* 1 = XImage support available */
/* 2 = Pixmap support available too */
-#ifdef USE_XSHM
+#if defined(USE_XSHM) && !defined(XFree86Server)
XShmSegmentInfo shminfo;
#endif
-#endif
XMesaImage *rowimage; /* Used for optimized span writing */
XMesaPixmap stipple_pixmap; /* For polygon stippling */
@@ -252,12 +255,6 @@ struct xmesa_buffer {
};
-/* Values for xmesa->db_state: */
-#define FRONT_PIXMAP 1
-#define BACK_PIXMAP 2
-#define BACK_XIMAGE 4
-
-
/*
* If pixelformat==PF_TRUECOLOR:
*/
@@ -489,7 +486,8 @@ extern const int xmesa_kernel1[16];
*/
extern struct xmesa_renderbuffer *
-xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode);
+xmesa_new_renderbuffer(GLcontext *ctx, GLuint name, GLboolean rgbMode,
+ GLboolean backBuffer);
extern unsigned long
xmesa_color_to_pixel( GLcontext *ctx,