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.
This commit is contained in:
Samuel Rødal 2011-06-21 13:39:26 +02:00
parent 272daebaa0
commit 176f30b137
65 changed files with 477 additions and 553 deletions

View File

@ -15,7 +15,7 @@ Renderer::Renderer()
m_context = new QGuiGLContext(m_format); m_context = new QGuiGLContext(m_format);
} }
QGuiGLFormat Renderer::format() const QSurfaceFormat Renderer::format() const
{ {
return m_format; return m_format;
} }
@ -24,10 +24,9 @@ HelloWindow::HelloWindow(Renderer *renderer)
: m_colorIndex(0) : m_colorIndex(0)
, m_renderer(renderer) , m_renderer(renderer)
{ {
setSurfaceType(OpenGLSurface);
setWindowTitle(QLatin1String("Hello Window")); setWindowTitle(QLatin1String("Hello Window"));
setGLFormat(renderer->format()); setFormat(renderer->format());
setGeometry(QRect(10, 10, 640, 480)); setGeometry(QRect(10, 10, 640, 480));
@ -62,13 +61,13 @@ void HelloWindow::updateColor()
void HelloWindow::render() void HelloWindow::render()
{ {
if (glSurface()) m_renderer->render(this, m_color, geometry().size());
m_renderer->render(glSurface(), m_color, geometry().size());
} }
void Renderer::render(QPlatformGLSurface *surface, const QColor &color, const QSize &viewSize) void Renderer::render(QSurface *surface, const QColor &color, const QSize &viewSize)
{ {
m_context->makeCurrent(surface); if (!m_context->makeCurrent(surface))
return;
if (!m_initialized) { if (!m_initialized) {
initialize(); initialize();

View File

@ -12,9 +12,9 @@ class Renderer : public QObject
public: public:
Renderer(); Renderer();
QGuiGLFormat format() const; QSurfaceFormat format() const;
void render(QPlatformGLSurface *surface, const QColor &color, const QSize &viewSize); void render(QSurface *surface, const QColor &color, const QSize &viewSize);
private: private:
void initialize(); void initialize();
@ -35,7 +35,7 @@ private:
int colorUniform; int colorUniform;
bool m_initialized; bool m_initialized;
QGuiGLFormat m_format; QSurfaceFormat m_format;
QGuiGLContext *m_context; QGuiGLContext *m_context;
}; };

View File

@ -52,7 +52,7 @@ qpa {
kernel/qplatformcursor_qpa.h \ kernel/qplatformcursor_qpa.h \
kernel/qplatformclipboard_qpa.h \ kernel/qplatformclipboard_qpa.h \
kernel/qplatformnativeinterface_qpa.h \ kernel/qplatformnativeinterface_qpa.h \
kernel/qguiglformat_qpa.h \ kernel/qsurfaceformat.h \
kernel/qguiapplication.h \ kernel/qguiapplication.h \
kernel/qguiapplication_p.h \ kernel/qguiapplication_p.h \
kernel/qwindow_p.h \ kernel/qwindow_p.h \
@ -76,7 +76,7 @@ qpa {
kernel/qplatformclipboard_qpa.cpp \ kernel/qplatformclipboard_qpa.cpp \
kernel/qplatformnativeinterface_qpa.cpp \ kernel/qplatformnativeinterface_qpa.cpp \
kernel/qsessionmanager_qpa.cpp \ kernel/qsessionmanager_qpa.cpp \
kernel/qguiglformat_qpa.cpp \ kernel/qsurfaceformat.cpp \
kernel/qguiapplication.cpp \ kernel/qguiapplication.cpp \
kernel/qwindow.cpp kernel/qwindow.cpp

View File

@ -120,7 +120,7 @@ QPlatformGLContext *QGuiGLContext::handle() const
/*! /*!
Creates a new GL context with the given format and shared context. 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()) : d_ptr(new QGuiGLContextPrivate())
{ {
Q_D(QGuiGLContext); Q_D(QGuiGLContext);
@ -149,7 +149,7 @@ bool QGuiGLContext::isValid() const
/*! /*!
If surface is 0 this is equivalent to calling doneCurrent(). If surface is 0 this is equivalent to calling doneCurrent().
*/ */
bool QGuiGLContext::makeCurrent(QPlatformGLSurface *surface) bool QGuiGLContext::makeCurrent(QSurface *surface)
{ {
Q_D(QGuiGLContext); Q_D(QGuiGLContext);
if (!d->platformGLContext) if (!d->platformGLContext)
@ -160,7 +160,10 @@ bool QGuiGLContext::makeCurrent(QPlatformGLSurface *surface)
return true; return true;
} }
if (d->platformGLContext->makeCurrent(*surface)) { if (!surface->surfaceHandle())
return false;
if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
QGuiGLContextPrivate::setCurrentContext(this); QGuiGLContextPrivate::setCurrentContext(this);
return true; return true;
} }
@ -181,7 +184,7 @@ void QGuiGLContext::doneCurrent()
QGuiGLContextPrivate::setCurrentContext(0); QGuiGLContextPrivate::setCurrentContext(0);
} }
void QGuiGLContext::swapBuffers(QPlatformGLSurface *surface) void QGuiGLContext::swapBuffers(QSurface *surface)
{ {
Q_D(QGuiGLContext); Q_D(QGuiGLContext);
if (!d->platformGLContext) if (!d->platformGLContext)
@ -192,7 +195,7 @@ void QGuiGLContext::swapBuffers(QPlatformGLSurface *surface)
return; return;
} }
d->platformGLContext->swapBuffers(*surface); d->platformGLContext->swapBuffers(surface->surfaceHandle());
} }
void (*QGuiGLContext::getProcAddress(const QByteArray &procName)) () void (*QGuiGLContext::getProcAddress(const QByteArray &procName)) ()
@ -203,11 +206,11 @@ void (*QGuiGLContext::getProcAddress(const QByteArray &procName)) ()
return d->platformGLContext->getProcAddress(procName); return d->platformGLContext->getProcAddress(procName);
} }
QGuiGLFormat QGuiGLContext::format() const QSurfaceFormat QGuiGLContext::format() const
{ {
Q_D(const QGuiGLContext); Q_D(const QGuiGLContext);
if (!d->platformGLContext) if (!d->platformGLContext)
return QGuiGLFormat(); return QSurfaceFormat();
return d->platformGLContext->format(); return d->platformGLContext->format();
} }

View File

@ -53,24 +53,25 @@ QT_MODULE(Gui)
class QGuiGLContextPrivate; class QGuiGLContextPrivate;
class QPlatformGLContext; class QPlatformGLContext;
class QPlatformGLSurface; class QSurface;
class QSurfaceFormat;
class Q_GUI_EXPORT QGuiGLContext class Q_GUI_EXPORT QGuiGLContext
{ {
Q_DECLARE_PRIVATE(QGuiGLContext); Q_DECLARE_PRIVATE(QGuiGLContext);
public: public:
QGuiGLContext(const QGuiGLFormat &format = QGuiGLFormat(), QGuiGLContext *shareContext = 0); QGuiGLContext(const QSurfaceFormat &format = QSurfaceFormat(), QGuiGLContext *shareContext = 0);
~QGuiGLContext(); ~QGuiGLContext();
bool isValid() const; bool isValid() const;
bool makeCurrent(QPlatformGLSurface *surface); bool makeCurrent(QSurface *surface);
void doneCurrent(); void doneCurrent();
void swapBuffers(QPlatformGLSurface *surface); void swapBuffers(QSurface *surface);
void (*getProcAddress(const QByteArray &procName)) (); void (*getProcAddress(const QByteArray &procName)) ();
QGuiGLFormat format() const; QSurfaceFormat format() const;
QGuiGLContext *shareContext() const; QGuiGLContext *shareContext() const;

View File

@ -39,11 +39,12 @@
** **
****************************************************************************/ ****************************************************************************/
#ifndef QPLATFORM_GL_CONTEXT_H #ifndef QPLATFORMGLCONTEXT_H
#define QPLATFORM_GL_CONTEXT_H #define QPLATFORMGLCONTEXT_H
#include <QtCore/qnamespace.h> #include <QtCore/qnamespace.h>
#include <QtGui/qguiglformat_qpa.h> #include <QtGui/qsurfaceformat.h>
#include <QtGui/qwindow.h>
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -51,29 +52,19 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui) QT_MODULE(Gui)
class Q_GUI_EXPORT QPlatformGLSurface class Q_GUI_EXPORT QPlatformSurface
{ {
public: public:
QPlatformGLSurface(const QGuiGLFormat &format = QGuiGLFormat()) virtual QSurfaceFormat format() const = 0;
: m_format(format)
{
}
virtual ~QPlatformGLSurface() {} QSurface::SurfaceType surfaceType() const { return m_type; }
QGuiGLFormat format() const
{
return m_format;
}
protected:
void setFormat(const QGuiGLFormat &format)
{
m_format = format;
}
private: private:
QGuiGLFormat m_format; QPlatformSurface(QSurface::SurfaceType type) : m_type(type) {}
QSurface::SurfaceType m_type;
friend class QPlatformWindow;
}; };
class Q_GUI_EXPORT QPlatformGLContext class Q_GUI_EXPORT QPlatformGLContext
@ -81,11 +72,11 @@ class Q_GUI_EXPORT QPlatformGLContext
public: public:
virtual ~QPlatformGLContext() {} 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 doneCurrent() = 0;
virtual void (*getProcAddress(const QByteArray &procName)) () = 0; virtual void (*getProcAddress(const QByteArray &procName)) () = 0;
@ -96,4 +87,4 @@ QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER
#endif // QPLATFORM_GL_CONTEXT_H #endif // QPLATFORMGLCONTEXT_H

View File

@ -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!"); qWarning("This plugin does not support createPlatformGLContext!");
return 0; return 0;

View File

@ -45,6 +45,7 @@
#include <QtGui/qwindowdefs.h> #include <QtGui/qwindowdefs.h>
#include <QtGui/private/qpixmapdata_p.h> #include <QtGui/private/qpixmapdata_p.h>
#include <QtGui/qplatformscreen_qpa.h> #include <QtGui/qplatformscreen_qpa.h>
#include <QtGui/qsurfaceformat.h>
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -79,7 +80,7 @@ public:
virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0; virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0;
virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0; virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0;
virtual QPlatformBackingStore *createPlatformBackingStore(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 // Window System functions
virtual QList<QPlatformScreen *> screens() const = 0; virtual QList<QPlatformScreen *> screens() const = 0;

View File

@ -56,7 +56,8 @@ class QPlatformWindowPrivate
*/ */
QPlatformWindow::QPlatformWindow(QWindow *window) QPlatformWindow::QPlatformWindow(QWindow *window)
: d_ptr(new QPlatformWindowPrivate) : QPlatformSurface(QSurface::Window)
, d_ptr(new QPlatformWindowPrivate)
{ {
Q_D(QPlatformWindow); Q_D(QPlatformWindow);
d->window = window; d->window = window;
@ -87,6 +88,14 @@ QPlatformWindow *QPlatformWindow::parent() const
return d->window->parent() ? d->window->parent()->handle() : 0; return d->window->parent() ? d->window->parent()->handle() : 0;
} }
/*!
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 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 can happen programatically(from ie. user application) or by the window manager. This means that
@ -209,14 +218,6 @@ void QPlatformWindow::requestActivateWindow()
QWindowSystemInterface::handleWindowActivated(window()); QWindowSystemInterface::handleWindowActivated(window());
} }
/*!
Reimplement to create a GL surface for the window.
*/
QPlatformGLSurface *QPlatformWindow::createGLSurface() const
{
return 0;
}
bool QPlatformWindow::setKeyboardGrabEnabled(bool grab) bool QPlatformWindow::setKeyboardGrabEnabled(bool grab)
{ {
Q_UNUSED(grab); Q_UNUSED(grab);

View File

@ -41,13 +41,13 @@
#ifndef QPLATFORMWINDOW_H #ifndef QPLATFORMWINDOW_H
#define QPLATFORMWINDOW_H #define QPLATFORMWINDOW_H
#include <QtCore/qscopedpointer.h> #include <QtCore/qscopedpointer.h>
#include <QtCore/qrect.h> #include <QtCore/qrect.h>
#include <QtCore/qmargins.h> #include <QtCore/qmargins.h>
#include <QtCore/qstring.h> #include <QtCore/qstring.h>
#include <QtGui/qwindowdefs.h> #include <QtGui/qwindowdefs.h>
#include <QtGui/qwindow.h>
#include <QtGui/qplatformglcontext_qpa.h>
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -57,9 +57,8 @@ QT_MODULE(Gui)
class QPlatformWindowPrivate; class QPlatformWindowPrivate;
class QWindow; class QWindow;
class QPlatformGLSurface;
class Q_GUI_EXPORT QPlatformWindow class Q_GUI_EXPORT QPlatformWindow : public QPlatformSurface
{ {
Q_DECLARE_PRIVATE(QPlatformWindow) Q_DECLARE_PRIVATE(QPlatformWindow)
public: public:
@ -69,6 +68,8 @@ public:
QWindow *window() const; QWindow *window() const;
QPlatformWindow *parent() const; QPlatformWindow *parent() const;
virtual QSurfaceFormat format() const;
virtual void setGeometry(const QRect &rect); virtual void setGeometry(const QRect &rect);
virtual QRect geometry() const; virtual QRect geometry() const;
@ -90,8 +91,6 @@ public:
virtual void setOpacity(qreal level); virtual void setOpacity(qreal level);
virtual void requestActivateWindow(); virtual void requestActivateWindow();
virtual QPlatformGLSurface *createGLSurface() const;
virtual bool setKeyboardGrabEnabled(bool grab); virtual bool setKeyboardGrabEnabled(bool grab);
virtual bool setMouseGrabEnabled(bool grab); virtual bool setMouseGrabEnabled(bool grab);

View File

@ -39,29 +39,29 @@
** **
****************************************************************************/ ****************************************************************************/
#include "qguiglformat_qpa.h" #include "qsurfaceformat.h"
#include <QtCore/qatomic.h> #include <QtCore/qatomic.h>
#include <QtCore/QDebug> #include <QtCore/QDebug>
class QGuiGLFormatPrivate class QSurfaceFormatPrivate
{ {
public: public:
QGuiGLFormatPrivate() QSurfaceFormatPrivate()
: ref(1) : ref(1)
, opts(QGuiGLFormat::DoubleBuffer | QGuiGLFormat::WindowSurface) , opts(QSurfaceFormat::DoubleBuffer)
, redBufferSize(-1) , redBufferSize(-1)
, greenBufferSize(-1) , greenBufferSize(-1)
, blueBufferSize(-1) , blueBufferSize(-1)
, alphaBufferSize(-1) , alphaBufferSize(-1)
, depthSize(-1) , depthSize(-1)
, stencilSize(-1) , stencilSize(-1)
, swapBehavior(QGuiGLFormat::DefaultSwapBehavior) , swapBehavior(QSurfaceFormat::DefaultSwapBehavior)
, numSamples(-1) , numSamples(-1)
{ {
} }
QGuiGLFormatPrivate(const QGuiGLFormatPrivate *other) QSurfaceFormatPrivate(const QSurfaceFormatPrivate *other)
: ref(1), : ref(1),
opts(other->opts), opts(other->opts),
redBufferSize(other->redBufferSize), redBufferSize(other->redBufferSize),
@ -76,35 +76,35 @@ public:
} }
QAtomicInt ref; QAtomicInt ref;
QGuiGLFormat::FormatOptions opts; QSurfaceFormat::FormatOptions opts;
int redBufferSize; int redBufferSize;
int greenBufferSize; int greenBufferSize;
int blueBufferSize; int blueBufferSize;
int alphaBufferSize; int alphaBufferSize;
int depthSize; int depthSize;
int stencilSize; int stencilSize;
QGuiGLFormat::SwapBehavior swapBehavior; QSurfaceFormat::SwapBehavior swapBehavior;
int numSamples; 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; d->opts = options;
} }
/*! /*!
\internal \internal
*/ */
void QGuiGLFormat::detach() void QSurfaceFormat::detach()
{ {
if (d->ref != 1) { if (d->ref != 1) {
QGuiGLFormatPrivate *newd = new QGuiGLFormatPrivate(d); QSurfaceFormatPrivate *newd = new QSurfaceFormatPrivate(d);
if (!d->ref.deref()) if (!d->ref.deref())
delete d; delete d;
d = newd; d = newd;
@ -115,7 +115,7 @@ void QGuiGLFormat::detach()
Constructs a copy of \a other. Constructs a copy of \a other.
*/ */
QGuiGLFormat::QGuiGLFormat(const QGuiGLFormat &other) QSurfaceFormat::QSurfaceFormat(const QSurfaceFormat &other)
{ {
d = other.d; d = other.d;
d->ref.ref(); d->ref.ref();
@ -125,7 +125,7 @@ QGuiGLFormat::QGuiGLFormat(const QGuiGLFormat &other)
Assigns \a other to this object. Assigns \a other to this object.
*/ */
QGuiGLFormat &QGuiGLFormat::operator=(const QGuiGLFormat &other) QSurfaceFormat &QSurfaceFormat::operator=(const QSurfaceFormat &other)
{ {
if (d != other.d) { if (d != other.d) {
other.d->ref.ref(); 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()) if (!d->ref.deref())
delete d; delete d;
} }
/*! /*!
\fn bool QGuiGLFormat::stereo() const \fn bool QSurfaceFormat::stereo() const
Returns true if stereo buffering is enabled; otherwise returns Returns true if stereo buffering is enabled; otherwise returns
false. Stereo buffering is disabled by default. false. Stereo buffering is disabled by default.
@ -166,12 +166,12 @@ QGuiGLFormat::~QGuiGLFormat()
\sa stereo() \sa stereo()
*/ */
void QGuiGLFormat::setStereo(bool enable) void QSurfaceFormat::setStereo(bool enable)
{ {
if (enable) { if (enable) {
d->opts |= QGuiGLFormat::StereoBuffers; d->opts |= QSurfaceFormat::StereoBuffers;
} else { } else {
d->opts &= ~QGuiGLFormat::StereoBuffers; d->opts &= ~QSurfaceFormat::StereoBuffers;
} }
} }
@ -182,7 +182,7 @@ void QGuiGLFormat::setStereo(bool enable)
\sa setSampleBuffers(), sampleBuffers(), setSamples() \sa setSampleBuffers(), sampleBuffers(), setSamples()
*/ */
int QGuiGLFormat::samples() const int QSurfaceFormat::samples() const
{ {
return d->numSamples; return d->numSamples;
} }
@ -194,41 +194,19 @@ int QGuiGLFormat::samples() const
\sa setSampleBuffers(), sampleBuffers(), samples() \sa setSampleBuffers(), sampleBuffers(), samples()
*/ */
void QGuiGLFormat::setSamples(int numSamples) void QSurfaceFormat::setSamples(int numSamples)
{ {
detach(); detach();
d->numSamples = numSamples; 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. Sets the format option to \a opt.
\sa testOption() \sa testOption()
*/ */
void QGuiGLFormat::setOption(QGuiGLFormat::FormatOptions opt) void QSurfaceFormat::setOption(QSurfaceFormat::FormatOptions opt)
{ {
detach(); detach();
d->opts |= opt; d->opts |= opt;
@ -240,7 +218,7 @@ void QGuiGLFormat::setOption(QGuiGLFormat::FormatOptions opt)
\sa setOption() \sa setOption()
*/ */
bool QGuiGLFormat::testOption(QGuiGLFormat::FormatOptions opt) const bool QSurfaceFormat::testOption(QSurfaceFormat::FormatOptions opt) const
{ {
return d->opts & opt; return d->opts & opt;
} }
@ -250,7 +228,7 @@ bool QGuiGLFormat::testOption(QGuiGLFormat::FormatOptions opt) const
\sa depthBufferSize(), setDepth(), depth() \sa depthBufferSize(), setDepth(), depth()
*/ */
void QGuiGLFormat::setDepthBufferSize(int size) void QSurfaceFormat::setDepthBufferSize(int size)
{ {
detach(); detach();
d->depthSize = size; d->depthSize = size;
@ -261,22 +239,22 @@ void QGuiGLFormat::setDepthBufferSize(int size)
\sa depth(), setDepth(), setDepthBufferSize() \sa depth(), setDepth(), setDepthBufferSize()
*/ */
int QGuiGLFormat::depthBufferSize() const int QSurfaceFormat::depthBufferSize() const
{ {
return d->depthSize; return d->depthSize;
} }
void QGuiGLFormat::setSwapBehavior(SwapBehavior behavior) void QSurfaceFormat::setSwapBehavior(SwapBehavior behavior)
{ {
d->swapBehavior = behavior; d->swapBehavior = behavior;
} }
QGuiGLFormat::SwapBehavior QGuiGLFormat::swapBehavior() const QSurfaceFormat::SwapBehavior QSurfaceFormat::swapBehavior() const
{ {
return d->swapBehavior; return d->swapBehavior;
} }
bool QGuiGLFormat::hasAlpha() const bool QSurfaceFormat::hasAlpha() const
{ {
return d->alphaBufferSize > 0; return d->alphaBufferSize > 0;
} }
@ -286,7 +264,7 @@ bool QGuiGLFormat::hasAlpha() const
\sa stencilBufferSize(), setStencil(), stencil() \sa stencilBufferSize(), setStencil(), stencil()
*/ */
void QGuiGLFormat::setStencilBufferSize(int size) void QSurfaceFormat::setStencilBufferSize(int size)
{ {
detach(); detach();
d->stencilSize = size; d->stencilSize = size;
@ -297,52 +275,52 @@ void QGuiGLFormat::setStencilBufferSize(int size)
\sa stencil(), setStencil(), setStencilBufferSize() \sa stencil(), setStencil(), setStencilBufferSize()
*/ */
int QGuiGLFormat::stencilBufferSize() const int QSurfaceFormat::stencilBufferSize() const
{ {
return d->stencilSize; return d->stencilSize;
} }
int QGuiGLFormat::redBufferSize() const int QSurfaceFormat::redBufferSize() const
{ {
return d->redBufferSize; return d->redBufferSize;
} }
int QGuiGLFormat::greenBufferSize() const int QSurfaceFormat::greenBufferSize() const
{ {
return d->greenBufferSize; return d->greenBufferSize;
} }
int QGuiGLFormat::blueBufferSize() const int QSurfaceFormat::blueBufferSize() const
{ {
return d->blueBufferSize; return d->blueBufferSize;
} }
int QGuiGLFormat::alphaBufferSize() const int QSurfaceFormat::alphaBufferSize() const
{ {
return d->alphaBufferSize; return d->alphaBufferSize;
} }
void QGuiGLFormat::setRedBufferSize(int size) void QSurfaceFormat::setRedBufferSize(int size)
{ {
d->redBufferSize = size; d->redBufferSize = size;
} }
void QGuiGLFormat::setGreenBufferSize(int size) void QSurfaceFormat::setGreenBufferSize(int size)
{ {
d->greenBufferSize = size; d->greenBufferSize = size;
} }
void QGuiGLFormat::setBlueBufferSize(int size) void QSurfaceFormat::setBlueBufferSize(int size)
{ {
d->blueBufferSize = size; d->blueBufferSize = size;
} }
void QGuiGLFormat::setAlphaBufferSize(int size) void QSurfaceFormat::setAlphaBufferSize(int size)
{ {
d->alphaBufferSize = 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 return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts
&& a.d->stencilSize == b.d->stencilSize && 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. \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); return !(a == b);
} }
#ifndef QT_NO_DEBUG_STREAM #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 << "options " << d->opts
<< ", depthBufferSize " << d->depthSize << ", depthBufferSize " << d->depthSize
<< ", redBufferSize " << d->redBufferSize << ", redBufferSize " << d->redBufferSize

View File

@ -38,8 +38,8 @@
** $QT_END_LICENSE$ ** $QT_END_LICENSE$
** **
****************************************************************************/ ****************************************************************************/
#ifndef QGUIGLFORMAT_QPA_H #ifndef QSURFACEFORMAT_H
#define QGUIGLFORMAT_QPA_H #define QSURFACEFORMAT_H
#include <qglobal.h> #include <qglobal.h>
@ -50,14 +50,13 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui) QT_MODULE(Gui)
class QGuiGLContext; class QGuiGLContext;
class QGuiGLFormatPrivate; class QSurfaceFormatPrivate;
class Q_GUI_EXPORT QGuiGLFormat class Q_GUI_EXPORT QSurfaceFormat
{ {
public: public:
enum FormatOption { enum FormatOption {
StereoBuffers = 0x0001, StereoBuffers = 0x0001
WindowSurface = 0x0002
}; };
Q_DECLARE_FLAGS(FormatOptions, FormatOption) Q_DECLARE_FLAGS(FormatOptions, FormatOption)
@ -74,11 +73,11 @@ public:
CompatibilityProfile CompatibilityProfile
}; };
QGuiGLFormat(); QSurfaceFormat();
QGuiGLFormat(FormatOptions options); QSurfaceFormat(FormatOptions options);
QGuiGLFormat(const QGuiGLFormat &other); QSurfaceFormat(const QSurfaceFormat &other);
QGuiGLFormat &operator=(const QGuiGLFormat &other); QSurfaceFormat &operator=(const QSurfaceFormat &other);
~QGuiGLFormat(); ~QSurfaceFormat();
void setDepthBufferSize(int size); void setDepthBufferSize(int size);
int depthBufferSize() const; int depthBufferSize() const;
@ -108,45 +107,38 @@ public:
bool stereo() const; bool stereo() const;
void setStereo(bool enable); void setStereo(bool enable);
bool windowSurface() const;
void setWindowSurface(bool enable);
void setOption(QGuiGLFormat::FormatOptions opt); void setOption(QSurfaceFormat::FormatOptions opt);
bool testOption(QGuiGLFormat::FormatOptions opt) const; bool testOption(QSurfaceFormat::FormatOptions opt) const;
private: private:
QGuiGLFormatPrivate *d; QSurfaceFormatPrivate *d;
void detach(); void detach();
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 QGuiGLFormat&, const QGuiGLFormat&); friend Q_GUI_EXPORT bool operator!=(const QSurfaceFormat&, const QSurfaceFormat&);
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QGuiGLFormat &); friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
#endif #endif
}; };
Q_GUI_EXPORT bool operator==(const QGuiGLFormat&, const QGuiGLFormat&); Q_GUI_EXPORT bool operator==(const QSurfaceFormat&, const QSurfaceFormat&);
Q_GUI_EXPORT bool operator!=(const QGuiGLFormat&, const QGuiGLFormat&); Q_GUI_EXPORT bool operator!=(const QSurfaceFormat&, const QSurfaceFormat&);
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QGuiGLFormat &); Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
#endif #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); return testOption(QSurfaceFormat::StereoBuffers);
}
inline bool QGuiGLFormat::windowSurface() const
{
return testOption(QGuiGLFormat::WindowSurface);
} }
QT_END_NAMESPACE QT_END_NAMESPACE
QT_END_HEADER QT_END_HEADER
#endif //QGUIGLFORMAT_QPA_H #endif //QSURFACEFORMAT_H

View File

@ -42,7 +42,7 @@
#include "qwindow.h" #include "qwindow.h"
#include "qplatformwindow_qpa.h" #include "qplatformwindow_qpa.h"
#include "qguiglformat_qpa.h" #include "qsurfaceformat.h"
#include "qplatformglcontext_qpa.h" #include "qplatformglcontext_qpa.h"
#include "qguiglcontext_qpa.h" #include "qguiglcontext_qpa.h"
@ -57,6 +57,7 @@ QT_BEGIN_NAMESPACE
QWindow::QWindow(QWindow *parent) QWindow::QWindow(QWindow *parent)
: QObject(*new QWindowPrivate(), parent) : QObject(*new QWindowPrivate(), parent)
, QSurface(QSurface::Window)
{ {
Q_D(QWindow); Q_D(QWindow);
d->parentWindow = parent; d->parentWindow = parent;
@ -178,40 +179,20 @@ void QWindow::setWindowModality(Qt::WindowModality windowModality)
d->modality = windowModality; d->modality = windowModality;
} }
void QWindow::setGLFormat(const QGuiGLFormat &format) void QWindow::setFormat(const QSurfaceFormat &format)
{ {
Q_D(QWindow); Q_D(QWindow);
d->requestedFormat = format; d->requestedFormat = format;
} }
QGuiGLFormat QWindow::glFormat() const QSurfaceFormat QWindow::format() const
{ {
Q_D(const QWindow); Q_D(const QWindow);
if (d->glSurface) if (d->platformWindow)
return d->glSurface->format(); return d->platformWindow->format();
return d->requestedFormat; 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) void QWindow::setWindowFlags(Qt::WindowFlags flags)
{ {
Q_D(QWindow); Q_D(QWindow);
@ -414,9 +395,7 @@ void QWindow::setWindowIcon(const QImage &icon) const
void QWindow::destroy() void QWindow::destroy()
{ {
Q_D(QWindow); Q_D(QWindow);
delete d->glSurface;
delete d->platformWindow; delete d->platformWindow;
d->glSurface = 0;
d->platformWindow = 0; d->platformWindow = 0;
} }
@ -426,6 +405,11 @@ QPlatformWindow *QWindow::handle() const
return d->platformWindow; return d->platformWindow;
} }
QPlatformSurface *QWindow::surfaceHandle() const
{
Q_D(const QWindow);
return d->platformWindow;
}
bool QWindow::setKeyboardGrabEnabled(bool grab) bool QWindow::setKeyboardGrabEnabled(bool grab)
{ {

View File

@ -46,7 +46,7 @@
#include <QtCore/QEvent> #include <QtCore/QEvent>
#include <QtCore/QMargins> #include <QtCore/QMargins>
#include <QtGui/qguiglformat_qpa.h> #include <QtGui/qsurfaceformat.h>
#include <QtGui/qwindowdefs.h> #include <QtGui/qwindowdefs.h>
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -67,11 +67,31 @@ class QMouseEvent;
class QWheelEvent; class QWheelEvent;
#endif #endif
class QPlatformGLSurface; class QPlatformSurface;
class QPlatformWindow; class QPlatformWindow;
class QBackingStore; 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_OBJECT
Q_DECLARE_PRIVATE(QWindow) Q_DECLARE_PRIVATE(QWindow)
@ -79,11 +99,6 @@ class Q_GUI_EXPORT QWindow : public QObject
Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
public: public:
enum SurfaceType {
RasterSurface,
OpenGLSurface
};
QWindow(QWindow *parent = 0); QWindow(QWindow *parent = 0);
virtual ~QWindow(); virtual ~QWindow();
@ -103,13 +118,8 @@ public:
Qt::WindowModality windowModality() const; Qt::WindowModality windowModality() const;
void setWindowModality(Qt::WindowModality windowModality); void setWindowModality(Qt::WindowModality windowModality);
void setGLFormat(const QGuiGLFormat &format); void setFormat(const QSurfaceFormat &format);
QGuiGLFormat glFormat() const; QSurfaceFormat format() const;
QPlatformGLSurface *glSurface() const;
void setSurfaceType(SurfaceType type);
SurfaceType surfaceType() const;
void setWindowFlags(Qt::WindowFlags flags); void setWindowFlags(Qt::WindowFlags flags);
Qt::WindowFlags windowFlags() const; Qt::WindowFlags windowFlags() const;
@ -187,6 +197,8 @@ protected:
#endif #endif
private: private:
QPlatformSurface *surfaceHandle() const;
Q_DISABLE_COPY(QWindow) Q_DISABLE_COPY(QWindow)
friend class QGuiApplication; friend class QGuiApplication;

View File

@ -60,11 +60,9 @@ public:
QWindowPrivate() QWindowPrivate()
: QObjectPrivate() : QObjectPrivate()
, windowFlags(Qt::Window) , windowFlags(Qt::Window)
, surfaceType(QWindow::RasterSurface)
, parentWindow(0) , parentWindow(0)
, platformWindow(0) , platformWindow(0)
, visible(false) , visible(false)
, glSurface(0)
, windowState(Qt::WindowNoState) , windowState(Qt::WindowNoState)
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX) , maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal) , modality(Qt::NonModal)
@ -78,14 +76,12 @@ public:
} }
Qt::WindowFlags windowFlags; Qt::WindowFlags windowFlags;
QWindow::SurfaceType surfaceType;
QWindow *parentWindow; QWindow *parentWindow;
QPlatformWindow *platformWindow; QPlatformWindow *platformWindow;
bool visible; bool visible;
QGuiGLFormat requestedFormat; QSurfaceFormat requestedFormat;
QString windowTitle; QString windowTitle;
QRect geometry; QRect geometry;
QPlatformGLSurface *glSurface;
Qt::WindowState windowState; Qt::WindowState windowState;
QSize minimumSize; QSize minimumSize;

View File

@ -48,9 +48,7 @@
#include <QtCore/qmap.h> #include <QtCore/qmap.h>
#include <QtCore/qscopedpointer.h> #include <QtCore/qscopedpointer.h>
#ifdef Q_WS_QPA #include <QtGui/QSurfaceFormat>
#include <QtGui/QGuiGLFormat>
#endif
QT_BEGIN_HEADER QT_BEGIN_HEADER
@ -282,10 +280,8 @@ public:
static OpenGLVersionFlags openGLVersionFlags(); static OpenGLVersionFlags openGLVersionFlags();
#if defined(Q_WS_QPA) static QGLFormat fromSurfaceFormat(const QSurfaceFormat &format);
static QGLFormat fromGuiGLFormat(const QGuiGLFormat &format); static QSurfaceFormat toSurfaceFormat(const QGLFormat &format);
static QGuiGLFormat toGuiGLFormat(const QGLFormat &format);
#endif
private: private:
QGLFormatPrivate *d; QGLFormatPrivate *d;

View File

@ -47,7 +47,7 @@
#include <private/qapplication_p.h> #include <private/qapplication_p.h>
#include <QtGui/QPlatformGLContext> #include <QtGui/QPlatformGLContext>
#include <QtGui/QPlatformWindow> #include <QtGui/QPlatformWindow>
#include <QtGui/QGuiGLFormat> #include <QtGui/QSurfaceFormat>
#include "qgl.h" #include "qgl.h"
#include "qgl_p.h" #include "qgl_p.h"
@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
/*! /*!
Returns an OpenGL format for the window format specified by \a format. Returns an OpenGL format for the window format specified by \a format.
*/ */
QGLFormat QGLFormat::fromGuiGLFormat(const QGuiGLFormat &format) QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &format)
{ {
QGLFormat retFormat; QGLFormat retFormat;
if (format.alphaBufferSize() >= 0) if (format.alphaBufferSize() >= 0)
@ -78,7 +78,7 @@ QGLFormat QGLFormat::fromGuiGLFormat(const QGuiGLFormat &format)
retFormat.setStencil(true); retFormat.setStencil(true);
retFormat.setStencilBufferSize(format.stencilBufferSize()); retFormat.setStencilBufferSize(format.stencilBufferSize());
} }
retFormat.setDoubleBuffer(format.swapBehavior() != QGuiGLFormat::SingleBuffer); retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer);
retFormat.setStereo(format.stereo()); retFormat.setStereo(format.stereo());
return retFormat; return retFormat;
} }
@ -86,9 +86,9 @@ QGLFormat QGLFormat::fromGuiGLFormat(const QGuiGLFormat &format)
/*! /*!
Returns a window format for the OpenGL format specified by \a format. Returns a window format for the OpenGL format specified by \a format.
*/ */
QGuiGLFormat QGLFormat::toGuiGLFormat(const QGLFormat &format) QSurfaceFormat QGLFormat::toSurfaceFormat(const QGLFormat &format)
{ {
QGuiGLFormat retFormat; QSurfaceFormat retFormat;
if (format.alpha()) if (format.alpha())
retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize()); retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : format.alphaBufferSize());
if (format.blueBufferSize() >= 0) if (format.blueBufferSize() >= 0)
@ -99,7 +99,7 @@ QGuiGLFormat QGLFormat::toGuiGLFormat(const QGLFormat &format)
retFormat.setRedBufferSize(format.redBufferSize()); retFormat.setRedBufferSize(format.redBufferSize());
if (format.depth()) if (format.depth())
retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize()); retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize());
retFormat.setSwapBehavior(format.doubleBuffer() ? QGuiGLFormat::DoubleBuffer : QGuiGLFormat::DefaultSwapBehavior); retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::DefaultSwapBehavior);
if (format.sampleBuffers()) if (format.sampleBuffers())
retFormat.setSamples(format.samples() == -1 ? 4 : format.samples()); retFormat.setSamples(format.samples() == -1 ? 4 : format.samples());
if (format.stencil()) if (format.stencil())
@ -138,14 +138,12 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
}else { }else {
QWidget *widget = static_cast<QWidget *>(d->paintDevice); QWidget *widget = static_cast<QWidget *>(d->paintDevice);
QGLFormat glformat = format(); QGLFormat glformat = format();
QGuiGLFormat winFormat = QGLFormat::toGuiGLFormat(glformat); QSurfaceFormat winFormat = QGLFormat::toSurfaceFormat(glformat);
if (widget->testAttribute(Qt::WA_TranslucentBackground)) if (widget->testAttribute(Qt::WA_TranslucentBackground))
winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8)); winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8));
winFormat.setWindowSurface(false);
if (!widget->windowHandle()->handle()) { if (!widget->windowHandle()->handle()) {
widget->windowHandle()->setSurfaceType(QWindow::OpenGLSurface); widget->windowHandle()->setFormat(winFormat);
widget->windowHandle()->setGLFormat(winFormat);
widget->winId();//make window widget->winId();//make window
} }
@ -153,7 +151,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
QGuiGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0; QGuiGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0;
d->guiGlContext = new QGuiGLContext(winFormat, shareGlContext); d->guiGlContext = new QGuiGLContext(winFormat, shareGlContext);
d->glFormat = QGLFormat::fromGuiGLFormat(d->guiGlContext->format()); d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format());
d->valid = d->guiGlContext->isValid(); d->valid = d->guiGlContext->isValid();
if (d->valid) { if (d->valid) {
d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext); d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext);
@ -193,7 +191,7 @@ void QGLContext::makeCurrent()
if (!widget->windowHandle()) if (!widget->windowHandle())
return; return;
if (d->guiGlContext->makeCurrent(widget->windowHandle()->glSurface())) { if (d->guiGlContext->makeCurrent(widget->windowHandle())) {
if (!d->workaroundsCached) { if (!d->workaroundsCached) {
d->workaroundsCached = true; d->workaroundsCached = true;
const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER)); const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
@ -220,7 +218,7 @@ void QGLContext::swapBuffers() const
if (!widget->windowHandle()) if (!widget->windowHandle())
return; return;
d->guiGlContext->swapBuffers(widget->windowHandle()->glSurface()); d->guiGlContext->swapBuffers(widget->windowHandle());
} }
void *QGLContext::getProcAddress(const QString &procName) const void *QGLContext::getProcAddress(const QString &procName) const
@ -297,11 +295,10 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
d->window = new QWindow; d->window = new QWindow;
d->window->setGeometry(QRect(0, 0, 3, 3)); d->window->setGeometry(QRect(0, 0, 3, 3));
d->window->setSurfaceType(QWindow::OpenGLSurface);
d->window->create(); d->window->create();
d->context = new QGuiGLContext; d->context = new QGuiGLContext;
d->context->makeCurrent(d->window->glSurface()); d->context->makeCurrent(d->window);
} }
QGLTemporaryContext::~QGLTemporaryContext() QGLTemporaryContext::~QGLTemporaryContext()
@ -380,7 +377,7 @@ QGLContext::QGLContext(QGuiGLContext *context)
: d_ptr(new QGLContextPrivate(this)) : d_ptr(new QGLContextPrivate(this))
{ {
Q_D(QGLContext); Q_D(QGLContext);
d->init(0,QGLFormat::fromGuiGLFormat(context->format())); d->init(0, QGLFormat::fromSurfaceFormat(context->format()));
d->guiGlContext = context; d->guiGlContext = context;
d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext); d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext);
d->valid = context->isValid(); d->valid = context->isValid();

View File

@ -45,7 +45,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QVector<EGLint> q_createConfigAttributesFromFormat(const QGuiGLFormat &format) QVector<EGLint> q_createConfigAttributesFromFormat(const QSurfaceFormat &format)
{ {
int redSize = format.redBufferSize(); int redSize = format.redBufferSize();
int greenSize = format.greenBufferSize(); int greenSize = format.greenBufferSize();
@ -70,7 +70,7 @@ QVector<EGLint> q_createConfigAttributesFromFormat(const QGuiGLFormat &format)
// "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are // "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are
// put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit, // put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit,
// we must set the red/green/blue sizes to zero. This has an unfortunate consequence that // we must set the red/green/blue sizes to zero. This has an unfortunate consequence that
// if the application sets the red/green/blue size to 5/6/5 on the QGuiGLFormat, // if the application sets the red/green/blue size to 5/6/5 on the QSurfaceFormat,
// they will probably get a 32-bit config, even when there's an RGB565 config available. // they will probably get a 32-bit config, even when there's an RGB565 config available.
// // Now normalize the values so -1 becomes 0 // // Now normalize the values so -1 becomes 0
@ -197,7 +197,7 @@ bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes)
return false; return false;
} }
EGLConfig q_configFromGLFormat(EGLDisplay display, const QGuiGLFormat &format, bool highestPixelFormat, int surfaceType) EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType)
{ {
EGLConfig cfg = 0; EGLConfig cfg = 0;
QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(format); QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(format);
@ -259,9 +259,9 @@ EGLConfig q_configFromGLFormat(EGLDisplay display, const QGuiGLFormat &format, b
return 0; return 0;
} }
QGuiGLFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config) QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config)
{ {
QGuiGLFormat format; QSurfaceFormat format;
EGLint redSize = 0; EGLint redSize = 0;
EGLint greenSize = 0; EGLint greenSize = 0;
EGLint blueSize = 0; EGLint blueSize = 0;

View File

@ -43,16 +43,16 @@
#define QEGLCONVENIENCE_H #define QEGLCONVENIENCE_H
#include <QtGui/QGuiGLFormat> #include <QtGui/QSurfaceFormat>
#include <QtCore/QVector> #include <QtCore/QVector>
#include <EGL/egl.h> #include <EGL/egl.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QVector<EGLint> q_createConfigAttributesFromFormat(const QGuiGLFormat &format); QVector<EGLint> q_createConfigAttributesFromFormat(const QSurfaceFormat &format);
bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes); bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes);
EGLConfig q_configFromGLFormat(EGLDisplay display, const QGuiGLFormat &format, bool highestPixelFormat = false, int surfaceType = EGL_WINDOW_BIT); EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat = false, int surfaceType = EGL_WINDOW_BIT);
QGuiGLFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config); QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config);
bool q_hasEglExtension(EGLDisplay display,const char* extensionName); bool q_hasEglExtension(EGLDisplay display,const char* extensionName);
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -47,13 +47,7 @@
#include <EGL/egl.h> #include <EGL/egl.h>
QEGLSurface::QEGLSurface(EGLSurface surface, const QGuiGLFormat &format) QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformGLContext *share, EGLDisplay display,
: QPlatformGLSurface(format)
, m_eglSurface(surface)
{
}
QEGLPlatformContext::QEGLPlatformContext(const QGuiGLFormat &format, QPlatformGLContext *share, EGLDisplay display,
EGLint eglClientVersion, EGLenum eglApi) EGLint eglClientVersion, EGLenum eglApi)
: m_eglDisplay(display) : m_eglDisplay(display)
, m_eglApi(eglApi) , m_eglApi(eglApi)
@ -78,18 +72,18 @@ QEGLPlatformContext::QEGLPlatformContext(const QGuiGLFormat &format, QPlatformGL
} }
} }
bool QEGLPlatformContext::makeCurrent(const QPlatformGLSurface &surface) bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface)
{ {
#ifdef QEGL_EXTRA_DEBUG #ifdef QEGL_EXTRA_DEBUG
qWarning("QEglContext::makeCurrent: %p\n",this); qWarning("QEglContext::makeCurrent: %p\n",this);
#endif #endif
eglBindAPI(m_eglApi); eglBindAPI(m_eglApi);
EGLSurface eglSurface = static_cast<const QEGLSurface &>(surface).eglSurface(); EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);
bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext); bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);
if (!ok) if (!ok)
qWarning("QEGLPlatformContext::makeCurrent: eglError: %d, this: %p \n", eglGetError(), this); qWarning("QEGLPlatformContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this);
#ifdef QEGL_EXTRA_DEBUG #ifdef QEGL_EXTRA_DEBUG
static bool showDebug = true; static bool showDebug = true;
if (showDebug) { if (showDebug) {
@ -134,13 +128,14 @@ void QEGLPlatformContext::doneCurrent()
qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this); qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this);
} }
void QEGLPlatformContext::swapBuffers(const QPlatformGLSurface &surface) void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface)
{ {
#ifdef QEGL_EXTRA_DEBUG #ifdef QEGL_EXTRA_DEBUG
qWarning("QEglContext::swapBuffers:%p\n",this); qWarning("QEglContext::swapBuffers:%p\n",this);
#endif #endif
eglBindAPI(m_eglApi); eglBindAPI(m_eglApi);
bool ok = eglSwapBuffers(m_eglDisplay, static_cast<const QEGLSurface &>(surface).eglSurface()); EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);
bool ok = eglSwapBuffers(m_eglDisplay, eglSurface);
if (!ok) if (!ok)
qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this); qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this);
} }
@ -154,7 +149,7 @@ void (*QEGLPlatformContext::getProcAddress(const QByteArray &procName)) ()
return eglGetProcAddress(procName.constData()); return eglGetProcAddress(procName.constData());
} }
QGuiGLFormat QEGLPlatformContext::format() const QSurfaceFormat QEGLPlatformContext::format() const
{ {
return m_format; return m_format;
} }

View File

@ -42,42 +42,35 @@
#ifndef QEGLPLATFORMCONTEXT_H #ifndef QEGLPLATFORMCONTEXT_H
#define QEGLPLATFORMCONTEXT_H #define QEGLPLATFORMCONTEXT_H
#include <QtGui/QPlatformWindow>
#include <QtGui/QPlatformGLContext> #include <QtGui/QPlatformGLContext>
#include <EGL/egl.h> #include <EGL/egl.h>
class QEGLSurface : public QPlatformGLSurface
{
public:
QEGLSurface(EGLSurface surface, const QGuiGLFormat &format);
virtual EGLSurface eglSurface() const { return m_eglSurface; }
private:
EGLSurface m_eglSurface;
};
class QEGLPlatformContext : public QPlatformGLContext class QEGLPlatformContext : public QPlatformGLContext
{ {
public: public:
QEGLPlatformContext(const QGuiGLFormat &format, QPlatformGLContext *share, EGLDisplay display, QEGLPlatformContext(const QSurfaceFormat &format, QPlatformGLContext *share, EGLDisplay display,
EGLint eglClientVersion = 2, EGLenum eglApi = EGL_OPENGL_ES_API); EGLint eglClientVersion = 2, EGLenum eglApi = EGL_OPENGL_ES_API);
~QEGLPlatformContext(); ~QEGLPlatformContext();
bool makeCurrent(const QPlatformGLSurface &surface); bool makeCurrent(QPlatformSurface *surface);
void doneCurrent(); void doneCurrent();
void swapBuffers(const QPlatformGLSurface &surface); void swapBuffers(QPlatformSurface *surface);
void (*getProcAddress(const QByteArray &procName)) (); void (*getProcAddress(const QByteArray &procName)) ();
QGuiGLFormat format() const; QSurfaceFormat format() const;
EGLContext eglContext() const; EGLContext eglContext() const;
protected:
virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0;
private: private:
EGLContext m_eglContext; EGLContext m_eglContext;
EGLDisplay m_eglDisplay; EGLDisplay m_eglDisplay;
EGLenum m_eglApi; EGLenum m_eglApi;
QGuiGLFormat m_format; QSurfaceFormat m_format;
}; };
#endif //QEGLPLATFORMCONTEXT_H #endif //QEGLPLATFORMCONTEXT_H

View File

@ -70,7 +70,7 @@ enum {
#undef FontChange #undef FontChange
#endif #endif
QVector<int> qglx_buildSpec(const QGuiGLFormat &format, int drawableBit) QVector<int> qglx_buildSpec(const QSurfaceFormat &format, int drawableBit)
{ {
QVector<int> spec(48); QVector<int> spec(48);
int i = 0; int i = 0;
@ -88,7 +88,7 @@ QVector<int> qglx_buildSpec(const QGuiGLFormat &format, int drawableBit)
spec[i++] = GLX_ALPHA_SIZE; spec[i++] = format.alphaBufferSize(); spec[i++] = GLX_ALPHA_SIZE; spec[i++] = format.alphaBufferSize();
} }
spec[i++] = GLX_DOUBLEBUFFER; spec[i++] = format.swapBehavior() != QGuiGLFormat::SingleBuffer ? True : False; spec[i++] = GLX_DOUBLEBUFFER; spec[i++] = format.swapBehavior() != QSurfaceFormat::SingleBuffer ? True : False;
spec[i++] = GLX_STEREO; spec[i++] = format.stereo() ? True : False; spec[i++] = GLX_STEREO; spec[i++] = format.stereo() ? True : False;
@ -111,11 +111,11 @@ QVector<int> qglx_buildSpec(const QGuiGLFormat &format, int drawableBit)
return spec; return spec;
} }
GLXFBConfig qglx_findConfig(Display *display, int screen , const QGuiGLFormat &format, int drawableBit) GLXFBConfig qglx_findConfig(Display *display, int screen , const QSurfaceFormat &format, int drawableBit)
{ {
bool reduced = true; bool reduced = true;
GLXFBConfig chosenConfig = 0; GLXFBConfig chosenConfig = 0;
QGuiGLFormat reducedFormat = format; QSurfaceFormat reducedFormat = format;
while (!chosenConfig && reduced) { while (!chosenConfig && reduced) {
QVector<int> spec = qglx_buildSpec(reducedFormat, drawableBit); QVector<int> spec = qglx_buildSpec(reducedFormat, drawableBit);
int confcount = 0; int confcount = 0;
@ -147,7 +147,7 @@ GLXFBConfig qglx_findConfig(Display *display, int screen , const QGuiGLFormat &f
XFree(configs); XFree(configs);
} }
reducedFormat = qglx_reduceGuiGLFormat(reducedFormat,&reduced); reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced);
} }
if (!chosenConfig) if (!chosenConfig)
@ -156,16 +156,16 @@ GLXFBConfig qglx_findConfig(Display *display, int screen , const QGuiGLFormat &f
return chosenConfig; return chosenConfig;
} }
XVisualInfo *qglx_findVisualInfo(Display *display, int screen, const QGuiGLFormat &format) XVisualInfo *qglx_findVisualInfo(Display *display, int screen, const QSurfaceFormat &format)
{ {
GLXFBConfig config = qglx_findConfig(display,screen,format); GLXFBConfig config = qglx_findConfig(display,screen,format);
XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display,config); XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display,config);
return visualInfo; return visualInfo;
} }
QGuiGLFormat qglx_guiGLFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext) QSurfaceFormat qglx_surfaceFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext)
{ {
QGuiGLFormat format; QSurfaceFormat format;
int redSize = 0; int redSize = 0;
int greenSize = 0; int greenSize = 0;
int blueSize = 0; int blueSize = 0;
@ -203,9 +203,9 @@ QGuiGLFormat qglx_guiGLFormatFromGLXFBConfig(Display *display, GLXFBConfig confi
return format; return format;
} }
QGuiGLFormat qglx_reduceGuiGLFormat(const QGuiGLFormat &format, bool *reduced) QSurfaceFormat qglx_reduceSurfaceFormat(const QSurfaceFormat &format, bool *reduced)
{ {
QGuiGLFormat retFormat = format; QSurfaceFormat retFormat = format;
*reduced = true; *reduced = true;
if (retFormat.samples() > 1) { if (retFormat.samples() > 1) {

View File

@ -42,16 +42,16 @@
#ifndef QGLXCONVENIENCE_H #ifndef QGLXCONVENIENCE_H
#define QGLXCONVENIENCE_H #define QGLXCONVENIENCE_H
#include <QGuiGLFormat> #include <QSurfaceFormat>
#include <QVector> #include <QVector>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <GL/glx.h> #include <GL/glx.h>
XVisualInfo *qglx_findVisualInfo(Display *display, int screen, const QGuiGLFormat &format); XVisualInfo *qglx_findVisualInfo(Display *display, int screen, const QSurfaceFormat &format);
GLXFBConfig qglx_findConfig(Display *display, int screen, const QGuiGLFormat &format, int drawableBit = GLX_WINDOW_BIT); GLXFBConfig qglx_findConfig(Display *display, int screen, const QSurfaceFormat &format, int drawableBit = GLX_WINDOW_BIT);
QGuiGLFormat qglx_guiGLFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext context); QSurfaceFormat qglx_surfaceFormatFromGLXFBConfig(Display *display, GLXFBConfig config, GLXContext context);
QVector<int> qglx_buildSpec(const QGuiGLFormat &format, int drawableBit = GLX_WINDOW_BIT); QVector<int> qglx_buildSpec(const QSurfaceFormat &format, int drawableBit = GLX_WINDOW_BIT);
QGuiGLFormat qglx_reduceGuiGLFormat(const QGuiGLFormat &format, bool *reduced); QSurfaceFormat qglx_reduceSurfaceFormat(const QSurfaceFormat &format, bool *reduced);
#endif // QGLXCONVENIENCE_H #endif // QGLXCONVENIENCE_H

View File

@ -10,28 +10,16 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QCocoaGLSurface : public QPlatformGLSurface
{
public:
QCocoaGLSurface(const QGuiGLFormat &format, QWindow *window)
: QPlatformGLSurface(format)
, window(window)
{
}
QWindow *window;
};
class QCocoaGLContext : public QPlatformGLContext class QCocoaGLContext : public QPlatformGLContext
{ {
public: public:
QCocoaGLContext(const QGuiGLFormat &format, QPlatformGLContext *share); QCocoaGLContext(const QSurfaceFormat &format, QPlatformGLContext *share);
QGuiGLFormat format() const; QSurfaceFormat format() const;
void swapBuffers(const QPlatformGLSurface &surface); void swapBuffers(QPlatformSurface *surface);
bool makeCurrent(const QPlatformGLSurface &surface); bool makeCurrent(QPlatformSurface *surface);
void doneCurrent(); void doneCurrent();
void (*getProcAddress(const QByteArray &procName)) (); void (*getProcAddress(const QByteArray &procName)) ();
@ -45,7 +33,7 @@ private:
void setActiveWindow(QWindow *window); void setActiveWindow(QWindow *window);
NSOpenGLContext *m_context; NSOpenGLContext *m_context;
QGuiGLFormat m_format; QSurfaceFormat m_format;
QWeakPointer<QWindow> m_currentWindow; QWeakPointer<QWindow> m_currentWindow;
}; };

View File

@ -5,7 +5,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
QCocoaGLContext::QCocoaGLContext(const QGuiGLFormat &format, QPlatformGLContext *share) QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformGLContext *share)
: m_format(format) : m_format(format)
{ {
NSOpenGLPixelFormat *pixelFormat = createNSOpenGLPixelFormat(); NSOpenGLPixelFormat *pixelFormat = createNSOpenGLPixelFormat();
@ -16,22 +16,22 @@ QCocoaGLContext::QCocoaGLContext(const QGuiGLFormat &format, QPlatformGLContext
} }
// Match up with createNSOpenGLPixelFormat! // Match up with createNSOpenGLPixelFormat!
QGuiGLFormat QCocoaGLContext::format() const QSurfaceFormat QCocoaGLContext::format() const
{ {
return m_format; return m_format;
} }
void QCocoaGLContext::swapBuffers(const QPlatformGLSurface &surface) void QCocoaGLContext::swapBuffers(QPlatformSurface *surface)
{ {
QWindow *window = static_cast<const QCocoaGLSurface &>(surface).window; QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
setActiveWindow(window); setActiveWindow(window);
[m_context flushBuffer]; [m_context flushBuffer];
} }
bool QCocoaGLContext::makeCurrent(const QPlatformGLSurface &surface) bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
{ {
QWindow *window = static_cast<const QCocoaGLSurface &>(surface).window; QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
setActiveWindow(window); setActiveWindow(window);
[m_context makeCurrentContext]; [m_context makeCurrentContext];

View File

@ -78,7 +78,7 @@ public:
bool hasCapability(QPlatformIntegration::Capability cap) const; bool hasCapability(QPlatformIntegration::Capability cap) const;
QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPixmapData *createPixmapData(QPixmapData::PixelType type) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const;
QList<QPlatformScreen *> screens() const { return mScreens; } QList<QPlatformScreen *> screens() const { return mScreens; }

View File

@ -112,7 +112,7 @@ QPlatformWindow *QCocoaIntegration::createPlatformWindow(QWindow *window) const
return new QCocoaWindow(window); return new QCocoaWindow(window);
} }
QPlatformGLContext *QCocoaIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const QPlatformGLContext *QCocoaIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
return new QCocoaGLContext(glFormat, share); return new QCocoaGLContext(glFormat, share);
} }

View File

@ -70,8 +70,6 @@ public:
void windowDidMove(); void windowDidMove();
void windowDidResize(); void windowDidResize();
QPlatformGLSurface *createGLSurface() const;
void setCurrentContext(QCocoaGLContext *context); void setCurrentContext(QCocoaGLContext *context);
QCocoaGLContext *currentContext() const; QCocoaGLContext *currentContext() const;

View File

@ -157,12 +157,6 @@ void QCocoaWindow::windowDidResize()
m_glContext->update(); m_glContext->update();
} }
QPlatformGLSurface *QCocoaWindow::createGLSurface() const
{
Q_ASSERT(window()->surfaceType() == QWindow::OpenGLSurface);
return new QCocoaGLSurface(window()->glFormat(), window());
}
void QCocoaWindow::setCurrentContext(QCocoaGLContext *context) void QCocoaWindow::setCurrentContext(QCocoaGLContext *context)
{ {
m_glContext = context; m_glContext = context;

View File

@ -47,7 +47,7 @@ class QWaylandDisplay;
class QWindow; class QWindow;
class QPlatformGLContext; class QPlatformGLContext;
class QGuiGLFormat; class QSurfaceFormat;
class QWaylandGLIntegration class QWaylandGLIntegration
{ {
@ -58,7 +58,7 @@ public:
virtual void initialize() = 0; virtual void initialize() = 0;
virtual QWaylandWindow *createEglWindow(QWindow *window) = 0; virtual QWaylandWindow *createEglWindow(QWindow *window) = 0;
virtual QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const = 0; virtual QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const = 0;
static QWaylandGLIntegration *createGLIntegration(QWaylandDisplay *waylandDisplay); static QWaylandGLIntegration *createGLIntegration(QWaylandDisplay *waylandDisplay);
}; };

View File

@ -86,7 +86,7 @@ QWaylandWindow * QWaylandReadbackEglIntegration::createEglWindow(QWindow *window
return new QWaylandReadbackEglWindow(window, this); return new QWaylandReadbackEglWindow(window, this);
} }
QPlatformGLContext *QWaylandReadbackEglWindow::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const QPlatformGLContext *QWaylandReadbackEglWindow::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
return new QWaylandReadbackEglContext(glFormat, share, this); return new QWaylandReadbackEglContext(glFormat, share, this);
} }

View File

@ -63,7 +63,7 @@ public:
void initialize(); void initialize();
QWaylandWindow *createEglWindow(QWindow *window); QWaylandWindow *createEglWindow(QWindow *window);
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QWaylandDisplay *waylandDisplay() const; QWaylandDisplay *waylandDisplay() const;
Display *xDisplay() const; Display *xDisplay() const;

View File

@ -47,16 +47,6 @@
#include <QtGui/QGuiGLContext> #include <QtGui/QGuiGLContext>
#include <QtCore/QDebug> #include <QtCore/QDebug>
QWaylandReadbackGlxSurface::QWaylandReadbackGlxSurface(QWaylandReadbackGlxWindow *window)
: m_window(window)
{
}
GLXPixmap QWaylandReadbackGlxSurface::glxPixmap() const
{
return m_window->glxPixmap();
}
static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type) static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type)
{ {
const int width = img.width(); const int width = img.width();
@ -79,7 +69,7 @@ static inline void qgl_byteSwapImage(QImage &img, GLenum pixel_type)
} }
} }
QWaylandReadbackGlxContext::QWaylandReadbackGlxContext(const QGuiGLFormat &format, QWaylandReadbackGlxContext::QWaylandReadbackGlxContext(const QSurfaceFormat &format,
QPlatformGLContext *share, Display *display, int screen) QPlatformGLContext *share, Display *display, int screen)
: m_display(display) : m_display(display)
{ {
@ -89,17 +79,17 @@ QWaylandReadbackGlxContext::QWaylandReadbackGlxContext(const QGuiGLFormat &forma
XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display, config); XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display, config);
m_context = glXCreateContext(display, visualInfo, shareContext, TRUE); m_context = glXCreateContext(display, visualInfo, shareContext, TRUE);
m_format = qglx_guiGLFormatFromGLXFBConfig(display, config, m_context); m_format = qglx_surfaceFormatFromGLXFBConfig(display, config, m_context);
} }
QGuiGLFormat QWaylandReadbackGlxContext::format() const QSurfaceFormat QWaylandReadbackGlxContext::format() const
{ {
return m_format; return m_format;
} }
bool QWaylandReadbackGlxContext::makeCurrent(const QPlatformGLSurface &surface) bool QWaylandReadbackGlxContext::makeCurrent(QPlatformSurface *surface)
{ {
GLXPixmap glxPixmap = static_cast<const QWaylandReadbackGlxSurface &>(surface).glxPixmap(); GLXPixmap glxPixmap = static_cast<QWaylandReadbackGlxWindow *>(surface)->glxPixmap();
return glXMakeCurrent(m_display, glxPixmap, m_context); return glXMakeCurrent(m_display, glxPixmap, m_context);
} }
@ -109,16 +99,15 @@ void QWaylandReadbackGlxContext::doneCurrent()
glXMakeCurrent(m_display, 0, 0); glXMakeCurrent(m_display, 0, 0);
} }
void QWaylandReadbackGlxContext::swapBuffers(const QPlatformGLSurface &surface) void QWaylandReadbackGlxContext::swapBuffers(QPlatformSurface *surface)
{ {
// #### makeCurrent() directly on the platform context doesn't update QGuiGLContext::currentContext() // #### makeCurrent() directly on the platform context doesn't update QGuiGLContext::currentContext()
if (QGuiGLContext::currentContext()->handle() != this) if (QGuiGLContext::currentContext()->handle() != this)
makeCurrent(surface); makeCurrent(surface);
const QWaylandReadbackGlxSurface &s = QWaylandReadbackGlxWindow *w = static_cast<QWaylandReadbackGlxWindow *>(surface);
static_cast<const QWaylandReadbackGlxSurface &>(surface);
QSize size = s.window()->geometry().size(); QSize size = w->geometry().size();
QImage img(size, QImage::Format_ARGB32); QImage img(size, QImage::Format_ARGB32);
const uchar *constBits = img.bits(); const uchar *constBits = img.bits();
@ -130,13 +119,13 @@ void QWaylandReadbackGlxContext::swapBuffers(const QPlatformGLSurface &surface)
qgl_byteSwapImage(img, GL_UNSIGNED_INT_8_8_8_8_REV); qgl_byteSwapImage(img, GL_UNSIGNED_INT_8_8_8_8_REV);
constBits = img.bits(); constBits = img.bits();
const uchar *constDstBits = s.window()->buffer(); const uchar *constDstBits = w->buffer();
uchar *dstBits = const_cast<uchar *>(constDstBits); uchar *dstBits = const_cast<uchar *>(constDstBits);
memcpy(dstBits, constBits, (img.width() * 4) * img.height()); memcpy(dstBits, constBits, (img.width() * 4) * img.height());
s.window()->damage(QRect(QPoint(), size)); w->damage(QRect(QPoint(), size));
s.window()->waitForFrameSync(); w->waitForFrameSync();
} }
void (*QWaylandReadbackGlxContext::getProcAddress(const QByteArray &procName)) () void (*QWaylandReadbackGlxContext::getProcAddress(const QByteArray &procName)) ()

View File

@ -43,7 +43,7 @@
#define QWAYLANDREADBACKGLXCONTEXT_H #define QWAYLANDREADBACKGLXCONTEXT_H
#include <QPlatformGLContext> #include <QPlatformGLContext>
#include <QGuiGLFormat> #include <QSurfaceFormat>
#include "qwaylandreadbackglxintegration.h" #include "qwaylandreadbackglxintegration.h"
@ -52,28 +52,16 @@
class QWaylandReadbackGlxWindow; class QWaylandReadbackGlxWindow;
class QWaylandShmBuffer; class QWaylandShmBuffer;
class QWaylandReadbackGlxSurface : public QPlatformGLSurface
{
public:
QWaylandReadbackGlxSurface(QWaylandReadbackGlxWindow *window);
QWaylandReadbackGlxWindow *window() const { return m_window; }
GLXPixmap glxPixmap() const;
private:
QWaylandReadbackGlxWindow *m_window;
};
class QWaylandReadbackGlxContext : public QPlatformGLContext class QWaylandReadbackGlxContext : public QPlatformGLContext
{ {
public: public:
QWaylandReadbackGlxContext(const QGuiGLFormat &format, QPlatformGLContext *share, Display *display, int screen); QWaylandReadbackGlxContext(const QSurfaceFormat &format, QPlatformGLContext *share, Display *display, int screen);
QGuiGLFormat format() const; QSurfaceFormat format() const;
void swapBuffers(const QPlatformGLSurface &surface); void swapBuffers(QPlatformSurface *surface);
bool makeCurrent(const QPlatformGLSurface &surface); bool makeCurrent(QPlatformSurface *surface);
void doneCurrent(); void doneCurrent();
void (*getProcAddress(const QByteArray &procName)) (); void (*getProcAddress(const QByteArray &procName)) ();
@ -82,7 +70,7 @@ private:
GLXContext m_context; GLXContext m_context;
Display *m_display; Display *m_display;
QGuiGLFormat m_format; QSurfaceFormat m_format;
}; };
#endif // QWAYLANDREADBACKGLXCONTEXT_H #endif // QWAYLANDREADBACKGLXCONTEXT_H

View File

@ -71,7 +71,7 @@ QWaylandWindow * QWaylandReadbackGlxIntegration::createEglWindow(QWindow *window
return new QWaylandReadbackGlxWindow(window,this); return new QWaylandReadbackGlxWindow(window,this);
} }
QPlatformGLContext *QWaylandReadbackGlxIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const QPlatformGLContext *QWaylandReadbackGlxIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
return new QWaylandReadbackGlxContext(glFormat, share, mDisplay, mScreen); return new QWaylandReadbackGlxContext(glFormat, share, mDisplay, mScreen);
} }

View File

@ -61,7 +61,7 @@ public:
void initialize(); void initialize();
QWaylandWindow *createEglWindow(QWindow *window); QWaylandWindow *createEglWindow(QWindow *window);
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QWaylandDisplay *waylandDisplay() const; QWaylandDisplay *waylandDisplay() const;

View File

@ -86,11 +86,6 @@ uchar *QWaylandReadbackGlxWindow::buffer()
return m_buffer->image()->bits(); return m_buffer->image()->bits();
} }
QPlatformGLSurface *QWaylandReadbackGlxWindow::createGLSurface() const
{
return new QWaylandReadbackGlxSurface(const_cast<QWaylandReadbackGlxWindow *>(this));
}
void QWaylandReadbackGlxWindow::createSurface() void QWaylandReadbackGlxWindow::createSurface()
{ {
QSize size(geometry().size()); QSize size(geometry().size());

View File

@ -52,8 +52,6 @@ public:
QWaylandReadbackGlxWindow(QWindow *window, QWaylandReadbackGlxIntegration *glxIntegration); QWaylandReadbackGlxWindow(QWindow *window, QWaylandReadbackGlxIntegration *glxIntegration);
WindowType windowType() const; WindowType windowType() const;
QPlatformGLSurface *createGLSurface() const;
void setGeometry(const QRect &rect); void setGeometry(const QRect &rect);
Pixmap glxPixmap() const; Pixmap glxPixmap() const;

View File

@ -48,31 +48,25 @@
#include <QtPlatformSupport/private/qeglconvenience_p.h> #include <QtPlatformSupport/private/qeglconvenience_p.h>
QWaylandXCompositeEGLSurface::QWaylandXCompositeEGLSurface(QWaylandXCompositeEGLWindow *window) QWaylandXCompositeEGLContext::QWaylandXCompositeEGLContext(const QSurfaceFormat &format, QPlatformGLContext *share, EGLDisplay display)
: QEGLSurface(window->eglSurface(), window->window()->glFormat())
, m_window(window)
{
}
EGLSurface QWaylandXCompositeEGLSurface::eglSurface() const
{
return m_window->eglSurface();
}
QWaylandXCompositeEGLContext::QWaylandXCompositeEGLContext(const QGuiGLFormat &format, QPlatformGLContext *share, EGLDisplay display)
: QEGLPlatformContext(format, share, display) : QEGLPlatformContext(format, share, display)
{ {
} }
void QWaylandXCompositeEGLContext::swapBuffers(const QPlatformGLSurface &surface) void QWaylandXCompositeEGLContext::swapBuffers(QPlatformSurface *surface)
{ {
QEGLPlatformContext::swapBuffers(surface); QEGLPlatformContext::swapBuffers(surface);
const QWaylandXCompositeEGLSurface &s = QWaylandXCompositeEGLWindow *w =
static_cast<const QWaylandXCompositeEGLSurface &>(surface); static_cast<QWaylandXCompositeEGLWindow *>(surface);
QSize size = s.window()->geometry().size(); QSize size = w->geometry().size();
s.window()->damage(QRect(QPoint(), size)); w->damage(QRect(QPoint(), size));
s.window()->waitForFrameSync(); w->waitForFrameSync();
}
EGLSurface QWaylandXCompositeEGLContext::eglSurfaceForPlatformSurface(QPlatformSurface *surface)
{
return static_cast<QWaylandXCompositeEGLWindow *>(surface)->eglSurface();
} }

View File

@ -50,23 +50,15 @@
class QWaylandXCompositeEGLWindow; class QWaylandXCompositeEGLWindow;
class QWaylandXCompositeEGLSurface : public QEGLSurface
{
public:
QWaylandXCompositeEGLSurface(QWaylandXCompositeEGLWindow *window);
EGLSurface eglSurface() const;
QWaylandXCompositeEGLWindow *window() const { return m_window; }
private:
QWaylandXCompositeEGLWindow *m_window;
};
class QWaylandXCompositeEGLContext : public QEGLPlatformContext class QWaylandXCompositeEGLContext : public QEGLPlatformContext
{ {
public: public:
QWaylandXCompositeEGLContext(const QGuiGLFormat &format, QPlatformGLContext *share, EGLDisplay display); QWaylandXCompositeEGLContext(const QSurfaceFormat &format, QPlatformGLContext *share, EGLDisplay display);
void swapBuffers(const QPlatformGLSurface &surface); void swapBuffers(QPlatformSurface *surface);
private:
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface);
}; };
#endif // QWAYLANDXCOMPOSITEEGLCONTEXT_H #endif // QWAYLANDXCOMPOSITEEGLCONTEXT_H

View File

@ -75,7 +75,7 @@ QWaylandWindow * QWaylandXCompositeEGLIntegration::createEglWindow(QWindow *wind
return new QWaylandXCompositeEGLWindow(window,this); return new QWaylandXCompositeEGLWindow(window,this);
} }
QPlatformGLContext *QWaylandXCompositeEGLIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const QPlatformGLContext *QWaylandXCompositeEGLIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
return new QWaylandXCompositeEGLContext(glFormat, share, eglDisplay()); return new QWaylandXCompositeEGLContext(glFormat, share, eglDisplay());
} }

View File

@ -69,7 +69,7 @@ public:
void initialize(); void initialize();
QWaylandWindow *createEglWindow(QWindow *window); QWaylandWindow *createEglWindow(QWindow *window);
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QWaylandDisplay *waylandDisplay() const; QWaylandDisplay *waylandDisplay() const;
struct wl_xcomposite *waylandXComposite() const; struct wl_xcomposite *waylandXComposite() const;

View File

@ -57,7 +57,7 @@ QWaylandXCompositeEGLWindow::QWaylandXCompositeEGLWindow(QWindow *window, QWayla
, m_context(0) , m_context(0)
, m_buffer(0) , m_buffer(0)
, m_xWindow(0) , m_xWindow(0)
, m_config(q_configFromGLFormat(glxIntegration->eglDisplay(), window->glFormat(), true)) , m_config(q_configFromGLFormat(glxIntegration->eglDisplay(), window->format(), true))
, m_surface(0) , m_surface(0)
, m_waitingForSync(false) , m_waitingForSync(false)
{ {
@ -69,11 +69,6 @@ QWaylandWindow::WindowType QWaylandXCompositeEGLWindow::windowType() const
return QWaylandWindow::Egl; return QWaylandWindow::Egl;
} }
QPlatformGLSurface *QWaylandXCompositeEGLWindow::createGLSurface() const
{
return new QWaylandXCompositeEGLSurface(const_cast<QWaylandXCompositeEGLWindow *>(this));
}
void QWaylandXCompositeEGLWindow::setGeometry(const QRect &rect) void QWaylandXCompositeEGLWindow::setGeometry(const QRect &rect)
{ {
QWaylandWindow::setGeometry(rect); QWaylandWindow::setGeometry(rect);

View File

@ -54,8 +54,6 @@ public:
QWaylandXCompositeEGLWindow(QWindow *window, QWaylandXCompositeEGLIntegration *glxIntegration); QWaylandXCompositeEGLWindow(QWindow *window, QWaylandXCompositeEGLIntegration *glxIntegration);
WindowType windowType() const; WindowType windowType() const;
QPlatformGLSurface *createGLSurface() const;
void setGeometry(const QRect &rect); void setGeometry(const QRect &rect);
EGLSurface eglSurface() const; EGLSurface eglSurface() const;

View File

@ -47,17 +47,7 @@
#include <QRegion> #include <QRegion>
QWaylandXCompositeGLXSurface::QWaylandXCompositeGLXSurface(QWaylandXCompositeGLXWindow *window) QWaylandXCompositeGLXContext::QWaylandXCompositeGLXContext(const QSurfaceFormat &format, QPlatformGLContext *share, Display *display, int screen)
: m_window(window)
{
}
Window QWaylandXCompositeGLXSurface::xWindow() const
{
return m_window->xWindow();
}
QWaylandXCompositeGLXContext::QWaylandXCompositeGLXContext(const QGuiGLFormat &format, QPlatformGLContext *share, Display *display, int screen)
: m_display(display) : m_display(display)
{ {
qDebug("creating XComposite-GLX context"); qDebug("creating XComposite-GLX context");
@ -65,12 +55,12 @@ QWaylandXCompositeGLXContext::QWaylandXCompositeGLXContext(const QGuiGLFormat &f
GLXFBConfig config = qglx_findConfig(display, screen, format); GLXFBConfig config = qglx_findConfig(display, screen, format);
XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display, config); XVisualInfo *visualInfo = glXGetVisualFromFBConfig(display, config);
m_context = glXCreateContext(display, visualInfo, shareContext, true); m_context = glXCreateContext(display, visualInfo, shareContext, true);
m_format = qglx_guiGLFormatFromGLXFBConfig(display, config, m_context); m_format = qglx_surfaceFormatFromGLXFBConfig(display, config, m_context);
} }
bool QWaylandXCompositeGLXContext::makeCurrent(const QPlatformGLSurface &surface) bool QWaylandXCompositeGLXContext::makeCurrent(QPlatformSurface *surface)
{ {
Window xWindow = static_cast<const QWaylandXCompositeGLXSurface &>(surface).xWindow(); Window xWindow = static_cast<QWaylandXCompositeGLXWindow *>(surface)->xWindow();
return glXMakeCurrent(m_display, xWindow, m_context); return glXMakeCurrent(m_display, xWindow, m_context);
} }
@ -80,17 +70,16 @@ void QWaylandXCompositeGLXContext::doneCurrent()
glXMakeCurrent(m_display, 0, 0); glXMakeCurrent(m_display, 0, 0);
} }
void QWaylandXCompositeGLXContext::swapBuffers(const QPlatformGLSurface &surface) void QWaylandXCompositeGLXContext::swapBuffers(QPlatformSurface *surface)
{ {
const QWaylandXCompositeGLXSurface &s = QWaylandXCompositeGLXWindow *w = static_cast<QWaylandXCompositeGLXWindow *>(surface);
static_cast<const QWaylandXCompositeGLXSurface &>(surface);
QSize size = s.window()->geometry().size(); QSize size = w->geometry().size();
glXSwapBuffers(m_display, s.xWindow()); glXSwapBuffers(m_display, w->xWindow());
s.window()->damage(QRect(QPoint(), size)); w->damage(QRect(QPoint(), size));
s.window()->waitForFrameSync(); w->waitForFrameSync();
} }
void (*QWaylandXCompositeGLXContext::getProcAddress(const QByteArray &procName)) () void (*QWaylandXCompositeGLXContext::getProcAddress(const QByteArray &procName)) ()
@ -98,7 +87,7 @@ void (*QWaylandXCompositeGLXContext::getProcAddress(const QByteArray &procName))
return glXGetProcAddress(reinterpret_cast<const GLubyte *>(procName.constData())); return glXGetProcAddress(reinterpret_cast<const GLubyte *>(procName.constData()));
} }
QGuiGLFormat QWaylandXCompositeGLXContext::format() const QSurfaceFormat QWaylandXCompositeGLXContext::format() const
{ {
return m_format; return m_format;
} }

View File

@ -50,29 +50,16 @@
class QWaylandXCompositeGLXWindow; class QWaylandXCompositeGLXWindow;
class QWaylandShmBuffer; class QWaylandShmBuffer;
class QWaylandXCompositeGLXSurface : public QPlatformGLSurface
{
public:
QWaylandXCompositeGLXSurface(QWaylandXCompositeGLXWindow *window);
QWaylandXCompositeGLXWindow *window() const { return m_window; }
Window xWindow() const;
private:
QWaylandXCompositeGLXWindow *m_window;
};
class QWaylandXCompositeGLXContext : public QPlatformGLContext class QWaylandXCompositeGLXContext : public QPlatformGLContext
{ {
public: public:
QWaylandXCompositeGLXContext(const QGuiGLFormat &format, QPlatformGLContext *share, Display *display, int screen); QWaylandXCompositeGLXContext(const QSurfaceFormat &format, QPlatformGLContext *share, Display *display, int screen);
QGuiGLFormat format() const; QSurfaceFormat format() const;
void swapBuffers(const QPlatformGLSurface &surface); void swapBuffers(QPlatformSurface *surface);
bool makeCurrent(const QPlatformGLSurface &surface); bool makeCurrent(QPlatformSurface *surface);
void doneCurrent(); void doneCurrent();
void (*getProcAddress(const QByteArray &procName)) (); void (*getProcAddress(const QByteArray &procName)) ();
@ -81,7 +68,7 @@ private:
GLXContext m_context; GLXContext m_context;
Display *m_display; Display *m_display;
QGuiGLFormat m_format; QSurfaceFormat m_format;
}; };
#endif // QWAYLANDXCOMPOSITEGLXCONTEXT_H #endif // QWAYLANDXCOMPOSITEGLXCONTEXT_H

View File

@ -78,7 +78,7 @@ QWaylandWindow * QWaylandXCompositeGLXIntegration::createEglWindow(QWindow *wind
return new QWaylandXCompositeGLXWindow(window, this); return new QWaylandXCompositeGLXWindow(window, this);
} }
QPlatformGLContext *QWaylandXCompositeGLXIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const QPlatformGLContext *QWaylandXCompositeGLXIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
return new QWaylandXCompositeGLXContext(glFormat, share, mDisplay, mScreen); return new QWaylandXCompositeGLXContext(glFormat, share, mDisplay, mScreen);
} }

View File

@ -64,7 +64,7 @@ public:
void initialize(); void initialize();
QWaylandWindow *createEglWindow(QWindow *window); QWaylandWindow *createEglWindow(QWindow *window);
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QWaylandDisplay *waylandDisplay() const; QWaylandDisplay *waylandDisplay() const;
struct wl_xcomposite *waylandXComposite() const; struct wl_xcomposite *waylandXComposite() const;

View File

@ -54,7 +54,7 @@ QWaylandXCompositeGLXWindow::QWaylandXCompositeGLXWindow(QWindow *window, QWayla
: QWaylandWindow(window) : QWaylandWindow(window)
, m_glxIntegration(glxIntegration) , m_glxIntegration(glxIntegration)
, m_xWindow(0) , m_xWindow(0)
, m_config(qglx_findConfig(glxIntegration->xDisplay(), glxIntegration->screen(), window->glFormat())) , m_config(qglx_findConfig(glxIntegration->xDisplay(), glxIntegration->screen(), window->format()))
, m_buffer(0) , m_buffer(0)
, m_waitingForSync(false) , m_waitingForSync(false)
{ {
@ -66,11 +66,6 @@ QWaylandWindow::WindowType QWaylandXCompositeGLXWindow::windowType() const
return QWaylandWindow::Egl; return QWaylandWindow::Egl;
} }
QPlatformGLSurface *QWaylandXCompositeGLXWindow::createGLSurface() const
{
return new QWaylandXCompositeGLXSurface(const_cast<QWaylandXCompositeGLXWindow *>(this));
}
void QWaylandXCompositeGLXWindow::setGeometry(const QRect &rect) void QWaylandXCompositeGLXWindow::setGeometry(const QRect &rect)
{ {
QWaylandWindow::setGeometry(rect); QWaylandWindow::setGeometry(rect);

View File

@ -56,8 +56,6 @@ public:
QWaylandXCompositeGLXWindow(QWindow *window, QWaylandXCompositeGLXIntegration *glxIntegration); QWaylandXCompositeGLXWindow(QWindow *window, QWaylandXCompositeGLXIntegration *glxIntegration);
WindowType windowType() const; WindowType windowType() const;
QPlatformGLSurface *createGLSurface() const;
void setGeometry(const QRect &rect); void setGeometry(const QRect &rect);
Window xWindow() const; Window xWindow() const;

View File

@ -51,7 +51,7 @@
#include <QtGui/QWindowSystemInterface> #include <QtGui/QWindowSystemInterface>
#include <QtGui/QPlatformCursor> #include <QtGui/QPlatformCursor>
#include <QtGui/QGuiGLFormat> #include <QtGui/QSurfaceFormat>
#include <QtGui/private/qpixmap_raster_p.h> #include <QtGui/private/qpixmap_raster_p.h>
@ -100,18 +100,19 @@ QPixmapData *QWaylandIntegration::createPixmapData(QPixmapData::PixelType type)
QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const QPlatformWindow *QWaylandIntegration::createPlatformWindow(QWindow *window) const
{ {
#ifdef QT_WAYLAND_GL_SUPPORT #ifdef QT_WAYLAND_GL_SUPPORT
if (window->surfaceType() == QWindow::OpenGLSurface) return mDisplay->eglIntegration()->createEglWindow(window);
return mDisplay->eglIntegration()->createEglWindow(window); #else
#endif
return new QWaylandShmWindow(window); return new QWaylandShmWindow(window);
#endif
} }
QPlatformGLContext *QWaylandIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const QPlatformGLContext *QWaylandIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
#ifdef QT_WAYLAND_GL_SUPPORT #ifdef QT_WAYLAND_GL_SUPPORT
return mDisplay->eglIntegration()->createPlatformGLContext(glFormat, share); return mDisplay->eglIntegration()->createPlatformGLContext(glFormat, share);
#else #else
Q_UNUSED(glFormat);
Q_UNUSED(share);
return 0; return 0;
#endif #endif
} }

View File

@ -57,7 +57,7 @@ public:
bool hasCapability(QPlatformIntegration::Capability cap) const; bool hasCapability(QPlatformIntegration::Capability cap) const;
QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPixmapData *createPixmapData(QPixmapData::PixelType type) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QList<QPlatformScreen *> screens() const; QList<QPlatformScreen *> screens() const;

View File

@ -63,9 +63,3 @@ QWaylandWindow::WindowType QWaylandShmWindow::windowType() const
return QWaylandWindow::Shm; return QWaylandWindow::Shm;
} }
QPlatformGLSurface * QWaylandShmWindow::glSurface() const
{
qWarning("Raster window does not have a GL drawable");
return 0;
}

View File

@ -52,7 +52,7 @@ public:
~QWaylandShmWindow(); ~QWaylandShmWindow();
WindowType windowType() const; WindowType windowType() const;
QPlatformGLSurface *glSurface() const; QSurfaceFormat format() const { return window()->format(); }
}; };
#endif // QWAYLANDSHMWINDOW_H #endif // QWAYLANDSHMWINDOW_H

View File

@ -59,13 +59,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
QGLXSurface::QGLXSurface(GLXDrawable drawable, const QGuiGLFormat &format) QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformGLContext *share)
: QPlatformGLSurface(format)
, glxDrawable(drawable)
{
}
QGLXContext::QGLXContext(QXcbScreen *screen, const QGuiGLFormat &format, QPlatformGLContext *share)
: QPlatformGLContext() : QPlatformGLContext()
, m_screen(screen) , m_screen(screen)
, m_context(0) , m_context(0)
@ -77,7 +71,7 @@ QGLXContext::QGLXContext(QXcbScreen *screen, const QGuiGLFormat &format, QPlatfo
GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),format); GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),format);
m_context = glXCreateNewContext(DISPLAY_FROM_XCB(screen), config, GLX_RGBA_TYPE, shareGlxContext, TRUE); m_context = glXCreateNewContext(DISPLAY_FROM_XCB(screen), config, GLX_RGBA_TYPE, shareGlxContext, TRUE);
m_format = qglx_guiGLFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context); m_format = qglx_surfaceFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context);
Q_XCB_NOOP(m_screen->connection()); Q_XCB_NOOP(m_screen->connection());
} }
@ -88,13 +82,15 @@ QGLXContext::~QGLXContext()
Q_XCB_NOOP(m_screen->connection()); Q_XCB_NOOP(m_screen->connection());
} }
bool QGLXContext::makeCurrent(const QPlatformGLSurface &surface) bool QGLXContext::makeCurrent(QPlatformSurface *surface)
{ {
Q_ASSERT(surface);
Q_XCB_NOOP(m_screen->connection()); Q_XCB_NOOP(m_screen->connection());
GLXDrawable glxSurface = static_cast<const QGLXSurface &>(surface).glxDrawable; GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window();
bool result = glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), glxSurface, m_context); bool result = glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), glxDrawable, m_context);
Q_XCB_NOOP(m_screen->connection()); Q_XCB_NOOP(m_screen->connection());
return result; return result;
@ -105,10 +101,10 @@ void QGLXContext::doneCurrent()
glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0); glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0);
} }
void QGLXContext::swapBuffers(const QPlatformGLSurface &drawable) void QGLXContext::swapBuffers(QPlatformSurface *surface)
{ {
Q_XCB_NOOP(m_screen->connection()); Q_XCB_NOOP(m_screen->connection());
GLXDrawable glxDrawable = static_cast<const QGLXSurface &>(drawable).glxDrawable; GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window();
glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), glxDrawable); glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), glxDrawable);
Q_XCB_NOOP(m_screen->connection()); Q_XCB_NOOP(m_screen->connection());
} }
@ -147,7 +143,7 @@ void (*QGLXContext::getProcAddress(const QByteArray &procName)) ()
return (void (*)())glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.constData())); return (void (*)())glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.constData()));
} }
QGuiGLFormat QGLXContext::format() const QSurfaceFormat QGLXContext::format() const
{ {
return m_format; return m_format;
} }

View File

@ -43,40 +43,34 @@
#define QGLXINTEGRATION_H #define QGLXINTEGRATION_H
#include "qxcbwindow.h" #include "qxcbwindow.h"
#include "qxcbscreen.h"
#include <QtGui/QPlatformGLContext> #include <QtGui/QPlatformGLContext>
#include <QtGui/QGuiGLFormat> #include <QtGui/QSurfaceFormat>
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <GL/glx.h> #include <GL/glx.h>
class QGLXSurface : public QPlatformGLSurface
{
public:
QGLXSurface(GLXDrawable drawable, const QGuiGLFormat &format);
GLXDrawable glxDrawable;
};
class QGLXContext : public QPlatformGLContext class QGLXContext : public QPlatformGLContext
{ {
public: public:
QGLXContext(QXcbScreen *xd, const QGuiGLFormat &format, QPlatformGLContext *share); QGLXContext(QXcbScreen *xd, const QSurfaceFormat &format, QPlatformGLContext *share);
~QGLXContext(); ~QGLXContext();
bool makeCurrent(const QPlatformGLSurface &surface); bool makeCurrent(QPlatformSurface *surface);
void doneCurrent(); void doneCurrent();
void swapBuffers(const QPlatformGLSurface &surface); void swapBuffers(QPlatformSurface *surface);
void (*getProcAddress(const QByteArray &procName)) (); void (*getProcAddress(const QByteArray &procName)) ();
QGuiGLFormat format() const; QSurfaceFormat format() const;
GLXContext glxContext() const { return m_context; } GLXContext glxContext() const { return m_context; }
private: private:
QXcbScreen *m_screen; QXcbScreen *m_screen;
GLXContext m_context; GLXContext m_context;
QGuiGLFormat m_format; QSurfaceFormat m_format;
}; };
#endif #endif

View File

@ -260,7 +260,7 @@ void QXcbBackingStore::resize(const QSize &size, const QRegion &)
QXcbWindow* win = static_cast<QXcbWindow *>(window()->handle()); QXcbWindow* win = static_cast<QXcbWindow *>(window()->handle());
delete m_image; delete m_image;
m_image = new QXcbShmImage(screen, size, win->depth(), win->format()); m_image = new QXcbShmImage(screen, size, win->depth(), win->imageFormat());
Q_XCB_NOOP(connection()); Q_XCB_NOOP(connection());
m_syncingResize = true; m_syncingResize = true;

View File

@ -39,6 +39,9 @@
** **
****************************************************************************/ ****************************************************************************/
#include <QtGui/private/qguiapplication_p.h>
#include <QtCore/QDebug>
#include "qxcbconnection.h" #include "qxcbconnection.h"
#include "qxcbkeyboard.h" #include "qxcbkeyboard.h"
#include "qxcbscreen.h" #include "qxcbscreen.h"
@ -49,11 +52,8 @@
#include <QtAlgorithms> #include <QtAlgorithms>
#include <QSocketNotifier> #include <QSocketNotifier>
#include <QtGui/private/qguiapplication_p.h>
#include <QAbstractEventDispatcher> #include <QAbstractEventDispatcher>
#include <QtCore/QDebug>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <xcb/xfixes.h> #include <xcb/xfixes.h>
@ -108,7 +108,7 @@ QXcbConnection::QXcbConnection(const char *displayName)
m_has_egl = eglInitialize(eglDisplay,&major,&minor); m_has_egl = eglInitialize(eglDisplay,&major,&minor);
#endif //XCB_USE_EGL #endif //XCB_USE_EGL
#else #else
m_connection = xcb_connect(m_displayName.constData(), &primaryScreen); m_connection = xcb_connect(m_displayName.constData(), &m_primaryScreen);
#endif //XCB_USE_XLIB #endif //XCB_USE_XLIB
xcb_prefetch_extension_data (m_connection, &xcb_xfixes_id); xcb_prefetch_extension_data (m_connection, &xcb_xfixes_id);

View File

@ -0,0 +1,68 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QXCBEGLSURFACE_H
#define QXCBEGLSURFACE_H
#include <EGL/egl.h>
class QXcbEGLSurface
{
public:
QXcbEGLSurface(EGLDisplay display, EGLSurface surface)
: m_display(display)
, m_surface(surface)
{
}
~QXcbEGLSurface()
{
eglDestroySurface(m_display, m_surface);
}
EGLSurface surface() const { return m_surface; }
private:
EGLDisplay m_display;
EGLSurface m_surface;
};
#endif

View File

@ -66,6 +66,7 @@
#if defined(XCB_USE_GLX) #if defined(XCB_USE_GLX)
#include "qglxintegration.h" #include "qglxintegration.h"
#elif defined(XCB_USE_EGL) #elif defined(XCB_USE_EGL)
#include "qxcbeglsurface.h"
#include <QtPlatformSupport/private/qeglplatformcontext_p.h> #include <QtPlatformSupport/private/qeglplatformcontext_p.h>
#endif #endif
@ -103,12 +104,28 @@ QPlatformWindow *QXcbIntegration::createPlatformWindow(QWindow *window) const
return new QXcbWindow(window); return new QXcbWindow(window);
} }
QPlatformGLContext *QXcbIntegration::createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const #if defined(XCB_USE_EGL)
class QEGLXcbPlatformContext : public QEGLPlatformContext
{
public:
QEGLXcbPlatformContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share, EGLDisplay display)
: QEGLPlatformContext(glFormat, share, display)
{
}
EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface)
{
return static_cast<QXcbWindow *>(surface)->eglSurface()->surface();
}
};
#endif
QPlatformGLContext *QXcbIntegration::createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const
{ {
#if defined(XCB_USE_GLX) #if defined(XCB_USE_GLX)
return new QGLXContext(static_cast<QXcbScreen *>(m_screens.at(0)), glFormat, share); return new QGLXContext(static_cast<QXcbScreen *>(m_screens.at(0)), glFormat, share);
#elif defined(XCB_USE_EGL) #elif defined(XCB_USE_EGL)
return new QEGLPlatformContext(glFormat, share, m_connection->egl_display()); return new QEGLXcbPlatformContext(glFormat, share, m_connection->egl_display());
#elif defined(XCB_USE_DRI2) #elif defined(XCB_USE_DRI2)
return new QDri2Context(glFormat, share); return new QDri2Context(glFormat, share);
#endif #endif

View File

@ -58,7 +58,7 @@ public:
bool hasCapability(Capability cap) const; bool hasCapability(Capability cap) const;
QPixmapData *createPixmapData(QPixmapData::PixelType type) const; QPixmapData *createPixmapData(QPixmapData::PixelType type) const;
QPlatformWindow *createPlatformWindow(QWindow *window) const; QPlatformWindow *createPlatformWindow(QWindow *window) const;
QPlatformGLContext *createPlatformGLContext(const QGuiGLFormat &glFormat, QPlatformGLContext *share) const; QPlatformGLContext *createPlatformGLContext(const QSurfaceFormat &glFormat, QPlatformGLContext *share) const;
QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const; QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;
QList<QPlatformScreen *> screens() const; QList<QPlatformScreen *> screens() const;

View File

@ -71,7 +71,7 @@
#include "qglxintegration.h" #include "qglxintegration.h"
#include <QtPlatformSupport/private/qglxconvenience_p.h> #include <QtPlatformSupport/private/qglxconvenience_p.h>
#elif defined(XCB_USE_EGL) #elif defined(XCB_USE_EGL)
#include <QtPlatformSupport/private/qeglplatformcontext_p.h> #include "qxcbeglsurface.h"
#include <QtPlatformSupport/private/qeglconvenience_p.h> #include <QtPlatformSupport/private/qeglconvenience_p.h>
#include <QtPlatformSupport/private/qxlibeglintegration_p.h> #include <QtPlatformSupport/private/qxlibeglintegration_p.h>
#endif #endif
@ -98,6 +98,9 @@ QXcbWindow::QXcbWindow(QWindow *window)
, m_syncCounter(0) , m_syncCounter(0)
, m_mapped(false) , m_mapped(false)
, m_netWmUserTimeWindow(XCB_NONE) , m_netWmUserTimeWindow(XCB_NONE)
#if defined(XCB_USE_EGL)
, m_eglSurface(0)
#endif
{ {
m_screen = static_cast<QXcbScreen *>(QGuiApplicationPrivate::platformIntegration()->screens().at(0)); m_screen = static_cast<QXcbScreen *>(QGuiApplicationPrivate::platformIntegration()->screens().at(0));
@ -120,7 +123,7 @@ void QXcbWindow::create()
if (type == Qt::Desktop) { if (type == Qt::Desktop) {
m_window = m_screen->root(); m_window = m_screen->root();
m_depth = m_screen->screen()->root_depth; m_depth = m_screen->screen()->root_depth;
m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; m_imageFormat = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
connection()->addWindow(m_window, this); connection()->addWindow(m_window, this);
return; return;
} }
@ -155,17 +158,18 @@ void QXcbWindow::create()
if (parent()) if (parent())
xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window(); xcb_parent_id = static_cast<QXcbWindow *>(parent())->xcb_window();
m_requestedFormat = window()->format();
#if defined(XCB_USE_GLX) || defined(XCB_USE_EGL) #if defined(XCB_USE_GLX) || defined(XCB_USE_EGL)
if ((window()->surfaceType() == QWindow::OpenGLSurface if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)
&& QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) || window()->format().hasAlpha())
|| window()->glFormat().hasAlpha())
{ {
#if defined(XCB_USE_GLX) #if defined(XCB_USE_GLX)
XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), window()->glFormat()); XVisualInfo *visualInfo = qglx_findVisualInfo(DISPLAY_FROM_XCB(m_screen),m_screen->screenNumber(), window()->format());
#elif defined(XCB_USE_EGL) #elif defined(XCB_USE_EGL)
EGLDisplay eglDisplay = connection()->egl_display(); EGLDisplay eglDisplay = connection()->egl_display();
EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, window()->glFormat(), true); EGLConfig eglConfig = q_configFromGLFormat(eglDisplay, window()->format(), true);
VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig); VisualID id = QXlibEglIntegration::getCompatibleVisualId(DISPLAY_FROM_XCB(this), eglDisplay, eglConfig);
XVisualInfo visualInfoTemplate; XVisualInfo visualInfoTemplate;
@ -178,7 +182,7 @@ void QXcbWindow::create()
#endif //XCB_USE_GLX #endif //XCB_USE_GLX
if (visualInfo) { if (visualInfo) {
m_depth = visualInfo->depth; m_depth = visualInfo->depth;
m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; m_imageFormat = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), xcb_parent_id, visualInfo->visual, AllocNone); Colormap cmap = XCreateColormap(DISPLAY_FROM_XCB(this), xcb_parent_id, visualInfo->visual, AllocNone);
XSetWindowAttributes a; XSetWindowAttributes a;
@ -196,7 +200,7 @@ void QXcbWindow::create()
{ {
m_window = xcb_generate_id(xcb_connection()); m_window = xcb_generate_id(xcb_connection());
m_depth = m_screen->screen()->root_depth; m_depth = m_screen->screen()->root_depth;
m_format = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32; m_imageFormat = (m_depth == 32) ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32;
Q_XCB_CALL(xcb_create_window(xcb_connection(), Q_XCB_CALL(xcb_create_window(xcb_connection(),
XCB_COPY_FROM_PARENT, // depth -- same as root XCB_COPY_FROM_PARENT, // depth -- same as root
@ -291,6 +295,11 @@ void QXcbWindow::destroy()
Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window)); Q_XCB_CALL(xcb_destroy_window(xcb_connection(), m_window));
} }
m_mapped = false; m_mapped = false;
#if defined(XCB_USE_EGL)
delete m_eglSurface;
m_eglSurface = 0;
#endif
} }
void QXcbWindow::setGeometry(const QRect &rect) void QXcbWindow::setGeometry(const QRect &rect)
@ -1028,28 +1037,26 @@ void QXcbWindow::requestActivateWindow()
connection()->sync(); connection()->sync();
} }
QPlatformGLSurface *QXcbWindow::createGLSurface() const QSurfaceFormat QXcbWindow::format() const
{ {
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) { // ### return actual format
qWarning() << "QXcb::createGLSurface() called without OpenGL support"; return m_requestedFormat;
return 0; }
#if defined(XCB_USE_EGL)
QXcbEGLSurface *QXcbWindow::eglSurface() const
{
if (!m_eglSurface) {
EGLDisplay display = connection()->egl_display();
EGLConfig config = q_configFromGLFormat(display, window()->format(), true);
EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0);
m_eglSurface = new QXcbEGLSurface(display, surface);
} }
QGuiGLFormat format = window()->glFormat(); return m_eglSurface;
#if defined(XCB_USE_GLX)
return new QGLXSurface(m_window, format);
#elif defined(XCB_USE_EGL)
EGLDisplay display = connection()->egl_display();
EGLConfig config = q_configFromGLFormat(display, format, true);
EGLSurface eglSurface = eglCreateWindowSurface(display, config, (EGLNativeWindowType)m_window, 0);
return new QEGLSurface(eglSurface, window()->glFormat());
#else
return 0;
#endif
} }
#endif
void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event) void QXcbWindow::handleExposeEvent(const xcb_expose_event_t *event)
{ {

View File

@ -43,7 +43,7 @@
#define QXCBWINDOW_H #define QXCBWINDOW_H
#include <QtGui/QPlatformWindow> #include <QtGui/QPlatformWindow>
#include <QtGui/QGuiGLFormat> #include <QtGui/QSurfaceFormat>
#include <QtGui/QImage> #include <QtGui/QImage>
#include <xcb/xcb.h> #include <xcb/xcb.h>
@ -52,6 +52,7 @@
#include "qxcbobject.h" #include "qxcbobject.h"
class QXcbScreen; class QXcbScreen;
class QXcbEGLSurface;
class QXcbWindow : public QXcbObject, public QPlatformWindow class QXcbWindow : public QXcbObject, public QPlatformWindow
{ {
@ -74,8 +75,6 @@ public:
void lower(); void lower();
void propagateSizeHints(); void propagateSizeHints();
QPlatformGLSurface *createGLSurface() const;
void requestActivateWindow(); void requestActivateWindow();
bool setKeyboardGrabEnabled(bool grab); bool setKeyboardGrabEnabled(bool grab);
@ -83,9 +82,11 @@ public:
void setCursor(xcb_cursor_t cursor); void setCursor(xcb_cursor_t cursor);
QSurfaceFormat format() const;
xcb_window_t xcb_window() const { return m_window; } xcb_window_t xcb_window() const { return m_window; }
uint depth() const { return m_depth; } uint depth() const { return m_depth; }
QImage::Format format() const { return m_format; } QImage::Format imageFormat() const { return m_imageFormat; }
void handleExposeEvent(const xcb_expose_event_t *event); void handleExposeEvent(const xcb_expose_event_t *event);
void handleClientMessageEvent(const xcb_client_message_event_t *event); void handleClientMessageEvent(const xcb_client_message_event_t *event);
@ -107,6 +108,10 @@ public:
void updateNetWmUserTime(xcb_timestamp_t timestamp); void updateNetWmUserTime(xcb_timestamp_t timestamp);
void netWmUserTime() const; void netWmUserTime() const;
#if defined(XCB_USE_EGL)
QXcbEGLSurface *eglSurface() const;
#endif
private: private:
void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0); void changeNetWmState(bool set, xcb_atom_t one, xcb_atom_t two = 0);
QVector<xcb_atom_t> getNetWmState(); QVector<xcb_atom_t> getNetWmState();
@ -119,7 +124,6 @@ private:
void updateMotifWmHintsBeforeMap(); void updateMotifWmHintsBeforeMap();
void updateNetWmStateBeforeMap(); void updateNetWmStateBeforeMap();
void create(); void create();
void destroy(); void destroy();
@ -131,7 +135,7 @@ private:
xcb_window_t m_window; xcb_window_t m_window;
uint m_depth; uint m_depth;
QImage::Format m_format; QImage::Format m_imageFormat;
xcb_sync_int64_t m_syncValue; xcb_sync_int64_t m_syncValue;
xcb_sync_counter_t m_syncCounter; xcb_sync_counter_t m_syncCounter;
@ -142,8 +146,14 @@ private:
bool m_mapped; bool m_mapped;
xcb_window_t m_netWmUserTimeWindow; xcb_window_t m_netWmUserTimeWindow;
QSurfaceFormat m_requestedFormat;
mutable bool m_dirtyFrameMargins; mutable bool m_dirtyFrameMargins;
mutable QMargins m_frameMargins; mutable QMargins m_frameMargins;
#if defined(XCB_USE_EGL)
mutable QXcbEGLSurface *m_eglSurface;
#endif
}; };
#endif #endif

View File

@ -67,6 +67,7 @@ contains(QT_CONFIG, opengl) {
contains(QT_CONFIG, opengles2) { contains(QT_CONFIG, opengles2) {
DEFINES += XCB_USE_EGL DEFINES += XCB_USE_EGL
LIBS += -lEGL LIBS += -lEGL
HEADERS += qxcbeglsurface.h
} else { } else {
DEFINES += XCB_USE_GLX DEFINES += XCB_USE_GLX
HEADERS += qglxintegration.h HEADERS += qglxintegration.h

View File

@ -48,7 +48,7 @@
#include "private/qapplication_p.h" #include "private/qapplication_p.h"
#include "QtWidgets/qdesktopwidget.h" #include "QtWidgets/qdesktopwidget.h"
#include "QtGui/qplatformwindow_qpa.h" #include "QtGui/qplatformwindow_qpa.h"
#include "QtGui/qguiglformat_qpa.h" #include "QtGui/qsurfaceformat.h"
#include "QtGui/qplatformglcontext_qpa.h" #include "QtGui/qplatformglcontext_qpa.h"
#include "QtGui/private/qwindow_p.h" #include "QtGui/private/qwindow_p.h"
@ -106,9 +106,9 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
win->setGeometry(q->geometry()); win->setGeometry(q->geometry());
if (q->testAttribute(Qt::WA_TranslucentBackground)) { if (q->testAttribute(Qt::WA_TranslucentBackground)) {
QGuiGLFormat format; QSurfaceFormat format;
format.setAlphaBufferSize(8); format.setAlphaBufferSize(8);
win->setGLFormat(format); win->setFormat(format);
} }
if (QWidget *nativeParent = q->nativeParentWidget()) { if (QWidget *nativeParent = q->nativeParentWidget()) {