/* Shutdown X11 */ void X11_Shutdown (struct _video_out *vout) { X11VID (); if (xWindow->output_3d_mode==1) { #ifdef GPAC_HAS_OPENGL X11_ReleaseGL(xWindow); #endif } else { X11_ReleaseBackBuffer (vout); } #ifdef GPAC_HAS_OPENGL if (xWindow->glx_visualinfo) XFree(xWindow->glx_visualinfo); xWindow->glx_visualinfo = NULL; #endif XFreeGC (xWindow->display, xWindow->the_gc); XUnmapWindow (xWindow->display, (Window) xWindow->wnd); XDestroyWindow (xWindow->display, (Window) xWindow->wnd); XDestroyWindow (xWindow->display, (Window) xWindow->full_wnd); #ifdef GPAC_HAS_OPENGL if (xWindow->gl_offscreen) glXDestroyGLXPixmap(xWindow->display, xWindow->gl_offscreen); if (xWindow->gl_pixmap) XFreePixmap(xWindow->display, xWindow->gl_pixmap); XUnmapWindow (xWindow->display, (Window) xWindow->gl_wnd); XDestroyWindow (xWindow->display, (Window) xWindow->gl_wnd); #endif /*restore xscreen saver*/ X11_XScreenSaverState(xWindow, 1); XCloseDisplay (xWindow->display); gf_free(xWindow); }
/* Shutdown X11 */ void X11_Shutdown (struct _video_out *vout) { X11VID (); if (xWindow->is_3D_out) { #ifdef GPAC_HAS_OPENGL X11_ReleaseGL(xWindow); #endif } else { X11_ReleaseBackBuffer (vout); } free(xWindow->back_buffer); XFreeGC (xWindow->display, xWindow->the_gc); XUnmapWindow (xWindow->display, (Window) xWindow->wnd); XDestroyWindow (xWindow->display, (Window) xWindow->wnd); XDestroyWindow (xWindow->display, (Window) xWindow->full_wnd); XCloseDisplay (xWindow->display); free (xWindow); }
/* * init backbuffer */ GF_Err X11_InitBackBuffer (GF_VideoOutput * vout, u32 VideoWidth, u32 VideoHeight) { Window cur_wnd; u32 size; VideoWidth = VideoWidth > 32 ? VideoWidth : 32; VideoWidth = VideoWidth < 4096 ? VideoWidth : 4096; VideoHeight = VideoHeight > 32 ? VideoHeight : 32; VideoHeight = VideoHeight > 4096 ? 4096 : VideoHeight; X11VID (); if (!xWindow || !VideoWidth || !VideoHeight) return GF_BAD_PARAM; X11_ReleaseBackBuffer(vout); /*WATCHOUT seems we need even width when using shared memory extensions*/ if (xWindow->use_shared_memory && (VideoWidth%2)) VideoWidth++; size = VideoWidth * VideoHeight * xWindow->bpp; cur_wnd = xWindow->fullscreen ? xWindow->full_wnd : xWindow->wnd; #ifdef GPAC_HAS_X11_SHM /*if we're using YUV blit to offscreen, we must use a pixmap*/ if (vout->hw_caps & GF_VIDEO_HW_HAS_YUV) { GF_SAFEALLOC(xWindow->shmseginfo, XShmSegmentInfo); xWindow->shmseginfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0776); xWindow->shmseginfo->shmaddr = shmat(xWindow->shmseginfo->shmid, 0, 0); xWindow->shmseginfo->readOnly = False; if (!XShmAttach (xWindow->display, xWindow->shmseginfo)) { GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[X11] Failed to attach shared memory!\n")); } xWindow->pixmap = XShmCreatePixmap(xWindow->display, cur_wnd, (unsigned char *) xWindow->shmseginfo->shmaddr, xWindow->shmseginfo, VideoWidth, VideoHeight, xWindow->depth); memset((unsigned char *) xWindow->shmseginfo->shmaddr, 0, sizeof(char)*size); XSetWindowBackgroundPixmap (xWindow->display, cur_wnd, xWindow->pixmap); xWindow->pwidth = VideoWidth; xWindow->pheight = VideoHeight; GF_LOG(GF_LOG_DEBUG, GF_LOG_MMIO, ("[X11] Using X11 Pixmap %08x\n", (u32)xWindow->pixmap)); } else if (xWindow->use_shared_memory) { GF_SAFEALLOC(xWindow->shmseginfo, XShmSegmentInfo); xWindow->surface = XShmCreateImage (xWindow->display, xWindow->visual, xWindow->depth, ZPixmap, NULL, xWindow->shmseginfo, VideoWidth, VideoHeight); xWindow->shmseginfo->shmid = shmget(IPC_PRIVATE, xWindow->surface->bytes_per_line * xWindow->surface->height, IPC_CREAT | 0777); xWindow->surface->data = xWindow->shmseginfo->shmaddr = shmat(xWindow->shmseginfo->shmid, NULL, 0); xWindow->shmseginfo->readOnly = False; XShmAttach (xWindow->display, xWindow->shmseginfo); } else #endif { char *data = (char *) gf_malloc(sizeof(char)*size); xWindow->surface = XCreateImage (xWindow->display, xWindow->visual, xWindow->depth, ZPixmap, 0, data, VideoWidth, VideoHeight, xWindow->bpp*8, xWindow->bpp*VideoWidth); if (!xWindow->surface) { gf_free(data); return GF_IO_ERR; } } xWindow->is_init = 1; return GF_OK; }
/* * init backbuffer */ GF_Err X11_InitBackBuffer (GF_VideoOutput * vout, u32 VideoWidth, u32 VideoHeight) { Window cur_wnd; u32 size; VideoWidth = VideoWidth > 32 ? VideoWidth : 32; VideoWidth = VideoWidth < 4096 ? VideoWidth : 4096; VideoHeight = VideoHeight > 32 ? VideoHeight : 32; VideoHeight = VideoHeight > 4096 ? 4096 : VideoHeight; X11VID (); if (!xWindow || !VideoWidth || !VideoHeight) return GF_BAD_PARAM; X11_ReleaseBackBuffer(vout); /*WATCHOUT seems we need even width when using shared memory extensions*/ if ((xWindow->videoaccesstype!=VIDEO_XI_STANDARD) && (VideoWidth%2)) VideoWidth++; xWindow->back_buffer->BPP = xWindow->bpp; xWindow->back_buffer->width = VideoWidth; xWindow->back_buffer->height = VideoHeight; xWindow->back_buffer->pitch = VideoWidth * xWindow->bpp; size = VideoWidth * VideoHeight * xWindow->bpp; cur_wnd = xWindow->fullscreen ? xWindow->full_wnd : xWindow->wnd; switch (xWindow->videoaccesstype) { #ifdef GPAC_HAS_X11_SHM case VIDEO_XI_SHMPIXMAP: GF_SAFEALLOC(xWindow->shmseginfo, XShmSegmentInfo); xWindow->shmseginfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777); xWindow->shmseginfo->shmaddr = shmat(xWindow->shmseginfo->shmid, 0, 0); xWindow->back_buffer->buffer = (unsigned char *) xWindow->shmseginfo->shmaddr; xWindow->shmseginfo->readOnly = False; XShmAttach (xWindow->display, xWindow->shmseginfo); xWindow->pixmap = XShmCreatePixmap (xWindow->display, cur_wnd, xWindow->back_buffer->buffer, xWindow->shmseginfo, VideoWidth, VideoHeight, xWindow->depth); XSetWindowBackgroundPixmap (xWindow->display, cur_wnd, xWindow->pixmap); break; case VIDEO_XI_SHMSTD: GF_SAFEALLOC(xWindow->shmseginfo, XShmSegmentInfo); xWindow->surface = XShmCreateImage (xWindow->display, xWindow->visual, xWindow->depth, ZPixmap, NULL, xWindow->shmseginfo, VideoWidth, VideoHeight); xWindow->shmseginfo->shmid = shmget(IPC_PRIVATE, xWindow->surface->bytes_per_line * xWindow->surface->height, IPC_CREAT | 0777); xWindow->surface->data = xWindow->shmseginfo->shmaddr = shmat(xWindow->shmseginfo->shmid, NULL, 0); xWindow->back_buffer->buffer = (unsigned char *) xWindow->surface->data; xWindow->shmseginfo->readOnly = False; XShmAttach (xWindow->display, xWindow->shmseginfo); break; #endif case VIDEO_XI_STANDARD: xWindow->back_buffer->buffer = (char *) malloc(sizeof(char)*size); xWindow->surface = XCreateImage (xWindow->display, xWindow->visual, xWindow->depth, ZPixmap, 0, xWindow->back_buffer->buffer, VideoWidth, VideoHeight, xWindow->bpp*8, xWindow->back_buffer->pitch); } xWindow->is_init = 1; return GF_OK; }