From df450566ddb614f2add0affc9aee20ce7688d56a Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Wed, 28 Aug 2019 09:37:49 -0700 Subject: [PATCH] Avoid including X11 headers from 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". --- include/wx/gtk/glcanvas.h | 2 +- include/wx/gtk1/glcanvas.h | 2 +- include/wx/unix/glx11.h | 56 ++++---------------- include/wx/x11/glcanvas.h | 2 +- samples/opengl/isosurf/isosurf.cpp | 8 +-- src/gtk/glcanvas.cpp | 4 +- src/gtk1/glcanvas.cpp | 4 +- src/unix/glx11.cpp | 85 +++++++++++++++++++----------- src/x11/glcanvas.cpp | 4 +- 9 files changed, 74 insertions(+), 93 deletions(-) diff --git a/include/wx/gtk/glcanvas.h b/include/wx/gtk/glcanvas.h index d79bba0439..ff0eddd141 100644 --- a/include/wx/gtk/glcanvas.h +++ b/include/wx/gtk/glcanvas.h @@ -63,7 +63,7 @@ public: // implement wxGLCanvasX11 methods // -------------------------------- - virtual Window GetXWindow() const wxOVERRIDE; + virtual unsigned long GetXWindow() const wxOVERRIDE; // deprecated methods diff --git a/include/wx/gtk1/glcanvas.h b/include/wx/gtk1/glcanvas.h index 73dcb27b59..96f956b8f2 100644 --- a/include/wx/gtk1/glcanvas.h +++ b/include/wx/gtk1/glcanvas.h @@ -61,7 +61,7 @@ public: // implement wxGLCanvasX11 methods // ------------------------------- - virtual Window GetXWindow() const; + virtual unsigned long GetXWindow() const; // deprecated methods diff --git a/include/wx/unix/glx11.h b/include/wx/unix/glx11.h index bfc5ac0e46..e7b49bbe10 100644 --- a/include/wx/unix/glx11.h +++ b/include/wx/unix/glx11.h @@ -10,10 +10,10 @@ #ifndef _WX_UNIX_GLX11_H_ #define _WX_UNIX_GLX11_H_ -#include +#include -class wxGLContextAttrs; -class wxGLAttributes; +typedef struct __GLXcontextRec* GLXContext; +typedef struct __GLXFBConfigRec* GLXFBConfig; // ---------------------------------------------------------------------------- // wxGLContext @@ -30,9 +30,6 @@ public: virtual bool SetCurrent(const wxGLCanvas& win) const wxOVERRIDE; private: - // attach context to the drawable or unset it (if NULL) - static bool MakeCurrent(GLXDrawable drawable, GLXContext context); - GLXContext m_glContext; wxDECLARE_CLASS(wxGLContext); @@ -74,7 +71,7 @@ public: static bool IsGLXMultiSampleAvailable(); // get the X11 handle of this window - virtual Window GetXWindow() const = 0; + virtual unsigned long GetXWindow() const = 0; // GLX-specific methods @@ -93,36 +90,15 @@ public: // get the GLXFBConfig/XVisualInfo we use 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 // not found 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: - - // this is only used if it's supported i.e. if GL >= 1.3 GLXFBConfig *m_fbc; - - // 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; + void* m_vi; }; // ---------------------------------------------------------------------------- @@ -135,29 +111,15 @@ private: class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase { public: - wxGLApp() : wxGLAppBase() { } - - // implement wxGLAppBase method - virtual bool InitGLVisual(const int *attribList) wxOVERRIDE - { - return wxGLCanvasX11::InitDefaultVisualInfo(attribList); - } + virtual bool InitGLVisual(const int *attribList) wxOVERRIDE; // This method is not currently used by the library itself, but remains for // backwards compatibility and also because wxGTK has it we could start // using it for the same purpose in wxX11 too some day. - virtual void* GetXVisualInfo() wxOVERRIDE - { - return wxGLCanvasX11::GetDefaultXVisualInfo(); - } + virtual void* GetXVisualInfo() wxOVERRIDE; // and override this wxApp method to clean up - virtual int OnExit() wxOVERRIDE - { - wxGLCanvasX11::FreeDefaultVisualInfo(); - - return wxGLAppBase::OnExit(); - } + virtual int OnExit() wxOVERRIDE; private: wxDECLARE_DYNAMIC_CLASS(wxGLApp); diff --git a/include/wx/x11/glcanvas.h b/include/wx/x11/glcanvas.h index d6bfe79da7..356eb00f26 100644 --- a/include/wx/x11/glcanvas.h +++ b/include/wx/x11/glcanvas.h @@ -57,7 +57,7 @@ public: // implement wxGLCanvasX11 methods // -------------------------------- - virtual Window GetXWindow() const; + virtual unsigned long GetXWindow() const; protected: virtual int GetColourIndex(const wxColour& col); diff --git a/samples/opengl/isosurf/isosurf.cpp b/samples/opengl/isosurf/isosurf.cpp index 46e02d055c..6e1dae45a8 100644 --- a/samples/opengl/isosurf/isosurf.cpp +++ b/samples/opengl/isosurf/isosurf.cpp @@ -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_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1, WX_GL_DOUBLEBUFFER, -# if defined(__WXMAC__) || defined(__WXQT__) - GL_NONE }; -# else - None }; -# endif + 0 }; #endif if (!g_doubleBuffer) @@ -130,7 +126,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString& title, const wxPoint& pos, wxLogWarning("Disabling double buffering"); #ifdef __WXGTK__ - gl_attrib[9] = None; + gl_attrib[9] = 0; #endif g_doubleBuffer = GL_FALSE; } diff --git a/src/gtk/glcanvas.cpp b/src/gtk/glcanvas.cpp index b320e00324..67c7c50f73 100644 --- a/src/gtk/glcanvas.cpp +++ b/src/gtk/glcanvas.cpp @@ -50,7 +50,7 @@ parent_set_hook(GSignalInvocationHint*, guint, const GValue* param_values, void* wxGLCanvas* win = (wxGLCanvas*)data; if (g_value_peek_pointer(¶m_values[0]) == win->m_wxwindow) { - const XVisualInfo* xvi = win->GetXVisualInfo(); + const XVisualInfo* xvi = static_cast(win->GetXVisualInfo()); GdkVisual* visual = gtk_widget_get_visual(win->m_wxwindow); if (GDK_VISUAL_XVISUAL(visual)->visualid != xvi->visualid) { @@ -239,7 +239,7 @@ bool wxGLCanvas::SetBackgroundStyle(wxBackgroundStyle /* style */) return false; } -Window wxGLCanvas::GetXWindow() const +unsigned long wxGLCanvas::GetXWindow() const { GdkWindow* window = GTKGetDrawingWindow(); return window ? GDK_WINDOW_XID(window) : 0; diff --git a/src/gtk1/glcanvas.cpp b/src/gtk1/glcanvas.cpp index f19df8e0cf..b75b3766d8 100644 --- a/src/gtk1/glcanvas.cpp +++ b/src/gtk1/glcanvas.cpp @@ -246,7 +246,7 @@ bool wxGLCanvas::Create(wxWindow *parent, if ( !InitVisual(dispAttrs) ) return false; - GdkVisual *visual = gdkx_visual_get( GetXVisualInfo()->visualid ); + GdkVisual *visual = gdkx_visual_get(static_cast(GetXVisualInfo())->visualid); GdkColormap *colormap = gdk_colormap_new( visual, TRUE ); gtk_widget_push_colormap( colormap ); @@ -292,7 +292,7 @@ bool wxGLCanvas::Create(wxWindow *parent, return true; } -Window wxGLCanvas::GetXWindow() const +unsigned long wxGLCanvas::GetXWindow() const { GdkWindow *window = GTK_PIZZA(m_wxwindow)->bin_window; return window ? GDK_WINDOW_XWINDOW(window) : 0; diff --git a/src/unix/glx11.cpp b/src/unix/glx11.cpp index 498e8f121c..cc6e8c3c8f 100644 --- a/src/unix/glx11.cpp +++ b/src/unix/glx11.cpp @@ -25,6 +25,7 @@ #endif //WX_PRECOMP #include "wx/glcanvas.h" +#include // IRIX headers call this differently #ifdef __SGI__ @@ -446,6 +447,8 @@ void wxGLAttributes::AddDefaultsForWXBefore31() // wxGLContext implementation // ============================================================================ +static bool MakeCurrent(GLXDrawable drawable, GLXContext context); + // Need this X error handler for the case context creation fails static bool g_ctxErrorOccurred = false; static int CTXErrorHandler( Display* WXUNUSED(dpy), XErrorEvent* WXUNUSED(ev) ) @@ -486,7 +489,7 @@ wxGLContext::wxGLContext(wxGLCanvas *win, m_isOk = false; Display* dpy = wxGetX11Display(); - XVisualInfo *vi = win->GetXVisualInfo(); + XVisualInfo* vi = static_cast(win->GetXVisualInfo()); wxCHECK_RET( vi, "invalid visual for OpenGL" ); // 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 // version -/* static */ -bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context) +static bool MakeCurrent(GLXDrawable drawable, GLXContext context) { if (wxGLCanvas::GetGLXVersion() >= 13) return glXMakeContextCurrent( wxGetX11Display(), drawable, drawable, context); @@ -598,6 +600,12 @@ bool wxGLContext::MakeCurrent(GLXDrawable drawable, GLXContext context) // wxGLCanvasX11 implementation // ============================================================================ +static GLXFBConfig* gs_glFBCInfo; +static XVisualInfo* gs_glVisualInfo; + +static bool InitXVisualInfo( + const wxGLAttributes& dispAttrs, GLXFBConfig** pFBC, XVisualInfo** pXVisual); + // ---------------------------------------------------------------------------- // initialization methods and dtor // ---------------------------------------------------------------------------- @@ -610,7 +618,9 @@ wxGLCanvasX11::wxGLCanvasX11() 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 ) { wxFAIL_MSG("Failed to get a XVisualInfo for the requested attributes."); @@ -620,10 +630,10 @@ bool wxGLCanvasX11::InitVisual(const wxGLAttributes& dispAttrs) wxGLCanvasX11::~wxGLCanvasX11() { - if ( m_fbc && m_fbc != ms_glFBCInfo ) + if (m_fbc && m_fbc != gs_glFBCInfo) XFree(m_fbc); - if ( m_vi && m_vi != ms_glVisualInfo ) + if (m_vi && m_vi != gs_glVisualInfo) XFree(m_vi); } @@ -651,9 +661,7 @@ bool wxGLCanvasX11::IsGLXMultiSampleAvailable() return s_isMultiSampleAvailable != 0; } - -/* static */ -bool wxGLCanvasX11::InitXVisualInfo(const wxGLAttributes& dispAttrs, +static bool InitXVisualInfo(const wxGLAttributes& dispAttrs, GLXFBConfig** pFBC, XVisualInfo** pXVisual) { @@ -667,7 +675,7 @@ bool wxGLCanvasX11::InitXVisualInfo(const wxGLAttributes& dispAttrs, Display* dpy = wxGetX11Display(); - if ( GetGLXVersion() >= 13 ) + if (wxGLCanvasX11::GetGLXVersion() >= 13) { int returned; *pFBC = glXChooseFBConfig(dpy, DefaultScreen(dpy), attrsListGLX, &returned); @@ -699,7 +707,7 @@ bool wxGLCanvasBase::IsDisplaySupported(const wxGLAttributes& dispAttrs) GLXFBConfig *fbc = NULL; XVisualInfo *vi = NULL; - bool isSupported = wxGLCanvasX11::InitXVisualInfo(dispAttrs, &fbc, &vi); + bool isSupported = InitXVisualInfo(dispAttrs, &fbc, &vi); if ( fbc ) XFree(fbc); @@ -722,8 +730,19 @@ bool wxGLCanvasBase::IsDisplaySupported(const int *attribList) // default visual management // ---------------------------------------------------------------------------- -XVisualInfo *wxGLCanvasX11::ms_glVisualInfo = NULL; -GLXFBConfig *wxGLCanvasX11::ms_glFBCInfo = NULL; +static void FreeDefaultVisualInfo() +{ + if (gs_glFBCInfo) + { + XFree(gs_glFBCInfo); + gs_glFBCInfo = NULL; + } + if (gs_glVisualInfo) + { + XFree(gs_glVisualInfo); + gs_glVisualInfo = NULL; + } +} /* static */ bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList) @@ -732,23 +751,7 @@ bool wxGLCanvasX11::InitDefaultVisualInfo(const int *attribList) wxGLAttributes dispAttrs; ParseAttribList(attribList, dispAttrs); - return InitXVisualInfo(dispAttrs, &ms_glFBCInfo, &ms_glVisualInfo); -} - -/* static */ -void wxGLCanvasX11::FreeDefaultVisualInfo() -{ - if ( ms_glFBCInfo ) - { - XFree(ms_glFBCInfo); - ms_glFBCInfo = NULL; - } - - if ( ms_glVisualInfo ) - { - XFree(ms_glVisualInfo); - ms_glVisualInfo = NULL; - } + return InitXVisualInfo(dispAttrs, &gs_glFBCInfo, &gs_glVisualInfo); } // ---------------------------------------------------------------------------- @@ -788,5 +791,25 @@ bool wxGLCanvasX11::IsShownOnScreen() const 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 diff --git a/src/x11/glcanvas.cpp b/src/x11/glcanvas.cpp index 83652d4623..7a4c5fb0b0 100644 --- a/src/x11/glcanvas.cpp +++ b/src/x11/glcanvas.cpp @@ -101,9 +101,9 @@ bool wxGLCanvas::Create(wxWindow *parent, return true; } -Window wxGLCanvas::GetXWindow() const +unsigned long wxGLCanvas::GetXWindow() const { - return (Window) + return (unsigned long) #ifdef __WXMOTIF__ GetClientXWindow(); #else