* 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;
return 0;
}
#else
- /* Can't compile XSHM support */
+ /* No XSHM support */
return 0;
#endif
}
-#endif
/*
_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);
}
/**********************************************************************/
-/*
- * 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
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)
/* 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. */
_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 );
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)
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;
}
}
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;
/* 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);
}
#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;
{
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 {
_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 */
{
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();
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) {
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 {
/**
- * 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;
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) {
_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;
_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
}
+/**
+ * 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
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);
}