/*
* Mesa 3-D graphics library
- * Version: 6.5.2
*
* Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*/
#include "main/formats.h"
#include "main/framebuffer.h"
#include "main/renderbuffer.h"
+#include "swrast/s_renderbuffer.h"
#define XMESA_RENDERBUFFER 0x1234
_mesa_warning(NULL, "alloc_back_buffer: XCreateImage failed.\n");
return;
}
- b->backxrb->ximage->data = (char *) MALLOC(b->backxrb->ximage->height
+ b->backxrb->ximage->data = malloc(b->backxrb->ximage->height
* b->backxrb->ximage->bytes_per_line);
if (!b->backxrb->ximage->data) {
_mesa_warning(NULL, "alloc_back_buffer: MALLOC failed.\n");
static void
-xmesa_delete_renderbuffer(struct gl_renderbuffer *rb)
+xmesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
{
/* XXX Note: the ximage or Pixmap attached to this renderbuffer
* should probably get freed here, but that's currently done in
struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer);
if (xrb) {
GLuint name = 0;
- _mesa_init_renderbuffer(&xrb->Base, name);
+ _mesa_init_renderbuffer(&xrb->Base.Base, name);
- xrb->Base.Delete = xmesa_delete_renderbuffer;
+ xrb->Base.Base.Delete = xmesa_delete_renderbuffer;
if (backBuffer)
- xrb->Base.AllocStorage = xmesa_alloc_back_storage;
+ xrb->Base.Base.AllocStorage = xmesa_alloc_back_storage;
else
- xrb->Base.AllocStorage = xmesa_alloc_front_storage;
+ xrb->Base.Base.AllocStorage = xmesa_alloc_front_storage;
- xrb->Base.InternalFormat = GL_RGBA;
- xrb->Base._BaseFormat = GL_RGBA;
- xrb->Base.DataType = GL_UNSIGNED_BYTE;
- xrb->Base.ClassID = XMESA_RENDERBUFFER;
+ xrb->Base.Base.InternalFormat = GL_RGBA;
+ xrb->Base.Base._BaseFormat = GL_RGBA;
+ xrb->Base.Base.ClassID = XMESA_RENDERBUFFER;
switch (xmvis->undithered_pf) {
case PF_8R8G8B:
/* This will really only happen for pixmaps. We'll access the
* pixmap via a temporary XImage which will be 32bpp.
*/
- xrb->Base.Format = MESA_FORMAT_XRGB8888;
+ xrb->Base.Base.Format = MESA_FORMAT_XRGB8888;
break;
case PF_8A8R8G8B:
- xrb->Base.Format = MESA_FORMAT_ARGB8888;
+ xrb->Base.Base.Format = MESA_FORMAT_ARGB8888;
break;
case PF_8A8B8G8R:
- xrb->Base.Format = MESA_FORMAT_RGBA8888_REV;
+ xrb->Base.Base.Format = MESA_FORMAT_RGBA8888_REV;
break;
case PF_5R6G5B:
- xrb->Base.Format = MESA_FORMAT_RGB565;
+ xrb->Base.Base.Format = MESA_FORMAT_RGB565;
break;
default:
_mesa_warning(ctx, "Bad pixel format in xmesa_new_renderbuffer");
- xrb->Base.Format = MESA_FORMAT_ARGB8888;
+ xrb->Base.Base.Format = MESA_FORMAT_ARGB8888;
break;
}
}
}
- if (b->rowimage) {
- free( b->rowimage->data );
- b->rowimage->data = NULL;
- XMesaDestroyImage( b->rowimage );
- }
-
_mesa_free_framebuffer_data(fb);
free(fb);
}
{
struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
- if (xrb->Base.ClassID == XMESA_RENDERBUFFER) {
+ if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
XImage *ximage = xrb->ximage;
assert(!xrb->map_mode); /* only a single mapping allowed */
}
else {
/* this must be a pixmap/window renderbuffer */
+ int (*old_handler)(XMesaDisplay *, XErrorEvent *);
int y2 = rb->Height - y - h;
assert(xrb->pixmap);
+ /* Install error handler for XGetImage() in case the the window
+ * isn't mapped. If we fail we'll create a temporary XImage.
+ */
+ mesaXErrorFlag = 0;
+ old_handler = XSetErrorHandler(mesaHandleXError);
+
/* read pixel data out of the pixmap/window into an XImage */
ximage = XGetImage(xrb->Parent->display,
xrb->pixmap, x, y2, w, h,
AllPlanes, ZPixmap);
+
+ XSetErrorHandler(old_handler);
+
+ if (mesaXErrorFlag) {
+ /* create new, temporary XImage */
+ int bytes_per_line =
+ _mesa_format_row_stride(xrb->Base.Base.Format,
+ xrb->Base.Base.Width);
+ char *image = malloc(bytes_per_line *
+ xrb->Base.Base.Height);
+ ximage = XCreateImage(xrb->Parent->display,
+ xrb->Parent->xm_visual->visinfo->visual,
+ xrb->Parent->xm_visual->visinfo->depth,
+ ZPixmap, /* format */
+ 0, /* offset */
+ image, /* data */
+ xrb->Base.Base.Width,
+ xrb->Base.Base.Height,
+ 8, /* pad */
+ bytes_per_line);
+ }
+
if (!ximage) {
*mapOut = NULL;
*rowStrideOut = 0;
}
/* otherwise, this is an ordinary malloc-based renderbuffer */
- _mesa_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
- mapOut, rowStrideOut);
+ _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode,
+ mapOut, rowStrideOut);
}
{
struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
- if (xrb->Base.ClassID == XMESA_RENDERBUFFER) {
+ if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
XImage *ximage = xrb->ximage;
if (!ximage) {
}
/* otherwise, this is an ordinary malloc-based renderbuffer */
- _mesa_unmap_soft_renderbuffer(ctx, rb);
+ _swrast_unmap_soft_renderbuffer(ctx, rb);
}