/** * Called via gl_framebuffer::Delete() method when this buffer * is _really_ being deleted. */ void xmesa_delete_framebuffer(struct gl_framebuffer *fb) { XMesaBuffer b = XMESA_BUFFER(fb); if (b->num_alloced > 0) { /* If no other buffer uses this X colormap then free the colors. */ if (!xmesa_find_buffer(b->display, b->cmap, b)) { XFreeColors(b->display, b->cmap, b->alloced_colors, b->num_alloced, 0); } } if (b->gc) XMesaFreeGC(b->display, b->gc); if (b->cleargc) XMesaFreeGC(b->display, b->cleargc); if (b->swapgc) XMesaFreeGC(b->display, b->swapgc); if (fb->Visual.doubleBufferMode) { /* free back ximage/pixmap/shmregion */ if (b->backxrb->ximage) { #if defined(USE_XSHM) if (b->shm) { XShmDetach( b->display, &b->shminfo ); XDestroyImage( b->backxrb->ximage ); shmdt( b->shminfo.shmaddr ); } else #endif XMesaDestroyImage( b->backxrb->ximage ); b->backxrb->ximage = NULL; } if (b->backxrb->pixmap) { XMesaFreePixmap( b->display, b->backxrb->pixmap ); if (b->xm_visual->hpcr_clear_flag) { XMesaFreePixmap( b->display, b->xm_visual->hpcr_clear_pixmap ); XMesaDestroyImage( b->xm_visual->hpcr_clear_ximage ); } } } if (b->rowimage) { free( b->rowimage->data ); b->rowimage->data = NULL; XMesaDestroyImage( b->rowimage ); } _mesa_free_framebuffer_data(fb); free(fb); }
/** * Setup an off-screen pixmap or Ximage to use as the back buffer. * Input: b - the X/Mesa buffer */ static void alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height) { if (b->db_mode == BACK_XIMAGE) { /* Deallocate the old backxrb->ximage, if any */ if (b->backxrb->ximage) { #if defined(USE_XSHM) if (b->shm) { XShmDetach(b->xm_visual->display, &b->shminfo); XDestroyImage(b->backxrb->ximage); shmdt(b->shminfo.shmaddr); } else #endif XMesaDestroyImage(b->backxrb->ximage); b->backxrb->ximage = NULL; } if (width == 0 || height == 0) return; /* Allocate new back buffer */ if (b->shm == 0 || !alloc_back_shm_ximage(b, width, height)) { /* Allocate a regular XImage for the back buffer. */ b->backxrb->ximage = XCreateImage(b->xm_visual->display, b->xm_visual->visinfo->visual, GET_VISUAL_DEPTH(b->xm_visual), ZPixmap, 0, /* format, offset */ NULL, width, height, 8, 0); /* pad, bytes_per_line */ if (!b->backxrb->ximage) { _mesa_warning(NULL, "alloc_back_buffer: XCreateImage failed.\n"); return; } b->backxrb->ximage->data = (char *) 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"); XMesaDestroyImage(b->backxrb->ximage); b->backxrb->ximage = NULL; } } b->backxrb->pixmap = None; } else if (b->db_mode == BACK_PIXMAP) { /* Free the old back pixmap */ if (b->backxrb->pixmap) { XMesaFreePixmap(b->xm_visual->display, b->backxrb->pixmap); b->backxrb->pixmap = 0; } if (width > 0 && height > 0) { /* Allocate new back pixmap */ b->backxrb->pixmap = XMesaCreatePixmap(b->xm_visual->display, b->frontxrb->drawable, width, height, GET_VISUAL_DEPTH(b->xm_visual)); } b->backxrb->ximage = NULL; b->backxrb->drawable = b->backxrb->pixmap; } }