Ejemplo n.º 1
0
void exit_display()
{
   int i;

   glXMakeContextCurrent(display, None, None, NULL);
   glXDestroyContext(display, gl_context);
   glXDestroyWindow(display, gl_window);
   glXDestroyPbuffer(display, gl_pbuffer);

#ifdef USE_NV_FENCE
   glDeleteFencesNV(1, &nvFence);
#endif

   XDestroyWindow(display, window);

   for(i = 0; i < numsurfaces; i++) {
     XvMCDestroySurface(display, &surfaces[i]);
   }

   XvMCDestroyBlocks(display, &blocks);
   XvMCDestroyMacroBlocks(display, &macro_blocks);
   XvMCDestroyContext(display, &context);
   XvUngrabPort(display, portNum, CurrentTime);
  
   XCloseDisplay(display);
}
Ejemplo n.º 2
0
SceneOpenGL::~SceneOpenGL()
{
    if (!init_ok) {
        // TODO this probably needs to clean up whatever has been created until the failure
        m_overlayWindow->destroy();
        return;
    }
    foreach (Window * w, windows)
    delete w;
    // do cleanup after initBuffer()
    cleanupGL();
    glXMakeCurrent(display(), None, NULL);
    glXDestroyContext(display(), ctxbuffer);
    if (m_overlayWindow->window()) {
        if (hasGLXVersion(1, 3))
            glXDestroyWindow(display(), glxbuffer);
        XDestroyWindow(display(), buffer);
        m_overlayWindow->destroy();
    } else {
        glXDestroyPixmap(display(), glxbuffer);
        XFreeGC(display(), gcroot);
        XFreePixmap(display(), buffer);
    }
    SceneOpenGL::EffectFrame::cleanup();
    checkGLError("Cleanup");
}
Ejemplo n.º 3
0
static void
clutter_stage_glx_unrealize (ClutterStageWindow *stage_window)
{
  ClutterBackend *backend = clutter_get_default_backend ();
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (backend);
  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
  ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);

  /* Note unrealize should free up any backend stage related resources */
  CLUTTER_NOTE (BACKEND, "Unrealizing stage");

  clutter_x11_trap_x_errors ();

  if (stage_glx->glxwin != None)
    {
      glXDestroyWindow (backend_x11->xdpy, stage_glx->glxwin);
      stage_glx->glxwin = None;
    }

  if (!stage_x11->is_foreign_xwin && stage_x11->xwin != None)
    {
      XDestroyWindow (backend_x11->xdpy, stage_x11->xwin);
      stage_x11->xwin = None;
    }
  else
    stage_x11->xwin = None;

  XSync (backend_x11->xdpy, False);

  clutter_x11_untrap_x_errors ();

  CLUTTER_MARK ();
}
Ejemplo n.º 4
0
static void
clutter_backend_glx_dispose (GObject *gobject)
{
  ClutterBackendGLX *backend_glx = CLUTTER_BACKEND_GLX (gobject);
  ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (gobject);

  /* Unrealize all shaders, since the GL context is going away */
  _clutter_shader_release_all ();

  if (backend_glx->gl_context)
    {
      glXMakeContextCurrent (backend_x11->xdpy, None, None, NULL);
      glXDestroyContext (backend_x11->xdpy, backend_glx->gl_context);
      backend_glx->gl_context = None;
    }

  if (backend_glx->dummy_glxwin)
    {
      glXDestroyWindow (backend_x11->xdpy, backend_glx->dummy_glxwin);
      backend_glx->dummy_glxwin = None;
    }

  if (backend_glx->dummy_xwin)
    {
      XDestroyWindow (backend_x11->xdpy, backend_glx->dummy_xwin);
      backend_glx->dummy_xwin = None;
    }

  G_OBJECT_CLASS (clutter_backend_glx_parent_class)->dispose (gobject);
}
Ejemplo n.º 5
0
GlxBackend::~GlxBackend()
{
    if (isFailed()) {
        m_overlayWindow->destroy();
    }
    // TODO: cleanup in error case
    // do cleanup after initBuffer()
    cleanupGL();
    doneCurrent();

    gs_tripleBufferUndetected = true;
    gs_tripleBufferNeedsDetection = false;

    if (ctx)
        glXDestroyContext(display(), ctx);

    if (glxWindow)
        glXDestroyWindow(display(), glxWindow);

    if (window)
        XDestroyWindow(display(), window);

    overlayWindow()->destroy();
    delete m_overlayWindow;
}
Ejemplo n.º 6
0
 ~GlxDrawable() {
     if (pbuffer) {
         glXDestroyPbuffer(display, drawable);
     } else {
         glXDestroyWindow(display, drawable);
         XDestroyWindow(display, window);
     }
 }
Ejemplo n.º 7
0
X11Win::~X11Win(void) {
	glXDestroyWindow(_d, _glxWin);
	glXMakeCurrent(_d, 0, 0);
	glXDestroyContext(_d, _ctx);
	XDestroyWindow(_d, _w);
	XFreeColormap(_d, _cmap);
	XCloseDisplay(_d);
}
Ejemplo n.º 8
0
void
ephyr_glamor_glx_screen_fini(struct ephyr_glamor *glamor)
{
    glXMakeCurrent(dpy, None, NULL);
    glXDestroyContext(dpy, glamor->ctx);
    glXDestroyWindow(dpy, glamor->glx_win);

    free(glamor);
}
Ejemplo n.º 9
0
static void gfx_ctx_destroy(void)
{
   if (g_dpy && g_ctx)
   {
      glXMakeContextCurrent(g_dpy, None, None, NULL);
      glXDestroyContext(g_dpy, g_ctx);
      g_ctx = NULL;
   }

   if (g_win)
   {
      glXDestroyWindow(g_dpy, g_glx_win);
      g_glx_win = 0;

      // Save last used monitor for later.
#ifdef HAVE_XINERAMA
      XWindowAttributes target;
      Window child;

      int x = 0, y = 0;
      XGetWindowAttributes(g_dpy, g_win, &target);
      XTranslateCoordinates(g_dpy, g_win, DefaultRootWindow(g_dpy),
            target.x, target.y, &x, &y, &child);

      g_screen = x11_get_xinerama_monitor(g_dpy, x, y,
            target.width, target.height);

      RARCH_LOG("[GLX]: Saved monitor #%u.\n", g_screen);
#endif

      XUnmapWindow(g_dpy, g_win);
      XDestroyWindow(g_dpy, g_win);
      g_win = None;
   }

   if (g_cmap)
   {
      XFreeColormap(g_dpy, g_cmap);
      g_cmap = None;
   }

   if (g_should_reset_mode)
   {
      x11_exit_fullscreen(g_dpy, &g_desktop_mode);
      g_should_reset_mode = false;
   }

   if (g_dpy)
   {
      XCloseDisplay(g_dpy);
      g_dpy = NULL;
   }

   g_inited = false;
   g_pglSwapInterval = NULL;
}
Ejemplo n.º 10
0
Archivo: glx.c Proyecto: 0xheart0/vlc
static void Close (vlc_object_t *obj)
{
    vlc_gl_t *gl = (vlc_gl_t *)obj;
    vlc_gl_sys_t *sys = gl->sys;
    Display *dpy = sys->display;

    glXDestroyContext (dpy, sys->ctx);
    glXDestroyWindow (dpy, sys->win);
    XCloseDisplay (dpy);
    free (sys);
}
Ejemplo n.º 11
0
void WindowImpl::close() {
	// TODO make this work better
	if (dpy != nullptr) {
		glXMakeContextCurrent(dpy, None, None, nullptr);
		glXDestroyContext(dpy, ctx);
		glXDestroyWindow(dpy, xWin);
		XDestroyWindow(dpy, win);
		XFreeColormap(dpy, cmap);
		XCloseDisplay(dpy);
		dpy = nullptr;
	}
}
Ejemplo n.º 12
0
static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx)
{
   if (!glx)
      return;

   x11_input_ctx_destroy();

   if (g_x11_dpy && glx->g_ctx)
   {

      glFinish();
      glXMakeContextCurrent(g_x11_dpy, None, None, NULL);

      if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL))
      {
         if (glx->g_hw_ctx)
            glXDestroyContext(g_x11_dpy, glx->g_hw_ctx);
         glXDestroyContext(g_x11_dpy, glx->g_ctx);
         glx->g_ctx = NULL;
         glx->g_hw_ctx = NULL;
      }
   }

   if (g_x11_win)
   {
      glXDestroyWindow(g_x11_dpy, glx->g_glx_win);
      glx->g_glx_win = 0;

      /* Save last used monitor for later. */
      x11_save_last_used_monitor(DefaultRootWindow(g_x11_dpy));
      x11_window_destroy(false);
   }

   x11_colormap_destroy();

   if (glx->g_should_reset_mode)
   {
      x11_exit_fullscreen(g_x11_dpy, &glx->g_desktop_mode);
      glx->g_should_reset_mode = false;
   }

   if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL) && g_x11_dpy)
   {
      XCloseDisplay(g_x11_dpy);
      g_x11_dpy = NULL;
   }

   g_pglSwapInterval = NULL;
   g_pglSwapIntervalSGI = NULL;
   g_pglSwapIntervalEXT = NULL;
   g_major = g_minor = 0;
   glx->g_core_es = false;
}
Ejemplo n.º 13
0
Archivo: common.c Proyecto: RAOF/piglit
void
GLX_ARB_create_context_teardown(void)
{
	if (glxWin != None) {
		glXDestroyWindow(dpy, glxWin);
		glxWin = None;
	}

	XFree(visinfo);
	visinfo = NULL;

	XSetErrorHandler(old_handler);
}
Ejemplo n.º 14
0
Archivo: glx.c Proyecto: forthyen/SDesk
/*****************************************************************************
 * DestroyOpenGL: destroys an OpenGL provider
 *****************************************************************************/
static void DestroyOpenGL( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;
    vout_sys_t *p_sys = p_vout->p_sys;

    glXDestroyContext( p_sys->p_display, p_sys->gwctx );
    if( p_sys->b_glx13 )
    {
        glXDestroyWindow( p_sys->p_display, p_sys->gwnd );
    }

    E_(Deactivate)( p_this );
}
Ejemplo n.º 15
0
void GraphicsContext::releaseGLSystem()
{
    glXMakeContextCurrent(m_display, None, None, NULL);

    if (m_context)
        glXDestroyContext(m_display, m_context);

    if (m_pbuffer)
        glXDestroyPbuffer(m_display, m_pbuffer);

    if (m_window)
        glXDestroyWindow(m_display, m_window);
}
Ejemplo n.º 16
0
// Destroy the OpenGL context
//
static void destroyContextGLX(_GLFWwindow* window)
{
    if (window->context.glx.window)
    {
        glXDestroyWindow(_glfw.x11.display, window->context.glx.window);
        window->context.glx.window = None;
    }

    if (window->context.glx.handle)
    {
        glXDestroyContext(_glfw.x11.display, window->context.glx.handle);
        window->context.glx.handle = NULL;
    }
}
Ejemplo n.º 17
0
void
window_impl_close(struct rtb_window *rwin)
{
    struct xrtb_window *self = RTB_WINDOW_AS(rwin, xrtb_window);

    glXMakeContextCurrent(self->xrtb->dpy, None, None, NULL);
    glXDestroyWindow(self->xrtb->dpy, self->gl_win);
    xcb_destroy_window(self->xrtb->xcb_conn, self->xcb_win);
    glXDestroyContext(self->xrtb->dpy, self->gl_ctx);

    uv_mutex_unlock(&self->lock);
    uv_mutex_destroy(&self->lock);

    free(self);
}
Ejemplo n.º 18
0
void GLWindow::destroy() {
    // hide window
    if (this->window != None) {
        XUnmapWindow(this->display, this->window);
    }

    // destroy opengl framebuffer
    if (this->glxWindow != None) {
        glXDestroyWindow(this->display, this->glxWindow);
        this->glxWindow = None;
    }

    // destroy window
    if (this->window != None) {
        XDestroyWindow(this->display, this->window);
        this->window = None;
    }

    // destroy colormap
    if (this->colormap != None) {
        XFreeColormap(this->display, this->colormap);
        this->colormap = None;
    }

    // destroy framebuffer configuration
    if (this->visualinfo != NULL) {
        XFree(this->visualinfo);
        this->visualinfo = NULL;
    }

    // destroy opengl context
    if (this->glxContext != NULL) {
        glXDestroyContext(this->display, this->glxContext);
        this->glxContext = NULL;
    }

    // free opengl framebuffer configurations
    if (this->glxConfigs != NULL) {
        XFree(this->glxConfigs);
        this->glxConfigs = NULL;
    }

    this->visible = false;
    this->x = this->y = 0;
    this->_width = this->_height = 0;
    this->mouse = false;
    this->mouseX = this->mouseY = 0;
}
Ejemplo n.º 19
0
void XvMCTextures::DeInit(void)
{
    VERBOSE(VB_IMPORTANT, LOC + "DeInit");
    if (!XJ_disp)
        return; // already called

    X11L;
    glXMakeContextCurrent(XJ_disp, None, None, NULL);
    glXDestroyContext(XJ_disp, glx_context); glx_context = 0;
    glXDestroyWindow( XJ_disp, glx_window);  glx_window  = 0;
    glXDestroyPbuffer(XJ_disp, glx_pbuffer); glx_pbuffer = 0;
    XDestroyWindow(   XJ_disp, gl_window);   gl_window   = 0;
    gl_vid_textures.clear();
    gl_osd_textures.clear();
    XJ_disp = NULL;
    X11U;
}
Ejemplo n.º 20
0
void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
{
	Display *display = swap->wi->display;
	struct gl_windowinfo *info = swap->wi;

	if (!info)
		return;

	if (info->glxid)
		glXDestroyWindow(display, info->glxid);

	if (info->int_id)
		XDestroyWindow(display, info->int_id);

	info->glxid = 0;
	info->int_id = 0;
}
Ejemplo n.º 21
0
void MFRenderer_DestroyDisplay(MFDisplay *pDisplay)
{
	if(gpDeviceRenderTarget)
		MFRenderTarget_Release(gpDeviceRenderTarget);

#if MF_DISPLAY == MF_DRIVER_X11
	if(fbConfigs != NULL)
	{
		XFree(fbConfigs);
		fbConfigs = NULL;
	}

	if(glXContext != NULL)
	{
		glXDestroyContext(xdisplay, glXContext);
		glXContext = NULL;
	}

	if(glXWindow != 0)
	{
		glXDestroyWindow(xdisplay, glXWindow);
		glXWindow = 0;
	}
#elif MF_DISPLAY == MF_DRIVER_WIN32
	HWND hWnd = (HWND)MFWindow_GetSystemWindowHandle(pDisplay->settings.pWindow);

	if(hRC)
	{
		if(wglMakeCurrent(NULL, NULL))
		{
			wglDeleteContext(hRC);
		}
		hRC = NULL;
	}

	if(hDC)
	{
		ReleaseDC(hWnd, hDC);
		hDC = NULL;
	}
#elif MF_DISPLAY == MF_DRIVER_SDL2
	SDL_GL_DeleteContext(glContext);
#endif
}
Ejemplo n.º 22
0
static void xdpy_destroy_display_hook_default(ALLEGRO_DISPLAY *d, bool is_last)
{
   ALLEGRO_SYSTEM_XGLX *s = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
   ALLEGRO_DISPLAY_XGLX *glx = (ALLEGRO_DISPLAY_XGLX *)d;
   (void)is_last;

   if (glx->context) {
      glXDestroyContext(s->gfxdisplay, glx->context);
      glx->context = NULL;
      ALLEGRO_DEBUG("destroy context.\n");
   }

   if (glx->fbc) {
      al_free(glx->fbc);
      glx->fbc = NULL;
      XFree(glx->xvinfo);
      glx->xvinfo = NULL;
   }
   else if (glx->xvinfo) {
      al_free(glx->xvinfo);
      glx->xvinfo = NULL;
   }

   if ((glx->glxwindow) && (glx->glxwindow != glx->window)) {
      glXDestroyWindow(s->x11display, glx->glxwindow);
      glx->glxwindow = 0;
      ALLEGRO_DEBUG("destroy glx window\n");
   }

   _al_cond_destroy(&glx->mapped);
   _al_cond_destroy(&glx->selectioned);

   ALLEGRO_DEBUG("destroy window.\n");
   XDestroyWindow(s->x11display, glx->window);

   _al_xglx_unuse_adapter(s, glx->adapter);

   if (d->flags & ALLEGRO_FULLSCREEN) {
      restore_mode_if_last_fullscreen_display(s, glx);
   }
}
Ejemplo n.º 23
0
DECLEXPORT(EGLBoolean) eglDestroySurface(EGLDisplay hDisplay, EGLSurface hSurface)
{
    Display *pDisplay = (Display *)hDisplay;

    if (!VALID_PTR(hDisplay))
        return setEGLError(EGL_NOT_INITIALIZED);
    switch ((GLXDrawable)hSurface & VBEGL_ANY_SURFACE)
    {
        case VBEGL_WINDOW_SURFACE:
            glXDestroyWindow(pDisplay, (GLXWindow)hSurface & ~VBEGL_WINDOW_SURFACE);
            return clearEGLError();
        case VBEGL_PBUFFER_SURFACE:
            glXDestroyPbuffer(pDisplay, (GLXPbuffer)hSurface & ~VBEGL_PBUFFER_SURFACE);
            return clearEGLError();
        case VBEGL_PIXMAP_SURFACE:
            glXDestroyPixmap(pDisplay, (GLXPixmap)hSurface & ~VBEGL_PIXMAP_SURFACE);
            return clearEGLError();
        default:
            return setEGLError(EGL_BAD_SURFACE);
    }
}
int
main(int argc, char **argv)
{
	XVisualInfo *visinfo;
	int i;

	for (i = 1; i < argc; ++i) {
		if (!strcmp(argv[i], "-auto"))
			piglit_automatic = 1;
		else
			fprintf(stderr, "Unknown option: %s\n", argv[i]);
	}

	dpy = XOpenDisplay(NULL);
	if (dpy == NULL) {
		fprintf(stderr, "couldn't open display\n");
		piglit_report_result(PIGLIT_FAIL);
	}
	visinfo = piglit_get_glx_visual(dpy);

	win = piglit_get_glx_window(dpy, visinfo);
	XMapWindow(dpy, win);

	for (i = 0; i < num_contexts; i++) {
		ctx[i] = piglit_get_glx_context(dpy, visinfo);
	}

	glXMakeCurrent(dpy, win, ctx[0]);
	piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);

	piglit_glx_event_loop(dpy, draw);

	XFree(visinfo);
	glXDestroyWindow(dpy, win);
	for (i = 0; i < num_contexts; i++) {
		glXDestroyContext(dpy, ctx[i]);
	}

	return 0;
}
Ejemplo n.º 25
0
GlxBackend::~GlxBackend()
{
    if (isFailed()) {
        m_overlayWindow->destroy();
    }
    // TODO: cleanup in error case
    // do cleanup after initBuffer()
    cleanupGL();
    checkGLError("Cleanup");
    doneCurrent();

    if (ctx)
        glXDestroyContext(display(), ctx);

    if (glxWindow)
        glXDestroyWindow(display(), glxWindow);

    if (window)
        XDestroyWindow(display(), window);

    overlayWindow()->destroy();
    delete m_overlayWindow;
}
Ejemplo n.º 26
0
static void
clutter_stage_glx_unrealize (ClutterStageWindow *stage_window)
{
  ClutterStageX11 *stage_x11 = CLUTTER_STAGE_X11 (stage_window);
  ClutterStageGLX *stage_glx = CLUTTER_STAGE_GLX (stage_window);
  ClutterBackendX11 *backend_x11 = stage_x11->backend;

  /* Note unrealize should free up any backend stage related resources */
  CLUTTER_NOTE (BACKEND, "Unrealizing GLX stage [%p]", stage_glx);

  clutter_x11_trap_x_errors ();

  if (stage_glx->glxwin != None)
    {
      glXDestroyWindow (backend_x11->xdpy, stage_glx->glxwin);
      stage_glx->glxwin = None;
    }

  _clutter_stage_x11_destroy_window_untrapped (stage_x11);

  XSync (backend_x11->xdpy, False);

  clutter_x11_untrap_x_errors ();
}
Ejemplo n.º 27
0
int setup_and_run(Display *display, xcb_connection_t *connection, int default_screen, xcb_screen_t *screen)
{
    int visualID = 0;

    /*Query framebuffer configurations */
    GLXFBConfig *fb_configs = 0;
    int num_fb_configs = 0;
    fb_configs = glXGetFBConfigs(display, default_screen, &num_fb_configs);
    if (!fb_configs || num_fb_configs == 0)
    {
        fprintf(stderr, "glXGetFBConfigs failed\n");
        return -1;
    }

    /* Select first framebuffer config and query visualID */
    GLXFBConfig fb_config = fb_configs[0];
    glXGetFBConfigAttrib(display, fb_config, GLX_VISUAL_ID, &visualID);

    GLXContext context;

    /* Create OpenGL context */
    context = glXCreateNewContext(display, fb_config, GLX_RGBA_TYPE, 0, True);
    if (!context)
    {
        fprintf(stderr, "glXCreateNewContext failed\n");
        return -1;
    }

    /* Create XID's for colormap and window */
    xcb_colormap_t colormap = xcb_generate_id(connection);
    xcb_window_t window  = xcb_generate_id(connection);

    /* Create colormap */
    xcb_create_colormap(
        connection,
        XCB_COLORMAP_ALLOC_NONE,
        colormap,
        screen->root,
        visualID);

    /* Create window */
    uint32_t eventmask = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
    uint32_t valuelist[] = {eventmask, colormap, 0};
    uint32_t valuemask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;

    xcb_create_window(
        connection,
        XCB_COPY_FROM_PARENT,
        window,
        screen->root,
        0, 0,
        window_width, window_height,
        0,
        XCB_WINDOW_CLASS_INPUT_OUTPUT,
        visualID,
        valuemask,
        valuelist);

    /* NOTE: window must be mapped before glXMakeContextCurrent */
    xcb_map_window(connection, window);

    /* Create GLX window */
    GLXDrawable drawable = 0;
    GLXWindow glxwindow = glXCreateWindow(display, fb_config, window, 0);
    if (!glxwindow)
    {
        xcb_destroy_window(connection, window);
        glXDestroyContext(display, context);
        fprintf(stderr, "glXCreateWindow failed\n");
        return -1;
    }

    drawable = glxwindow;

    /* make OpenGL context current */
    #if 1
    if (!glXMakeContextCurrent(display, drawable, drawable, context))
    {
        xcb_destroy_window(connection, window);
        glXDestroyContext(display, context);
        fprintf(stderr, "glXMakeContextCurrent failed\n");
        return -1;
    }
    #else
    if (!glXMakeCurrent(display, drawable, context))
    {
        xcb_destroy_window(connection, window);
        glXDestroyContext(display, context);
        fprintf(stderr, "glXMakeContextCurrent failed\n");
        return -1;
    }
    #endif

    /* run main loop */
    int retval = main_loop (display, connection, screen, window, drawable);

    /* Cleanup */
    glXDestroyWindow(display, glxwindow);
    xcb_destroy_window(connection, window);
    glXDestroyContext(display, context);
    return retval;
}
Ejemplo n.º 28
0
static void gfx_ctx_x_destroy_resources(gfx_ctx_x_data_t *x)
{
   x11_input_ctx_destroy();

   if (g_x11_dpy)
   {
      switch (x_api)
      {
         case GFX_CTX_OPENGL_API:
         case GFX_CTX_OPENGL_ES_API:
#ifdef HAVE_OPENGL
            if (x->g_ctx)
            {
               glFinish();
               glXMakeContextCurrent(g_x11_dpy, None, None, NULL);

               if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL))
               {
                  if (x->g_hw_ctx)
                     glXDestroyContext(g_x11_dpy, x->g_hw_ctx);
                  if (x->g_ctx)
                     glXDestroyContext(g_x11_dpy, x->g_ctx);

                  x->g_ctx    = NULL;
                  x->g_hw_ctx = NULL;
               }
            }
            
            if (g_x11_win)
            {
               if (x->g_glx_win)
                  glXDestroyWindow(g_x11_dpy, x->g_glx_win);
               x->g_glx_win = 0;
            }
#endif
            break;

         case GFX_CTX_VULKAN_API:
#ifdef HAVE_VULKAN
            vulkan_context_destroy(&x->vk, g_x11_win != 0);
#endif
            break;

         case GFX_CTX_NONE:
         default:
            break;
      }
   }

   if (g_x11_win)
   {
      /* Save last used monitor for later. */
      x11_save_last_used_monitor(DefaultRootWindow(g_x11_dpy));
      x11_window_destroy(false);
   }

   x11_colormap_destroy();

   if (x->g_should_reset_mode)
   {
      x11_exit_fullscreen(g_x11_dpy, &x->g_desktop_mode);
      x->g_should_reset_mode = false;
   }

   if (!video_driver_ctl(RARCH_DISPLAY_CTL_IS_VIDEO_CACHE_CONTEXT, NULL) 
         && g_x11_dpy)
   {
      XCloseDisplay(g_x11_dpy);
      g_x11_dpy = NULL;
   }

   g_pglSwapInterval    = NULL;
   g_pglSwapIntervalSGI = NULL;
#ifdef HAVE_OPENGL
   g_pglSwapIntervalEXT = NULL;
#endif
   g_major              = 0;
   g_minor              = 0;
   x->g_core_es         = false;
}
Ejemplo n.º 29
0
Archivo: glx.c Proyecto: 0xheart0/vlc
static int Open (vlc_object_t *obj)
{
    vlc_gl_t *gl = (vlc_gl_t *)obj;

    if (gl->surface->type != VOUT_WINDOW_TYPE_XID || !vlc_xlib_init (obj))
        return VLC_EGENERIC;

    /* Initialize GLX display */
    Display *dpy = XOpenDisplay (gl->surface->display.x11);
    if (dpy == NULL)
        return VLC_EGENERIC;

    vlc_gl_sys_t *sys = malloc (sizeof (*sys));
    if (unlikely(sys == NULL))
    {
        XCloseDisplay (dpy);
        return VLC_ENOMEM;
    }
    gl->sys = sys;
    sys->display = dpy;

    if (!CheckGLX (obj, dpy))
        goto error;

    /* Determine our pixel format */
    XWindowAttributes wa;
    if (!XGetWindowAttributes (dpy, gl->surface->handle.xid, &wa))
        goto error;

    const int snum = XScreenNumberOfScreen (wa.screen);
    const VisualID visual = XVisualIDFromVisual (wa.visual);
    static const int attr[] = {
        GLX_RED_SIZE, 5,
        GLX_GREEN_SIZE, 5,
        GLX_BLUE_SIZE, 5,
        GLX_DOUBLEBUFFER, True,
        GLX_X_RENDERABLE, True,
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        None
    };

    int nelem;
    GLXFBConfig *confs = glXChooseFBConfig (dpy, snum, attr, &nelem);
    if (confs == NULL)
    {
        msg_Err (obj, "cannot choose GLX frame buffer configurations");
        goto error;
    }

    GLXFBConfig conf;
    bool found = false;
    for (int i = 0; i < nelem && !found; i++)
    {
        conf = confs[i];

        XVisualInfo *vi = glXGetVisualFromFBConfig (dpy, conf);
        if (vi == NULL)
            continue;

        if (vi->visualid == visual)
            found = true;
        XFree (vi);
    }
    XFree (confs);

    if (!found)
    {
        msg_Err (obj, "cannot match GLX frame buffer configuration");
        goto error;
    }

    /* Create a drawing surface */
    sys->win = glXCreateWindow (dpy, conf, gl->surface->handle.xid, NULL);
    if (sys->win == None)
    {
        msg_Err (obj, "cannot create GLX window");
        goto error;
    }

    /* Create an OpenGL context */
    sys->ctx = glXCreateNewContext (dpy, conf, GLX_RGBA_TYPE, NULL, True);
    if (sys->ctx == NULL)
    {
        glXDestroyWindow (dpy, sys->win);
        msg_Err (obj, "cannot create GLX context");
        goto error;
    }

    /* Initialize OpenGL callbacks */
    gl->sys = sys;
    gl->makeCurrent = MakeCurrent;
    gl->releaseCurrent = ReleaseCurrent;
    gl->resize = NULL;
    gl->swap = SwapBuffers;
    gl->getProcAddress = GetSymbol;

#ifdef GLX_ARB_get_proc_address
    bool is_swap_interval_set = false;

    MakeCurrent (gl);
# ifdef GLX_SGI_swap_control
    if (!is_swap_interval_set
     && CheckGLXext (dpy, snum, "GLX_SGI_swap_control"))
    {
        PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
            glXGetProcAddressARB ((const GLubyte *)"glXSwapIntervalSGI");
        assert (SwapIntervalSGI != NULL);
        is_swap_interval_set = !SwapIntervalSGI (1);
    }
# endif
# ifdef GLX_EXT_swap_control
    if (!is_swap_interval_set
     && CheckGLXext (dpy, snum, "GLX_EXT_swap_control"))
    {
        PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
            glXGetProcAddress ((const GLubyte *)"glXSwapIntervalEXT");
        assert (SwapIntervalEXT != NULL);
        SwapIntervalEXT (dpy, sys->win, 1);
        is_swap_interval_set = true;
    }
# endif
    ReleaseCurrent (gl);
#endif

    return VLC_SUCCESS;

error:
    XCloseDisplay (dpy);
    free (sys);
    return VLC_EGENERIC;
}
Ejemplo n.º 30
0
static void ctx_glx_destroy_resources(gfx_ctx_glx_data_t *glx)
{
   driver_t *driver = driver_get_ptr();

   if (!glx)
      return;

   x11_destroy_input_context(&glx->g_xim, &glx->g_xic);

   if (glx->g_dpy && glx->g_ctx)
   {

      glFinish();
      glXMakeContextCurrent(glx->g_dpy, None, None, NULL);

      if (!driver->video_cache_context)
      {
         if (glx->g_hw_ctx)
            glXDestroyContext(glx->g_dpy, glx->g_hw_ctx);
         glXDestroyContext(glx->g_dpy, glx->g_ctx);
         glx->g_ctx = NULL;
         glx->g_hw_ctx = NULL;
      }
   }

   if (glx->g_win)
   {
      glXDestroyWindow(glx->g_dpy, glx->g_glx_win);
      glx->g_glx_win = 0;

      /* Save last used monitor for later. */
#ifdef HAVE_XINERAMA
      XWindowAttributes target;
      Window child;

      int x = 0, y = 0;
      XGetWindowAttributes(glx->g_dpy, glx->g_win, &target);
      XTranslateCoordinates(glx->g_dpy, glx->g_win, DefaultRootWindow(glx->g_dpy),
            target.x, target.y, &x, &y, &child);

      glx->g_screen = x11_get_xinerama_monitor(glx->g_dpy, x, y,
            target.width, target.height);

      RARCH_LOG("[GLX]: Saved monitor #%u.\n", glx->g_screen);
#endif

      XUnmapWindow(glx->g_dpy, glx->g_win);
      XDestroyWindow(glx->g_dpy, glx->g_win);
      glx->g_win = None;
   }

   if (glx->g_cmap)
   {
      XFreeColormap(glx->g_dpy, glx->g_cmap);
      glx->g_cmap = None;
   }

   if (glx->g_should_reset_mode)
   {
      x11_exit_fullscreen(glx->g_dpy, &glx->g_desktop_mode);
      glx->g_should_reset_mode = false;
   }

   if (!driver->video_cache_context && glx->g_dpy)
   {
      XCloseDisplay(glx->g_dpy);
      glx->g_dpy = NULL;
   }

   g_pglSwapInterval = NULL;
   g_pglSwapIntervalSGI = NULL;
   g_pglSwapIntervalEXT = NULL;
   g_major = g_minor = 0;
   glx->g_core_es = false;
}