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.

Fixes: QTBUG-120687
Change-Id: I3770ac8eaeee5bcf4e7234e5a2539935a8aa5a7d
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit b13c610f50c714873987d8c4f30f50953ade9aba)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2024-01-10 10:40:56 +01:00 committed by Qt Cherry-pick Bot
parent 87aa94008b
commit 1f3f99f673
3 changed files with 32 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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)