summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-06-21 13:39:26 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-06-21 14:02:22 +0200
commit176f30b13739b352cbe453cba7796d9a9c808bcd (patch)
tree8fa60b6ae4ef06455652863a0406bc5e86a22303 /src/gui
parent272daebaa07b21e372ad4274fafb51ce0be92396 (diff)
OpenGL API refactor.
Rename QGuiGLFormat to QSurfaceFormat, and make QWindow sub-class of QSurface and QPlatformWindow sub-class of QPlatformSurface, instead of having QPlatformGLSurface accessor in QWindow.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/kernel.pri4
-rw-r--r--src/gui/kernel/qguiglcontext_qpa.cpp17
-rw-r--r--src/gui/kernel/qguiglcontext_qpa.h11
-rw-r--r--src/gui/kernel/qplatformglcontext_qpa.h39
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.cpp2
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h3
-rw-r--r--src/gui/kernel/qplatformwindow_qpa.cpp19
-rw-r--r--src/gui/kernel/qplatformwindow_qpa.h11
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp (renamed from src/gui/kernel/qguiglformat_qpa.cpp)118
-rw-r--r--src/gui/kernel/qsurfaceformat.h (renamed from src/gui/kernel/qguiglformat_qpa.h)54
-rw-r--r--src/gui/kernel/qwindow.cpp38
-rw-r--r--src/gui/kernel/qwindow.h42
-rw-r--r--src/gui/kernel/qwindow_p.h6
13 files changed, 161 insertions, 203 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index 1d708e85b2..09df411404 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -52,7 +52,7 @@ qpa {
kernel/qplatformcursor_qpa.h \
kernel/qplatformclipboard_qpa.h \
kernel/qplatformnativeinterface_qpa.h \
- kernel/qguiglformat_qpa.h \
+ kernel/qsurfaceformat.h \
kernel/qguiapplication.h \
kernel/qguiapplication_p.h \
kernel/qwindow_p.h \
@@ -76,7 +76,7 @@ qpa {
kernel/qplatformclipboard_qpa.cpp \
kernel/qplatformnativeinterface_qpa.cpp \
kernel/qsessionmanager_qpa.cpp \
- kernel/qguiglformat_qpa.cpp \
+ kernel/qsurfaceformat.cpp \
kernel/qguiapplication.cpp \
kernel/qwindow.cpp
diff --git a/src/gui/kernel/qguiglcontext_qpa.cpp b/src/gui/kernel/qguiglcontext_qpa.cpp
index 4b30b41ab8..fd827966c4 100644
--- a/src/gui/kernel/qguiglcontext_qpa.cpp
+++ b/src/gui/kernel/qguiglcontext_qpa.cpp
@@ -120,7 +120,7 @@ QPlatformGLContext *QGuiGLContext::handle() const
/*!
Creates a new GL context with the given format and shared context.
*/
-QGuiGLContext::QGuiGLContext(const QGuiGLFormat &format, QGuiGLContext *shareContext)
+QGuiGLContext::QGuiGLContext(const QSurfaceFormat &format, QGuiGLContext *shareContext)
: d_ptr(new QGuiGLContextPrivate())
{
Q_D(QGuiGLContext);
@@ -149,7 +149,7 @@ bool QGuiGLContext::isValid() const
/*!
If surface is 0 this is equivalent to calling doneCurrent().
*/
-bool QGuiGLContext::makeCurrent(QPlatformGLSurface *surface)
+bool QGuiGLContext::makeCurrent(QSurface *surface)
{
Q_D(QGuiGLContext);
if (!d->platformGLContext)
@@ -160,7 +160,10 @@ bool QGuiGLContext::makeCurrent(QPlatformGLSurface *surface)
return true;
}
- if (d->platformGLContext->makeCurrent(*surface)) {
+ if (!surface->surfaceHandle())
+ return false;
+
+ if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
QGuiGLContextPrivate::setCurrentContext(this);
return true;
}
@@ -181,7 +184,7 @@ void QGuiGLContext::doneCurrent()
QGuiGLContextPrivate::setCurrentContext(0);
}
-void QGuiGLContext::swapBuffers(QPlatformGLSurface *surface)
+void QGuiGLContext::swapBuffers(QSurface *surface)
{
Q_D(QGuiGLContext);
if (!d->platformGLContext)
@@ -192,7 +195,7 @@ void QGuiGLContext::swapBuffers(QPlatformGLSurface *surface)
return;
}
- d->platformGLContext->swapBuffers(*surface);
+ d->platformGLContext->swapBuffers(surface->surfaceHandle());
}
void (*QGuiGLContext::getProcAddress(const QByteArray &procName)) ()
@@ -203,11 +206,11 @@ void (*QGuiGLContext::getProcAddress(const QByteArray &procName)) ()
return d->platformGLContext->getProcAddress(procName);
}
-QGuiGLFormat QGuiGLContext::format() const
+QSurfaceFormat QGuiGLContext::format() const
{
Q_D(const QGuiGLContext);
if (!d->platformGLContext)
- return QGuiGLFormat();
+ return QSurfaceFormat();
return d->platformGLContext->format();
}
diff --git a/src/gui/kernel/qguiglcontext_qpa.h b/src/gui/kernel/qguiglcontext_qpa.h
index 230be08029..65e9fb4c3f 100644
--- a/src/gui/kernel/qguiglcontext_qpa.h
+++ b/src/gui/kernel/qguiglcontext_qpa.h
@@ -53,24 +53,25 @@ QT_MODULE(Gui)
class QGuiGLContextPrivate;
class QPlatformGLContext;
-class QPlatformGLSurface;
+class QSurface;
+class QSurfaceFormat;
class Q_GUI_EXPORT QGuiGLContext
{
Q_DECLARE_PRIVATE(QGuiGLContext);
public:
- QGuiGLContext(const QGuiGLFormat &format = QGuiGLFormat(), QGuiGLContext *shareContext = 0);
+ QGuiGLContext(const QSurfaceFormat &format = QSurfaceFormat(), QGuiGLContext *shareContext = 0);
~QGuiGLContext();
bool isValid() const;
- bool makeCurrent(QPlatformGLSurface *surface);
+ bool makeCurrent(QSurface *surface);
void doneCurrent();
- void swapBuffers(QPlatformGLSurface *surface);
+ void swapBuffers(QSurface *surface);
void (*getProcAddress(const QByteArray &procName)) ();
- QGuiGLFormat format() const;
+ QSurfaceFormat format() const;
QGuiGLContext *shareContext() const;
diff --git a/src/gui/kernel/qplatformglcontext_qpa.h b/src/gui/kernel/qplatformglcontext_qpa.h
index 51c63d3fa1..e362e477c0 100644
--- a/src/gui/kernel/qplatformglcontext_qpa.h
+++ b/src/gui/kernel/qplatformglcontext_qpa.h
@@ -39,11 +39,12 @@
**
****************************************************************************/
-#ifndef QPLATFORM_GL_CONTEXT_H
-#define QPLATFORM_GL_CONTEXT_H
+#ifndef QPLATFORMGLCONTEXT_H
+#define QPLATFORMGLCONTEXT_H
#include <QtCore/qnamespace.h>
-#include <QtGui/qguiglformat_qpa.h>
+#include <QtGui/qsurfaceformat.h>
+#include <QtGui/qwindow.h>
QT_BEGIN_HEADER
@@ -51,29 +52,19 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
-class Q_GUI_EXPORT QPlatformGLSurface
+class Q_GUI_EXPORT QPlatformSurface
{
public:
- QPlatformGLSurface(const QGuiGLFormat &format = QGuiGLFormat())
- : m_format(format)
- {
- }
+ virtual QSurfaceFormat format() const = 0;
- virtual ~QPlatformGLSurface() {}
+ QSurface::SurfaceType surfaceType() const { return m_type; }
- QGuiGLFormat format() const
- {
- return m_format;
- }
+private:
+ QPlatformSurface(QSurface::SurfaceType type) : m_type(type) {}
-protected:
- void setFormat(const QGuiGLFormat &format)
- {
- m_format = format;
- }
+ QSurface::SurfaceType m_type;
-private:
- QGuiGLFormat m_format;
+ friend class QPlatformWindow;
};
class Q_GUI_EXPORT QPlatformGLContext
@@ -81,11 +72,11 @@ class Q_GUI_EXPORT QPlatformGLContext
public:
virtual ~QPlatformGLContext() {}
- virtual QGuiGLFormat format() const = 0;
+ virtual QSurfaceFormat format() const = 0;
- virtual void swapBuffers(const QPlatformGLSurface &surface) = 0;
+ virtual void swapBuffers(QPlatformSurface *surface) = 0;
- virtual bool makeCurrent(const QPlatformGLSurface &surface) = 0;
+ virtual bool makeCurrent(QPlatformSurface *surface) = 0;
virtual void doneCurrent() = 0;
virtual void (*getProcAddress(const QByteArray &procName)) () = 0;
@@ -96,4 +87,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QPLATFORM_GL_CONTEXT_H
+#endif // QPLATFORMGLCONTEXT_H
diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp
index 5db0366707..fe90ce86aa 100644
--- a/src/gui/kernel/qplatformintegration_qpa.cpp
+++ b/src/gui/kernel/qplatformintegration_qpa.cpp
@@ -171,7 +171,7 @@ QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
*/
-QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const
+QPlatformGLContext *QPlatformIntegration::createPlatformGLContext(const QSurfaceFormat &, QPlatformGLContext *) const
{
qWarning("This plugin does not support createPlatformGLContext!");
return 0;
diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h
index 8263999b2d..c1934ec83a 100644
--- a/src/gui/kernel/qplatformintegration_qpa.h
+++ b/src/gui/kernel/qplatformintegration_qpa.h
@@ -45,6 +45,7 @@
#include <QtGui/qwindowdefs.h>
#include <QtGui/private/qpixmapdata_p.h>
#include <QtGui/qplatformscreen_qpa.h>
+#include <QtGui/qsurfaceformat.h>
QT_BEGIN_HEADER
@@ -79,7 +80,7 @@ public:
virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0;
virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0;
virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const = 0;
- virtual QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const;
+ virtual QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &format, QPlatformGLContext *share) const;
// Window System functions
virtual QList<QPlatformScreen *> screens() const = 0;
diff --git a/src/gui/kernel/qplatformwindow_qpa.cpp b/src/gui/kernel/qplatformwindow_qpa.cpp
index feffd0cfed..b1fdc9734d 100644
--- a/src/gui/kernel/qplatformwindow_qpa.cpp
+++ b/src/gui/kernel/qplatformwindow_qpa.cpp
@@ -56,7 +56,8 @@ class QPlatformWindowPrivate
*/
QPlatformWindow::QPlatformWindow(QWindow *window)
- : d_ptr(new QPlatformWindowPrivate)
+ : QPlatformSurface(QSurface::Window)
+ , d_ptr(new QPlatformWindowPrivate)
{
Q_D(QPlatformWindow);
d->window = window;
@@ -88,6 +89,14 @@ QPlatformWindow *QPlatformWindow::parent() const
}
/*!
+ Returns the actual surface format of the window.
+*/
+QSurfaceFormat QPlatformWindow::format() const
+{
+ return QSurfaceFormat();
+}
+
+/*!
This function is called by Qt whenever a window is moved or the window is resized. The resize
can happen programatically(from ie. user application) or by the window manager. This means that
there is no need to call this function specifically from the window manager callback, instead
@@ -209,14 +218,6 @@ void QPlatformWindow::requestActivateWindow()
QWindowSystemInterface::handleWindowActivated(window());
}
-/*!
- Reimplement to create a GL surface for the window.
-*/
-QPlatformGLSurface *QPlatformWindow::createGLSurface() const
-{
- return 0;
-}
-
bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
{
Q_UNUSED(grab);
diff --git a/src/gui/kernel/qplatformwindow_qpa.h b/src/gui/kernel/qplatformwindow_qpa.h
index 8166344246..dc988e183e 100644
--- a/src/gui/kernel/qplatformwindow_qpa.h
+++ b/src/gui/kernel/qplatformwindow_qpa.h
@@ -41,13 +41,13 @@
#ifndef QPLATFORMWINDOW_H
#define QPLATFORMWINDOW_H
-
#include <QtCore/qscopedpointer.h>
#include <QtCore/qrect.h>
#include <QtCore/qmargins.h>
#include <QtCore/qstring.h>
#include <QtGui/qwindowdefs.h>
-
+#include <QtGui/qwindow.h>
+#include <QtGui/qplatformglcontext_qpa.h>
QT_BEGIN_HEADER
@@ -57,9 +57,8 @@ QT_MODULE(Gui)
class QPlatformWindowPrivate;
class QWindow;
-class QPlatformGLSurface;
-class Q_GUI_EXPORT QPlatformWindow
+class Q_GUI_EXPORT QPlatformWindow : public QPlatformSurface
{
Q_DECLARE_PRIVATE(QPlatformWindow)
public:
@@ -69,6 +68,8 @@ public:
QWindow *window() const;
QPlatformWindow *parent() const;
+ virtual QSurfaceFormat format() const;
+
virtual void setGeometry(const QRect &rect);
virtual QRect geometry() const;
@@ -90,8 +91,6 @@ public:
virtual void setOpacity(qreal level);
virtual void requestActivateWindow();
- virtual QPlatformGLSurface *createGLSurface() const;
-
virtual bool setKeyboardGrabEnabled(bool grab);
virtual bool setMouseGrabEnabled(bool grab);
diff --git a/src/gui/kernel/qguiglformat_qpa.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 65bd6a4ac2..88601cab1f 100644
--- a/src/gui/kernel/qguiglformat_qpa.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -39,29 +39,29 @@
**
****************************************************************************/
-#include "qguiglformat_qpa.h"
+#include "qsurfaceformat.h"
#include <QtCore/qatomic.h>
#include <QtCore/QDebug>
-class QGuiGLFormatPrivate
+class QSurfaceFormatPrivate
{
public:
- QGuiGLFormatPrivate()
+ QSurfaceFormatPrivate()
: ref(1)
- , opts(QGuiGLFormat::DoubleBuffer | QGuiGLFormat::WindowSurface)
+ , opts(QSurfaceFormat::DoubleBuffer)
, redBufferSize(-1)
, greenBufferSize(-1)
, blueBufferSize(-1)
, alphaBufferSize(-1)
, depthSize(-1)
, stencilSize(-1)
- , swapBehavior(QGuiGLFormat::DefaultSwapBehavior)
+ , swapBehavior(QSurfaceFormat::DefaultSwapBehavior)
, numSamples(-1)
{
}
- QGuiGLFormatPrivate(const QGuiGLFormatPrivate *other)
+ QSurfaceFormatPrivate(const QSurfaceFormatPrivate *other)
: ref(1),
opts(other->opts),
redBufferSize(other->redBufferSize),
@@ -76,35 +76,35 @@ public:
}
QAtomicInt ref;
- QGuiGLFormat::FormatOptions opts;
+ QSurfaceFormat::FormatOptions opts;
int redBufferSize;
int greenBufferSize;
int blueBufferSize;
int alphaBufferSize;
int depthSize;
int stencilSize;
- QGuiGLFormat::SwapBehavior swapBehavior;
+ QSurfaceFormat::SwapBehavior swapBehavior;
int numSamples;
};
-QGuiGLFormat::QGuiGLFormat()
+QSurfaceFormat::QSurfaceFormat()
{
- d = new QGuiGLFormatPrivate;
+ d = new QSurfaceFormatPrivate;
}
-QGuiGLFormat::QGuiGLFormat(QGuiGLFormat::FormatOptions options)
+QSurfaceFormat::QSurfaceFormat(QSurfaceFormat::FormatOptions options)
{
- d = new QGuiGLFormatPrivate;
+ d = new QSurfaceFormatPrivate;
d->opts = options;
}
/*!
\internal
*/
-void QGuiGLFormat::detach()
+void QSurfaceFormat::detach()
{
if (d->ref != 1) {
- QGuiGLFormatPrivate *newd = new QGuiGLFormatPrivate(d);
+ QSurfaceFormatPrivate *newd = new QSurfaceFormatPrivate(d);
if (!d->ref.deref())
delete d;
d = newd;
@@ -115,7 +115,7 @@ void QGuiGLFormat::detach()
Constructs a copy of \a other.
*/
-QGuiGLFormat::QGuiGLFormat(const QGuiGLFormat &other)
+QSurfaceFormat::QSurfaceFormat(const QSurfaceFormat &other)
{
d = other.d;
d->ref.ref();
@@ -125,7 +125,7 @@ QGuiGLFormat::QGuiGLFormat(const QGuiGLFormat &other)
Assigns \a other to this object.
*/
-QGuiGLFormat &QGuiGLFormat::operator=(const QGuiGLFormat &other)
+QSurfaceFormat &QSurfaceFormat::operator=(const QSurfaceFormat &other)
{
if (d != other.d) {
other.d->ref.ref();
@@ -137,16 +137,16 @@ QGuiGLFormat &QGuiGLFormat::operator=(const QGuiGLFormat &other)
}
/*!
- Destroys the QGuiGLFormat.
+ Destroys the QSurfaceFormat.
*/
-QGuiGLFormat::~QGuiGLFormat()
+QSurfaceFormat::~QSurfaceFormat()
{
if (!d->ref.deref())
delete d;
}
/*!
- \fn bool QGuiGLFormat::stereo() const
+ \fn bool QSurfaceFormat::stereo() const
Returns true if stereo buffering is enabled; otherwise returns
false. Stereo buffering is disabled by default.
@@ -166,12 +166,12 @@ QGuiGLFormat::~QGuiGLFormat()
\sa stereo()
*/
-void QGuiGLFormat::setStereo(bool enable)
+void QSurfaceFormat::setStereo(bool enable)
{
if (enable) {
- d->opts |= QGuiGLFormat::StereoBuffers;
+ d->opts |= QSurfaceFormat::StereoBuffers;
} else {
- d->opts &= ~QGuiGLFormat::StereoBuffers;
+ d->opts &= ~QSurfaceFormat::StereoBuffers;
}
}
@@ -182,7 +182,7 @@ void QGuiGLFormat::setStereo(bool enable)
\sa setSampleBuffers(), sampleBuffers(), setSamples()
*/
-int QGuiGLFormat::samples() const
+int QSurfaceFormat::samples() const
{
return d->numSamples;
}
@@ -194,41 +194,19 @@ int QGuiGLFormat::samples() const
\sa setSampleBuffers(), sampleBuffers(), samples()
*/
-void QGuiGLFormat::setSamples(int numSamples)
+void QSurfaceFormat::setSamples(int numSamples)
{
detach();
d->numSamples = numSamples;
}
-
-/*!
- \fn bool QGuiGLFormat::hasWindowSurface() const
-
- Returns true if the corresponding widget has an instance of QWindowSurface.
-
- Otherwise returns false.
-
- WindowSurface is enabled by default.
-
- \sa setOverlay()
-*/
-
-void QGuiGLFormat::setWindowSurface(bool enable)
-{
- if (enable) {
- d->opts |= QGuiGLFormat::WindowSurface;
- } else {
- d->opts &= ~QGuiGLFormat::WindowSurface;
- }
-}
-
/*!
Sets the format option to \a opt.
\sa testOption()
*/
-void QGuiGLFormat::setOption(QGuiGLFormat::FormatOptions opt)
+void QSurfaceFormat::setOption(QSurfaceFormat::FormatOptions opt)
{
detach();
d->opts |= opt;
@@ -240,7 +218,7 @@ void QGuiGLFormat::setOption(QGuiGLFormat::FormatOptions opt)
\sa setOption()
*/
-bool QGuiGLFormat::testOption(QGuiGLFormat::FormatOptions opt) const
+bool QSurfaceFormat::testOption(QSurfaceFormat::FormatOptions opt) const
{
return d->opts & opt;
}
@@ -250,7 +228,7 @@ bool QGuiGLFormat::testOption(QGuiGLFormat::FormatOptions opt) const
\sa depthBufferSize(), setDepth(), depth()
*/
-void QGuiGLFormat::setDepthBufferSize(int size)
+void QSurfaceFormat::setDepthBufferSize(int size)
{
detach();
d->depthSize = size;
@@ -261,22 +239,22 @@ void QGuiGLFormat::setDepthBufferSize(int size)
\sa depth(), setDepth(), setDepthBufferSize()
*/
-int QGuiGLFormat::depthBufferSize() const
+int QSurfaceFormat::depthBufferSize() const
{
return d->depthSize;
}
-void QGuiGLFormat::setSwapBehavior(SwapBehavior behavior)
+void QSurfaceFormat::setSwapBehavior(SwapBehavior behavior)
{
d->swapBehavior = behavior;
}
-QGuiGLFormat::SwapBehavior QGuiGLFormat::swapBehavior() const
+QSurfaceFormat::SwapBehavior QSurfaceFormat::swapBehavior() const
{
return d->swapBehavior;
}
-bool QGuiGLFormat::hasAlpha() const
+bool QSurfaceFormat::hasAlpha() const
{
return d->alphaBufferSize > 0;
}
@@ -286,7 +264,7 @@ bool QGuiGLFormat::hasAlpha() const
\sa stencilBufferSize(), setStencil(), stencil()
*/
-void QGuiGLFormat::setStencilBufferSize(int size)
+void QSurfaceFormat::setStencilBufferSize(int size)
{
detach();
d->stencilSize = size;
@@ -297,52 +275,52 @@ void QGuiGLFormat::setStencilBufferSize(int size)
\sa stencil(), setStencil(), setStencilBufferSize()
*/
-int QGuiGLFormat::stencilBufferSize() const
+int QSurfaceFormat::stencilBufferSize() const
{
return d->stencilSize;
}
-int QGuiGLFormat::redBufferSize() const
+int QSurfaceFormat::redBufferSize() const
{
return d->redBufferSize;
}
-int QGuiGLFormat::greenBufferSize() const
+int QSurfaceFormat::greenBufferSize() const
{
return d->greenBufferSize;
}
-int QGuiGLFormat::blueBufferSize() const
+int QSurfaceFormat::blueBufferSize() const
{
return d->blueBufferSize;
}
-int QGuiGLFormat::alphaBufferSize() const
+int QSurfaceFormat::alphaBufferSize() const
{
return d->alphaBufferSize;
}
-void QGuiGLFormat::setRedBufferSize(int size)
+void QSurfaceFormat::setRedBufferSize(int size)
{
d->redBufferSize = size;
}
-void QGuiGLFormat::setGreenBufferSize(int size)
+void QSurfaceFormat::setGreenBufferSize(int size)
{
d->greenBufferSize = size;
}
-void QGuiGLFormat::setBlueBufferSize(int size)
+void QSurfaceFormat::setBlueBufferSize(int size)
{
d->blueBufferSize = size;
}
-void QGuiGLFormat::setAlphaBufferSize(int size)
+void QSurfaceFormat::setAlphaBufferSize(int size)
{
d->alphaBufferSize = size;
}
-bool operator==(const QGuiGLFormat& a, const QGuiGLFormat& b)
+bool operator==(const QSurfaceFormat& a, const QSurfaceFormat& b)
{
return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts
&& a.d->stencilSize == b.d->stencilSize
@@ -357,23 +335,23 @@ bool operator==(const QGuiGLFormat& a, const QGuiGLFormat& b)
/*!
- Returns false if all the options of the two QGuiGLFormat objects
+ Returns false if all the options of the two QSurfaceFormat objects
\a a and \a b are equal; otherwise returns true.
- \relates QGuiGLFormat
+ \relates QSurfaceFormat
*/
-bool operator!=(const QGuiGLFormat& a, const QGuiGLFormat& b)
+bool operator!=(const QSurfaceFormat& a, const QSurfaceFormat& b)
{
return !(a == b);
}
#ifndef QT_NO_DEBUG_STREAM
-QDebug operator<<(QDebug dbg, const QGuiGLFormat &f)
+QDebug operator<<(QDebug dbg, const QSurfaceFormat &f)
{
- const QGuiGLFormatPrivate * const d = f.d;
+ const QSurfaceFormatPrivate * const d = f.d;
- dbg.nospace() << "QGuiGLFormat("
+ dbg.nospace() << "QSurfaceFormat("
<< "options " << d->opts
<< ", depthBufferSize " << d->depthSize
<< ", redBufferSize " << d->redBufferSize
diff --git a/src/gui/kernel/qguiglformat_qpa.h b/src/gui/kernel/qsurfaceformat.h
index a14a8256b6..6e89aa667b 100644
--- a/src/gui/kernel/qguiglformat_qpa.h
+++ b/src/gui/kernel/qsurfaceformat.h
@@ -38,8 +38,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef QGUIGLFORMAT_QPA_H
-#define QGUIGLFORMAT_QPA_H
+#ifndef QSURFACEFORMAT_H
+#define QSURFACEFORMAT_H
#include <qglobal.h>
@@ -50,14 +50,13 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QGuiGLContext;
-class QGuiGLFormatPrivate;
+class QSurfaceFormatPrivate;
-class Q_GUI_EXPORT QGuiGLFormat
+class Q_GUI_EXPORT QSurfaceFormat
{
public:
enum FormatOption {
- StereoBuffers = 0x0001,
- WindowSurface = 0x0002
+ StereoBuffers = 0x0001
};
Q_DECLARE_FLAGS(FormatOptions, FormatOption)
@@ -74,11 +73,11 @@ public:
CompatibilityProfile
};
- QGuiGLFormat();
- QGuiGLFormat(FormatOptions options);
- QGuiGLFormat(const QGuiGLFormat &other);
- QGuiGLFormat &operator=(const QGuiGLFormat &other);
- ~QGuiGLFormat();
+ QSurfaceFormat();
+ QSurfaceFormat(FormatOptions options);
+ QSurfaceFormat(const QSurfaceFormat &other);
+ QSurfaceFormat &operator=(const QSurfaceFormat &other);
+ ~QSurfaceFormat();
void setDepthBufferSize(int size);
int depthBufferSize() const;
@@ -108,45 +107,38 @@ public:
bool stereo() const;
void setStereo(bool enable);
- bool windowSurface() const;
- void setWindowSurface(bool enable);
- void setOption(QGuiGLFormat::FormatOptions opt);
- bool testOption(QGuiGLFormat::FormatOptions opt) const;
+ void setOption(QSurfaceFormat::FormatOptions opt);
+ bool testOption(QSurfaceFormat::FormatOptions opt) const;
private:
- QGuiGLFormatPrivate *d;
+ QSurfaceFormatPrivate *d;
void detach();
- friend Q_GUI_EXPORT bool operator==(const QGuiGLFormat&, const QGuiGLFormat&);
- friend Q_GUI_EXPORT bool operator!=(const QGuiGLFormat&, const QGuiGLFormat&);
+ friend Q_GUI_EXPORT bool operator==(const QSurfaceFormat&, const QSurfaceFormat&);
+ friend Q_GUI_EXPORT bool operator!=(const QSurfaceFormat&, const QSurfaceFormat&);
#ifndef QT_NO_DEBUG_STREAM
- friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QGuiGLFormat &);
+ friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
#endif
};
-Q_GUI_EXPORT bool operator==(const QGuiGLFormat&, const QGuiGLFormat&);
-Q_GUI_EXPORT bool operator!=(const QGuiGLFormat&, const QGuiGLFormat&);
+Q_GUI_EXPORT bool operator==(const QSurfaceFormat&, const QSurfaceFormat&);
+Q_GUI_EXPORT bool operator!=(const QSurfaceFormat&, const QSurfaceFormat&);
#ifndef QT_NO_DEBUG_STREAM
-Q_GUI_EXPORT QDebug operator<<(QDebug, const QGuiGLFormat &);
+Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
#endif
-Q_DECLARE_OPERATORS_FOR_FLAGS(QGuiGLFormat::FormatOptions)
+Q_DECLARE_OPERATORS_FOR_FLAGS(QSurfaceFormat::FormatOptions)
-inline bool QGuiGLFormat::stereo() const
+inline bool QSurfaceFormat::stereo() const
{
- return testOption(QGuiGLFormat::StereoBuffers);
-}
-
-inline bool QGuiGLFormat::windowSurface() const
-{
- return testOption(QGuiGLFormat::WindowSurface);
+ return testOption(QSurfaceFormat::StereoBuffers);
}
QT_END_NAMESPACE
QT_END_HEADER
-#endif //QGUIGLFORMAT_QPA_H
+#endif //QSURFACEFORMAT_H
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index c29bc7002d..f56962ddb4 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -42,7 +42,7 @@
#include "qwindow.h"
#include "qplatformwindow_qpa.h"
-#include "qguiglformat_qpa.h"
+#include "qsurfaceformat.h"
#include "qplatformglcontext_qpa.h"
#include "qguiglcontext_qpa.h"
@@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE
QWindow::QWindow(QWindow *parent)
: QObject(*new QWindowPrivate(), parent)
+ , QSurface(QSurface::Window)
{
Q_D(QWindow);
d->parentWindow = parent;
@@ -178,40 +179,20 @@ void QWindow::setWindowModality(Qt::WindowModality windowModality)
d->modality = windowModality;
}
-void QWindow::setGLFormat(const QGuiGLFormat &format)
+void QWindow::setFormat(const QSurfaceFormat &format)
{
Q_D(QWindow);
d->requestedFormat = format;
}
-QGuiGLFormat QWindow::glFormat() const
+QSurfaceFormat QWindow::format() const
{
Q_D(const QWindow);
- if (d->glSurface)
- return d->glSurface->format();
+ if (d->platformWindow)
+ return d->platformWindow->format();
return d->requestedFormat;
}
-QPlatformGLSurface *QWindow::glSurface() const
-{
- Q_D(const QWindow);
- if (d->platformWindow && !d->glSurface)
- const_cast<QPlatformGLSurface *&>(d->glSurface) = d->platformWindow->createGLSurface();
- return d->glSurface;
-}
-
-void QWindow::setSurfaceType(SurfaceType type)
-{
- Q_D(QWindow);
- d->surfaceType = type;
-}
-
-QWindow::SurfaceType QWindow::surfaceType() const
-{
- Q_D(const QWindow);
- return d->surfaceType;
-}
-
void QWindow::setWindowFlags(Qt::WindowFlags flags)
{
Q_D(QWindow);
@@ -414,9 +395,7 @@ void QWindow::setWindowIcon(const QImage &icon) const
void QWindow::destroy()
{
Q_D(QWindow);
- delete d->glSurface;
delete d->platformWindow;
- d->glSurface = 0;
d->platformWindow = 0;
}
@@ -426,6 +405,11 @@ QPlatformWindow *QWindow::handle() const
return d->platformWindow;
}
+QPlatformSurface *QWindow::surfaceHandle() const
+{
+ Q_D(const QWindow);
+ return d->platformWindow;
+}
bool QWindow::setKeyboardGrabEnabled(bool grab)
{
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index cfd251fff0..af882b5451 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -46,7 +46,7 @@
#include <QtCore/QEvent>
#include <QtCore/QMargins>
-#include <QtGui/qguiglformat_qpa.h>
+#include <QtGui/qsurfaceformat.h>
#include <QtGui/qwindowdefs.h>
QT_BEGIN_HEADER
@@ -67,11 +67,31 @@ class QMouseEvent;
class QWheelEvent;
#endif
-class QPlatformGLSurface;
+class QPlatformSurface;
class QPlatformWindow;
class QBackingStore;
-class Q_GUI_EXPORT QWindow : public QObject
+class Q_GUI_EXPORT QSurface
+{
+public:
+ enum SurfaceType {
+ Window
+ };
+
+ SurfaceType surfaceType() const { return m_type; }
+
+ virtual QSurfaceFormat format() const = 0;
+ virtual QPlatformSurface *surfaceHandle() const = 0;
+
+private:
+ QSurface(SurfaceType type) : m_type(type) {}
+
+ SurfaceType m_type;
+
+ friend class QWindow;
+};
+
+class Q_GUI_EXPORT QWindow : public QObject, public QSurface
{
Q_OBJECT
Q_DECLARE_PRIVATE(QWindow)
@@ -79,11 +99,6 @@ class Q_GUI_EXPORT QWindow : public QObject
Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
public:
- enum SurfaceType {
- RasterSurface,
- OpenGLSurface
- };
-
QWindow(QWindow *parent = 0);
virtual ~QWindow();
@@ -103,13 +118,8 @@ public:
Qt::WindowModality windowModality() const;
void setWindowModality(Qt::WindowModality windowModality);
- void setGLFormat(const QGuiGLFormat &format);
- QGuiGLFormat glFormat() const;
-
- QPlatformGLSurface *glSurface() const;
-
- void setSurfaceType(SurfaceType type);
- SurfaceType surfaceType() const;
+ void setFormat(const QSurfaceFormat &format);
+ QSurfaceFormat format() const;
void setWindowFlags(Qt::WindowFlags flags);
Qt::WindowFlags windowFlags() const;
@@ -187,6 +197,8 @@ protected:
#endif
private:
+ QPlatformSurface *surfaceHandle() const;
+
Q_DISABLE_COPY(QWindow)
friend class QGuiApplication;
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index 1c4c4bffad..a8b118319d 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -60,11 +60,9 @@ public:
QWindowPrivate()
: QObjectPrivate()
, windowFlags(Qt::Window)
- , surfaceType(QWindow::RasterSurface)
, parentWindow(0)
, platformWindow(0)
, visible(false)
- , glSurface(0)
, windowState(Qt::WindowNoState)
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal)
@@ -78,14 +76,12 @@ public:
}
Qt::WindowFlags windowFlags;
- QWindow::SurfaceType surfaceType;
QWindow *parentWindow;
QPlatformWindow *platformWindow;
bool visible;
- QGuiGLFormat requestedFormat;
+ QSurfaceFormat requestedFormat;
QString windowTitle;
QRect geometry;
- QPlatformGLSurface *glSurface;
Qt::WindowState windowState;
QSize minimumSize;