summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2024-01-10 10:40:56 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2024-01-16 14:53:39 +0100
commitb13c610f50c714873987d8c4f30f50953ade9aba (patch)
treec98d1bcc44bac1c25a66233d22b77e5396a3ee77
parent3b9f6b54b1cda08079ae97956478a4af55133803 (diff)
Don't include windows.h in the public qopengl.h header
All we need are the APIENTRY and WINGDIAPI macros, as those are used in the gl.h header. Define those locally for the time we need them. Use a QT_APIENTRY macro instead of hijacking APIENTRY for when we declare OpenGL functions with the stdcall calling convention. A few build fixes needed in tests that used Windows types without explicitly including windows.h first, or that (incorrectly) included one of the sub-headers of windows.h (like winuser.h). [ChangeLog][Potentially Source-Incompatible Changes][OpenGL] On Windows, the public qopengl.h header no longer includes windows.h. Pick-to: 6.7 Fixes: QTBUG-120687 Change-Id: I3770ac8eaeee5bcf4e7234e5a2539935a8aa5a7d Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--src/gui/opengl/qopengl.h41
-rw-r--r--tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp1
-rw-r--r--tests/shared/nativewindow.h2
3 files changed, 32 insertions, 12 deletions
diff --git a/src/gui/opengl/qopengl.h b/src/gui/opengl/qopengl.h
index 7e5b8e6961..e9a11080ce 100644
--- a/src/gui/opengl/qopengl.h
+++ b/src/gui/opengl/qopengl.h
@@ -8,9 +8,19 @@
#ifndef QT_NO_OPENGL
-// Windows always needs this to ensure that APIENTRY gets defined
+// On Windows we need to ensure that APIENTRY and WINGDIAPI are defined before
+// we can include gl.h. But we do not want to include <windows.h> in this public
+// Qt header, as it pollutes the global namespace with macros.
#if defined(Q_OS_WIN)
-# include <QtCore/qt_windows.h>
+# ifndef APIENTRY
+# define APIENTRY __stdcall
+# define Q_UNDEF_APIENTRY
+# endif // APIENTRY
+# ifndef WINGDIAPI
+# define WINGDIAPI __declspec(dllimport)
+# define Q_UNDEF_WINGDIAPI
+# endif // WINGDIAPI
+# define QT_APIENTRY __stdcall
#endif
// Note: Apple is a "controlled platform" for OpenGL ABI so we
@@ -128,11 +138,11 @@ typedef char GLchar;
// OS X 10.6 doesn't define these which are needed below
// OS X 10.7 and later define them in gl3.h
-#ifndef APIENTRY
-#define APIENTRY
+#ifndef QT_APIENTRY
+#define QT_APIENTRY
#endif
-#ifndef APIENTRYP
-#define APIENTRYP APIENTRY *
+#ifndef QT_APIENTRYP
+#define QT_APIENTRYP QT_APIENTRY *
#endif
#ifndef GLAPI
#define GLAPI extern
@@ -231,15 +241,15 @@ struct _cl_event;
#endif
#ifndef GL_ARB_debug_output
-typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam);
+typedef void (QT_APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam);
#endif
#ifndef GL_AMD_debug_output
-typedef void (APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
+typedef void (QT_APIENTRY *GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
#endif
#ifndef GL_KHR_debug
-typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam);
+typedef void (QT_APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const GLvoid *userParam);
#endif
#ifndef GL_NV_vdpau_interop
@@ -256,8 +266,8 @@ typedef ptrdiff_t qopengl_GLintptr;
typedef ptrdiff_t qopengl_GLsizeiptr;
-#if defined(APIENTRY) && !defined(QOPENGLF_APIENTRY)
-# define QOPENGLF_APIENTRY APIENTRY
+#if defined(QT_APIENTRY) && !defined(QOPENGLF_APIENTRY)
+# define QOPENGLF_APIENTRY QT_APIENTRY
#endif
# ifndef QOPENGLF_APIENTRYP
@@ -271,6 +281,15 @@ typedef ptrdiff_t qopengl_GLsizeiptr;
QT_END_NAMESPACE
+#ifdef Q_UNDEF_WINGDIAPI
+# undef WINGDIAPI
+# undef Q_UNDEF_WINGDIAPI
+#endif
+#ifdef Q_UNDEF_APIENTRY
+# undef APIENTRY
+# undef Q_UNDEF_APIENTRY
+#endif
+
#endif // QT_NO_OPENGL
#endif // QOPENGL_H
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
index 520233bf69..775b9018fd 100644
--- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
+++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
@@ -23,6 +23,7 @@
# include <QtGui/private/qguiapplication_p.h>
# include <QtGui/qwindowsmimeconverter.h>
# include <QtGui/qpa/qplatformintegration.h>
+# include <QtCore/qt_windows.h>
#endif
class tst_QClipboard : public QObject
diff --git a/tests/shared/nativewindow.h b/tests/shared/nativewindow.h
index bddc0f1216..def9c98af6 100644
--- a/tests/shared/nativewindow.h
+++ b/tests/shared/nativewindow.h
@@ -11,7 +11,7 @@
# include <UIKit/UIKit.h>
# define VIEW_BASE UIView
#elif defined(Q_OS_WIN)
-# include <winuser.h>
+# include <QtCore/qt_windows.h>
#elif QT_CONFIG(xcb)
# include <xcb/xcb.h>
#elif defined(ANDROID)