Avoid including X11 headers from <wx/glcanvas.h>

It's generally wxWidgets policy not to include platform-specific headers from our own
to avoid namespace pollution issues, in this case with names like "None" and "Window".
This commit is contained in:
Paul Cornett
2019-08-28 09:37:49 -07:00
parent 20b9964007
commit df450566dd
9 changed files with 74 additions and 93 deletions

View File

@@ -63,7 +63,7 @@ public:
// implement wxGLCanvasX11 methods // implement wxGLCanvasX11 methods
// -------------------------------- // --------------------------------
virtual Window GetXWindow() const wxOVERRIDE; virtual unsigned long GetXWindow() const wxOVERRIDE;
// deprecated methods // deprecated methods

View File

@@ -61,7 +61,7 @@ public:
// implement wxGLCanvasX11 methods // implement wxGLCanvasX11 methods
// ------------------------------- // -------------------------------
virtual Window GetXWindow() const; virtual unsigned long GetXWindow() const;
// deprecated methods // deprecated methods

View File

@@ -10,10 +10,10 @@
#ifndef _WX_UNIX_GLX11_H_ #ifndef _WX_UNIX_GLX11_H_
#define _WX_UNIX_GLX11_H_ #define _WX_UNIX_GLX11_H_
#include <GL/glx.h> #include <GL/gl.h>
class wxGLContextAttrs; typedef struct __GLXcontextRec* GLXContext;
class wxGLAttributes; typedef struct __GLXFBConfigRec* GLXFBConfig;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGLContext // wxGLContext
@@ -30,9 +30,6 @@ public:
virtual bool SetCurrent(const wxGLCanvas& win) const wxOVERRIDE; virtual bool SetCurrent(const wxGLCanvas& win) const wxOVERRIDE;
private: private:
// attach context to the drawable or unset it (if NULL)
static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
GLXContext m_glContext; GLXContext m_glContext;
wxDECLARE_CLASS(wxGLContext); wxDECLARE_CLASS(wxGLContext);
@@ -74,7 +71,7 @@ public:
static bool IsGLXMultiSampleAvailable(); static bool IsGLXMultiSampleAvailable();
// get the X11 handle of this window // get the X11 handle of this window
virtual Window GetXWindow() const = 0; virtual unsigned long GetXWindow() const = 0;
// GLX-specific methods // GLX-specific methods
@@ -93,36 +90,15 @@ public:
// get the GLXFBConfig/XVisualInfo we use // get the GLXFBConfig/XVisualInfo we use
GLXFBConfig *GetGLXFBConfig() const { return m_fbc; } GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
XVisualInfo *GetXVisualInfo() const { return m_vi; } void* GetXVisualInfo() const { return m_vi; }
// initialize the global default GL visual, return false if matching visual // initialize the global default GL visual, return false if matching visual
// not found // not found
static bool InitDefaultVisualInfo(const int *attribList); static bool InitDefaultVisualInfo(const int *attribList);
// get the default GL X11 visual (may be NULL, shouldn't be freed by caller)
static XVisualInfo *GetDefaultXVisualInfo() { return ms_glVisualInfo; }
// free the global GL visual, called by wxGLApp
static void FreeDefaultVisualInfo();
// initializes XVisualInfo (in any case) and, if supported, GLXFBConfig
//
// returns false if XVisualInfo couldn't be initialized, otherwise caller
// is responsible for freeing the pointers
static bool InitXVisualInfo(const wxGLAttributes& dispAttrs,
GLXFBConfig **pFBC, XVisualInfo **pXVisual);
private: private:
// this is only used if it's supported i.e. if GL >= 1.3
GLXFBConfig *m_fbc; GLXFBConfig *m_fbc;
void* m_vi;
// used for all GL versions, obtained from GLXFBConfig for GL >= 1.3
XVisualInfo *m_vi;
// the global/default versions of the above
static GLXFBConfig *ms_glFBCInfo;
static XVisualInfo *ms_glVisualInfo;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -135,29 +111,15 @@ private:
class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
{ {
public: public:
wxGLApp() : wxGLAppBase() { } virtual bool InitGLVisual(const int *attribList) wxOVERRIDE;
// implement wxGLAppBase method
virtual bool InitGLVisual(const int *attribList) wxOVERRIDE
{
return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
}
// This method is not currently used by the library itself, but remains for // This method is not currently used by the library itself, but remains for
// backwards compatibility and also because wxGTK has it we could start // backwards compatibility and also because wxGTK has it we could start
// using it for the same purpose in wxX11 too some day. // using it for the same purpose in wxX11 too some day.
virtual void* GetXVisualInfo() wxOVERRIDE virtual void* GetXVisualInfo() wxOVERRIDE;
{
return wxGLCanvasX11::GetDefaultXVisualInfo();
}
// and override this wxApp method to clean up // and override this wxApp method to clean up
virtual int OnExit() wxOVERRIDE virtual int OnExit() wxOVERRIDE;
{
wxGLCanvasX11::FreeDefaultVisualInfo();
return wxGLAppBase::OnExit();
}
private: private:
wxDECLARE_DYNAMIC_CLASS(wxGLApp); wxDECLARE_DYNAMIC_CLASS(wxGLApp);

View File

@@ -57,7 +57,7 @@ public:
// implement wxGLCanvasX11 methods // implement wxGLCanvasX11 methods
// -------------------------------- // --------------------------------
virtual Window GetXWindow() const; virtual unsigned long GetXWindow() const;
protected: protected:
virtual int GetColourIndex(const wxColour& col); virtual int GetColourIndex(const wxColour& col);

View File

@@ -118,11 +118,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
{ WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1, { WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1, WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
WX_GL_DOUBLEBUFFER, WX_GL_DOUBLEBUFFER,
# if defined(__WXMAC__) || defined(__WXQT__) 0 };
GL_NONE };
# else
None };
# endif
#endif #endif
if (!g_doubleBuffer) if (!g_doubleBuffer)
@@ -130,7 +126,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos,
wxLogWarning("Disabling double buffering"); wxLogWarning("Disabling double buffering");
#ifdef __WXGTK__ #ifdef __WXGTK__
gl_attrib[9] = None; gl_attrib[9] = 0;
#endif #endif
g_doubleBuffer = GL_FALSE; g_doubleBuffer = GL_FALSE;
} }

View File

@@ -50,7 +50,7 @@ parent_set_hook(GSignalInvocationHint*, guint, const GValue* param_values, void*
wxGLCanvas* win = (wxGLCanvas*)data; wxGLCanvas* win = (wxGLCanvas*)data;
if (g_value_peek_pointer(&param_values[0]) == win->m_wxwindow) if (g_value_peek_pointer(&param_values[0]) == win->m_wxwindow)
{ {
const XVisualInfo* xvi = win->GetXVisualInfo(); const XVisualInfo* xvi = static_cast<XVisualInfo*>(win->GetXVisualInfo());
GdkVisual* visual = gtk_widget_get_visual(win->m_wxwindow); GdkVisual* visual = gtk_widget_get_visual(win->m_wxwindow);
if (GDK_VISUAL_XVISUAL(visual)->visualid != xvi->visualid) if (GDK_VISUAL_XVISUAL(visual)->visualid != xvi->visualid)
{ {
@@ -239,7 +239,7 @@ bool wxGLCanvas::SetBackgroundStyle(wxBackgroundStyle /* style */)
return false; return false;
} }
Window wxGLCanvas::GetXWindow() const unsigned long wxGLCanvas::GetXWindow() const
{ {
GdkWindow* window = GTKGetDrawingWindow(); GdkWindow* window = GTKGetDrawingWindow();
return window ? GDK_WINDOW_XID(window) : 0; return window ? GDK_WINDOW_XID(window) : 0;

View File

@@ -246,7 +246,7 @@ bool wxGLCanvas::Create(wxWindow *parent,
if ( !InitVisual(dispAttrs) ) if ( !InitVisual(dispAttrs) )
return false; return false;
GdkVisual *visual = gdkx_visual_get( GetXVisualInfo()->visualid ); GdkVisual *visual = gdkx_visual_get(static_cast<XVisualInfo*>(GetXVisualInfo())->visualid);
GdkColormap *colormap = gdk_colormap_new( visual, TRUE ); GdkColormap *colormap = gdk_colormap_new( visual, TRUE );
gtk_widget_push_colormap( colormap ); gtk_widget_push_colormap( colormap );
@@ -292,7 +292,7 @@ bool wxGLCanvas::Create(wxWindow *parent,
return true; return true;
} }
Window wxGLCanvas::GetXWindow() const unsigned long wxGLCanvas::GetXWindow() const
{ {
GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window; GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window;
return window ? GDK_WINDOW_XWINDOW(window) : 0; return window ? GDK_WINDOW_XWINDOW(window) : 0;

View File

@@ -25,6 +25,7 @@
#endif //WX_PRECOMP #endif //WX_PRECOMP
#include "wx/glcanvas.h" #include "wx/glcanvas.h"
#include <GL/glx.h>
// IRIX headers call this differently // IRIX headers call this differently
#ifdef __SGI__ #ifdef __SGI__
@@ -446,6 +447,8 @@ void wxGLAttributes::AddDefaultsForWXBefore31()
// wxGLContext implementation // wxGLContext implementation
// ============================================================================ // ============================================================================
static bool MakeCurrent(GLXDrawable drawable, GLXContext context);
// Need this X error handler for the case context creation fails // Need this X error handler for the case context creation fails
static bool g_ctxErrorOccurred = false; static bool g_ctxErrorOccurred = false;
static int CTXErrorHandler( Display* WXUNUSED(dpy), XErrorEvent* WXUNUSED(ev) ) static int CTXErrorHandler( Display* WXUNUSED(dpy), XErrorEvent* WXUNUSED(ev) )
@@ -486,7 +489,7 @@ wxGLContext::wxGLContext(wxGLCanvas *win,
m_isOk = false; m_isOk = false;
Display* dpy = wxGetX11Display(); Display* dpy = wxGetX11Display();
XVisualInfo *vi = win->GetXVisualInfo(); XVisualInfo* vi = static_cast<XVisualInfo*>(win->GetXVisualInfo());
wxCHECK_RET( vi, "invalid visual for OpenGL" ); wxCHECK_RET( vi, "invalid visual for OpenGL" );
// We need to create a temporary context to get the // We need to create a temporary context to get the
@@ -585,8 +588,7 @@ bool wxGLContext::SetCurrent(const wxGLCanvas& win) const
// wrapper around glXMakeContextCurrent/glXMakeCurrent depending on GLX // wrapper around glXMakeContextCurrent/glXMakeCurrent depending on GLX
// version // version
/* static */ static bool MakeCurrent(GLXDrawable drawable, GLXContext context)
bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context)
{ {
if (wxGLCanvas::GetGLXVersion() >= 13) if (wxGLCanvas::GetGLXVersion() >= 13)
return glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context); return glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context);
@@ -598,6 +600,12 @@ bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context)
// wxGLCanvasX11 implementation // wxGLCanvasX11 implementation
// ============================================================================ // ============================================================================
static GLXFBConfig* gs_glFBCInfo;
static XVisualInfo* gs_glVisualInfo;
static bool InitXVisualInfo(
const wxGLAttributes& dispAttrs, GLXFBConfig** pFBC, XVisualInfo** pXVisual);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// initialization methods and dtor // initialization methods and dtor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -610,7 +618,9 @@ wxGLCanvasX11::wxGLCanvasX11()
bool wxGLCanvasX11::InitVisual(const wxGLAttributes& dispAttrs) bool wxGLCanvasX11::InitVisual(const wxGLAttributes& dispAttrs)
{ {
bool ret = InitXVisualInfo(dispAttrs, &m_fbc, &m_vi); XVisualInfo* vi = NULL;
bool ret = InitXVisualInfo(dispAttrs, &m_fbc, &vi);
m_vi = vi;
if ( !ret ) if ( !ret )
{ {
wxFAIL_MSG("Failed to get a XVisualInfo for the requested attributes."); wxFAIL_MSG("Failed to get a XVisualInfo for the requested attributes.");
@@ -620,10 +630,10 @@ bool wxGLCanvasX11::InitVisual(const wxGLAttributes& dispAttrs)
wxGLCanvasX11::~wxGLCanvasX11() wxGLCanvasX11::~wxGLCanvasX11()
{ {
if ( m_fbc && m_fbc != ms_glFBCInfo ) if (m_fbc && m_fbc != gs_glFBCInfo)
XFree(m_fbc); XFree(m_fbc);
if ( m_vi && m_vi != ms_glVisualInfo ) if (m_vi && m_vi != gs_glVisualInfo)
XFree(m_vi); XFree(m_vi);
} }
@@ -651,9 +661,7 @@ bool wxGLCanvasX11::IsGLXMultiSampleAvailable()
return s_isMultiSampleAvailable != 0; return s_isMultiSampleAvailable != 0;
} }
static bool InitXVisualInfo(const wxGLAttributes& dispAttrs,
/* static */
bool wxGLCanvasX11::InitXVisualInfo(const wxGLAttributes& dispAttrs,
GLXFBConfig** pFBC, GLXFBConfig** pFBC,
XVisualInfo** pXVisual) XVisualInfo** pXVisual)
{ {
@@ -667,7 +675,7 @@ bool wxGLCanvasX11::InitXVisualInfo(const wxGLAttributes& dispAttrs,
Display* dpy = wxGetX11Display(); Display* dpy = wxGetX11Display();
if ( GetGLXVersion() >= 13 ) if (wxGLCanvasX11::GetGLXVersion() >= 13)
{ {
int returned; int returned;
*pFBC = glXChooseFBConfig(dpy, DefaultScreen(dpy), attrsListGLX, &returned); *pFBC = glXChooseFBConfig(dpy, DefaultScreen(dpy), attrsListGLX, &returned);
@@ -699,7 +707,7 @@ bool wxGLCanvasBase::IsDisplaySupported(const wxGLAttributes& dispAttrs)
GLXFBConfig *fbc = NULL; GLXFBConfig *fbc = NULL;
XVisualInfo *vi = NULL; XVisualInfo *vi = NULL;
bool isSupported = wxGLCanvasX11::InitXVisualInfo(dispAttrs, &fbc, &vi); bool isSupported = InitXVisualInfo(dispAttrs, &fbc, &vi);
if ( fbc ) if ( fbc )
XFree(fbc); XFree(fbc);
@@ -722,8 +730,19 @@ bool wxGLCanvasBase::IsDisplaySupported(const int *attribList)
// default visual management // default visual management
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
XVisualInfo *wxGLCanvasX11::ms_glVisualInfo = NULL; static void FreeDefaultVisualInfo()
GLXFBConfig *wxGLCanvasX11::ms_glFBCInfo = NULL; {
if (gs_glFBCInfo)
{
XFree(gs_glFBCInfo);
gs_glFBCInfo = NULL;
}
if (gs_glVisualInfo)
{
XFree(gs_glVisualInfo);
gs_glVisualInfo = NULL;
}
}
/* static */ /* static */
bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList) bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList)
@@ -732,23 +751,7 @@ bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList)
wxGLAttributes dispAttrs; wxGLAttributes dispAttrs;
ParseAttribList(attribList, dispAttrs); ParseAttribList(attribList, dispAttrs);
return InitXVisualInfo(dispAttrs, &ms_glFBCInfo, &ms_glVisualInfo); return InitXVisualInfo(dispAttrs, &gs_glFBCInfo, &gs_glVisualInfo);
}
/* static */
void wxGLCanvasX11::FreeDefaultVisualInfo()
{
if ( ms_glFBCInfo )
{
XFree(ms_glFBCInfo);
ms_glFBCInfo = NULL;
}
if ( ms_glVisualInfo )
{
XFree(ms_glVisualInfo);
ms_glVisualInfo = NULL;
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -788,5 +791,25 @@ bool wxGLCanvasX11::IsShownOnScreen() const
return GetXWindow() && wxGLCanvasBase::IsShownOnScreen(); return GetXWindow() && wxGLCanvasBase::IsShownOnScreen();
} }
#endif // wxUSE_GLCANVAS // ----------------------------------------------------------------------------
// wxGLApp
// ----------------------------------------------------------------------------
bool wxGLApp::InitGLVisual(const int* attribList)
{
return wxGLCanvasX11::InitDefaultVisualInfo(attribList);
}
void* wxGLApp::GetXVisualInfo()
{
return gs_glVisualInfo;
}
int wxGLApp::OnExit()
{
FreeDefaultVisualInfo();
return wxGLAppBase::OnExit();
}
#endif // wxUSE_GLCANVAS

View File

@@ -101,9 +101,9 @@ bool wxGLCanvas::Create(wxWindow *parent,
return true; return true;
} }
Window wxGLCanvas::GetXWindow() const unsigned long wxGLCanvas::GetXWindow() const
{ {
return (Window) return (unsigned long)
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
GetClientXWindow(); GetClientXWindow();
#else #else