x11: make the X11 target work on macOS with Xquartz.

Ryan C. Gordon 2017-01-07 19:55:29 -05:00
parent 61a3ba303c
commit 13f2e54295
2 changed files with 67 additions and 38 deletions

View File

@ -202,7 +202,7 @@ ShouldUseTextureFramebuffer()
return SDL_FALSE; return SDL_FALSE;
#elif defined(__MACOSX__) #elif defined(__MACOSX__)
/* Mac OS X uses OpenGL as the native fast path */ /* Mac OS X uses OpenGL as the native fast path (for cocoa and X11) */
return SDL_TRUE; return SDL_TRUE;
#elif defined(__LINUX__) #elif defined(__LINUX__)
@ -1177,6 +1177,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
/* if the window is going away and no resolution change is necessary, /* if the window is going away and no resolution change is necessary,
do nothing, or else we may trigger an ugly double-transition do nothing, or else we may trigger an ugly double-transition
*/ */
if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP) if (window->is_destroying && (window->last_fullscreen_flags & FULLSCREEN_MASK) == SDL_WINDOW_FULLSCREEN_DESKTOP)
return 0; return 0;
@ -1202,6 +1203,7 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
return 0; return 0;
} }
} }
}
#elif __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10) #elif __WINRT__ && (NTDDI_VERSION < NTDDI_WIN10)
/* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen /* HACK: WinRT 8.x apps can't choose whether or not they are fullscreen
or not. The user can choose this, via OS-provided UI, but this can't or not. The user can choose this, via OS-provided UI, but this can't
@ -2521,9 +2523,11 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window)
} }
#ifdef __MACOSX__ #ifdef __MACOSX__
if (SDL_strcmp(_this->name, "cocoa") == 0) { /* don't do this for X11, etc */
if (Cocoa_IsWindowInFullscreenSpace(window)) { if (Cocoa_IsWindowInFullscreenSpace(window)) {
return SDL_FALSE; return SDL_FALSE;
} }
}
#endif #endif
return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE); return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_TRUE);

View File

@ -391,12 +391,17 @@ X11_GL_InitExtensions(_THIS)
/* glXChooseVisual and glXChooseFBConfig have some small differences in /* glXChooseVisual and glXChooseFBConfig have some small differences in
* the attribute encoding, it can be chosen with the for_FBConfig parameter. * the attribute encoding, it can be chosen with the for_FBConfig parameter.
* Some targets fail if you use GLX_X_VISUAL_TYPE_EXT/GLX_DIRECT_COLOR_EXT,
* so it gets specified last if used and is pointed to by *_pvistypeattr.
* In case of failure, if that pointer is not NULL, set that pointer to None
* and try again.
*/ */
static int static int
X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int size, Bool for_FBConfig) X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int size, Bool for_FBConfig, int **_pvistypeattr)
{ {
int i = 0; int i = 0;
const int MAX_ATTRIBUTES = 64; const int MAX_ATTRIBUTES = 64;
int *pvistypeattr = NULL;
/* assert buffer is large enough to hold all SDL attributes. */ /* assert buffer is large enough to hold all SDL attributes. */
SDL_assert(size >= MAX_ATTRIBUTES); SDL_assert(size >= MAX_ATTRIBUTES);
@ -488,6 +493,7 @@ X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int si
EXT_visual_info extension, then add GLX_X_VISUAL_TYPE_EXT. */ EXT_visual_info extension, then add GLX_X_VISUAL_TYPE_EXT. */
if (X11_UseDirectColorVisuals() && if (X11_UseDirectColorVisuals() &&
_this->gl_data->HAS_GLX_EXT_visual_info) { _this->gl_data->HAS_GLX_EXT_visual_info) {
pvistypeattr = &attribs[i];
attribs[i++] = GLX_X_VISUAL_TYPE_EXT; attribs[i++] = GLX_X_VISUAL_TYPE_EXT;
attribs[i++] = GLX_DIRECT_COLOR_EXT; attribs[i++] = GLX_DIRECT_COLOR_EXT;
} }
@ -496,6 +502,10 @@ X11_GL_GetAttributes(_THIS, Display * display, int screen, int * attribs, int si
SDL_assert(i <= MAX_ATTRIBUTES); SDL_assert(i <= MAX_ATTRIBUTES);
if (_pvistypeattr) {
*_pvistypeattr = pvistypeattr;
}
return i; return i;
} }
@ -505,14 +515,21 @@ X11_GL_GetVisual(_THIS, Display * display, int screen)
/* 64 seems nice. */ /* 64 seems nice. */
int attribs[64]; int attribs[64];
XVisualInfo *vinfo; XVisualInfo *vinfo;
int *pvistypeattr = NULL;
if (!_this->gl_data) { if (!_this->gl_data) {
/* The OpenGL library wasn't loaded, SDL_GetError() should have info */ /* The OpenGL library wasn't loaded, SDL_GetError() should have info */
return NULL; return NULL;
} }
X11_GL_GetAttributes(_this, display, screen, attribs, 64, SDL_FALSE); X11_GL_GetAttributes(_this, display, screen, attribs, 64, SDL_FALSE, &pvistypeattr);
vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs); vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
if (!vinfo && (pvistypeattr != NULL)) {
*pvistypeattr = None;
vinfo = _this->gl_data->glXChooseVisual(display, screen, attribs);
}
if (!vinfo) { if (!vinfo) {
SDL_SetError("Couldn't find matching GLX visual"); SDL_SetError("Couldn't find matching GLX visual");
} }
@ -626,16 +643,23 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
/* Create a GL 3.x context */ /* Create a GL 3.x context */
GLXFBConfig *framebuffer_config = NULL; GLXFBConfig *framebuffer_config = NULL;
int fbcount = 0; int fbcount = 0;
int *pvistypeattr = NULL;
X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE); X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE,&pvistypeattr);
if (!_this->gl_data->glXChooseFBConfig if (_this->gl_data->glXChooseFBConfig) {
|| !(framebuffer_config = framebuffer_config = _this->gl_data->glXChooseFBConfig(display,
_this->gl_data->glXChooseFBConfig(display,
DefaultScreen(display), glxAttribs, DefaultScreen(display), glxAttribs,
&fbcount))) { &fbcount);
SDL_SetError("No good framebuffers found. OpenGL 3.0 and later unavailable");
} else { if (!framebuffer_config && (pvistypeattr != NULL)) {
*pvistypeattr = None;
framebuffer_config = _this->gl_data->glXChooseFBConfig(display,
DefaultScreen(display), glxAttribs,
&fbcount);
}
if (framebuffer_config) {
context = _this->gl_data->glXCreateContextAttribsARB(display, context = _this->gl_data->glXCreateContextAttribsARB(display,
framebuffer_config[0], framebuffer_config[0],
share_context, True, attribs); share_context, True, attribs);
@ -643,6 +667,7 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
} }
} }
} }
}
X11_XFree(vinfo); X11_XFree(vinfo);
} }
X11_XSync(display, False); X11_XSync(display, False);