summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/kernel.pri2
-rw-r--r--src/gui/kernel/qplatformglcontext_qpa.cpp128
-rw-r--r--src/gui/kernel/qplatformglcontext_qpa.h33
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h2
-rw-r--r--src/gui/kernel/qwidget.cpp4
-rw-r--r--src/gui/kernel/qwidget_qpa.cpp32
-rw-r--r--src/gui/kernel/qwindow_qpa.cpp66
-rw-r--r--src/gui/kernel/qwindow_qpa.h39
-rw-r--r--src/gui/kernel/qwindowcontext_qpa.cpp200
-rw-r--r--src/gui/kernel/qwindowcontext_qpa.h90
-rw-r--r--src/gui/kernel/qwindowformat_qpa.cpp88
-rw-r--r--src/gui/kernel/qwindowformat_qpa.h26
12 files changed, 484 insertions, 226 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index daf9c9405e8..71a6a24fa99 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -221,6 +221,7 @@ qpa {
kernel/qplatformintegrationplugin_qpa.h \
kernel/qplatformwindow_qpa.h \
kernel/qplatformglcontext_qpa.h \
+ kernel/qwindowcontext_qpa.h \
kernel/qdesktopwidget_qpa_p.h \
kernel/qplatformeventloopintegration_qpa.h \
kernel/qplatformcursor_qpa.h \
@@ -248,6 +249,7 @@ qpa {
kernel/qplatformwindow_qpa.cpp \
kernel/qplatformeventloopintegration_qpa.cpp \
kernel/qplatformglcontext_qpa.cpp \
+ kernel/qwindowcontext_qpa.cpp \
kernel/qplatformcursor_qpa.cpp \
kernel/qplatformclipboard_qpa.cpp \
kernel/qplatformnativeinterface_qpa.cpp \
diff --git a/src/gui/kernel/qplatformglcontext_qpa.cpp b/src/gui/kernel/qplatformglcontext_qpa.cpp
index 181053223f3..2177a01d9b4 100644
--- a/src/gui/kernel/qplatformglcontext_qpa.cpp
+++ b/src/gui/kernel/qplatformglcontext_qpa.cpp
@@ -41,134 +41,6 @@
#include "qplatformglcontext_qpa.h"
-#include <QtCore/QThreadStorage>
-#include <QtCore/QThread>
-
-#include <QDebug>
-
-class QPlatformGLThreadContext
-{
-public:
- ~QPlatformGLThreadContext() {
- if (context)
- context->doneCurrent();
- }
- QPlatformGLContext *context;
-};
-
-static QThreadStorage<QPlatformGLThreadContext *> qplatformgl_context_storage;
-
-class QPlatformGLContextPrivate
-{
-public:
- QPlatformGLContextPrivate()
- :qGLContextHandle(0)
- {
- }
-
- virtual ~QPlatformGLContextPrivate()
- {
- //do not delete the QGLContext handle here as it is deleted in
- //QWidgetPrivate::deleteTLSysExtra()
- }
- void *qGLContextHandle;
- void (*qGLContextDeleteFunction)(void *handle);
- static QPlatformGLContext *staticSharedContext;
-
- static void setCurrentContext(QPlatformGLContext *context);
-};
-
-QPlatformGLContext *QPlatformGLContextPrivate::staticSharedContext = 0;
-
-void QPlatformGLContextPrivate::setCurrentContext(QPlatformGLContext *context)
-{
- QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData();
- if (!threadContext) {
- if (!QThread::currentThread()) {
- qWarning("No QTLS available. currentContext wont work");
- return;
- }
- threadContext = new QPlatformGLThreadContext;
- qplatformgl_context_storage.setLocalData(threadContext);
- }
- threadContext->context = context;
-}
-
-/*!
- Returns the last context which called makeCurrent. This function is thread aware.
-*/
-const QPlatformGLContext* QPlatformGLContext::currentContext()
-{
- QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData();
- if(threadContext) {
- return threadContext->context;
- }
- return 0;
-}
-
-/*!
- All subclasses needs to specify the platformWindow. It can be a null window.
-*/
-QPlatformGLContext::QPlatformGLContext()
- :d_ptr(new QPlatformGLContextPrivate())
-{
-}
-
-/*!
- If this is the current context for the thread, doneCurrent is called
-*/
-QPlatformGLContext::~QPlatformGLContext()
-{
- if (QPlatformGLContext::currentContext() == this) {
- doneCurrent();
- }
-
-}
-
-/*!
- Reimplement in subclass to do makeCurrent on native GL context
-*/
-void QPlatformGLContext::makeCurrent()
-{
- QPlatformGLContextPrivate::setCurrentContext(this);
-}
-
-/*!
- Reimplement in subclass to release current context.
- Typically this is calling makeCurrent with 0 "surface"
-*/
-void QPlatformGLContext::doneCurrent()
-{
- QPlatformGLContextPrivate::setCurrentContext(0);
-}
-
-/*
- internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant
- have any type information.
-*/
-void *QPlatformGLContext::qGLContextHandle() const
-{
- Q_D(const QPlatformGLContext);
- return d->qGLContextHandle;
-}
-
-void QPlatformGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *))
-{
- Q_D(QPlatformGLContext);
- d->qGLContextHandle = handle;
- d->qGLContextDeleteFunction = qGLContextDeleteFunction;
-}
-
-void QPlatformGLContext::deleteQGLContext()
-{
- Q_D(QPlatformGLContext);
- if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
- d->qGLContextDeleteFunction(d->qGLContextHandle);
- d->qGLContextDeleteFunction = 0;
- d->qGLContextHandle = 0;
- }
-}
-
/*!
\class QPlatformGLContext
\since 4.8
diff --git a/src/gui/kernel/qplatformglcontext_qpa.h b/src/gui/kernel/qplatformglcontext_qpa.h
index 5a22bc769a0..fbd43b2b480 100644
--- a/src/gui/kernel/qplatformglcontext_qpa.h
+++ b/src/gui/kernel/qplatformglcontext_qpa.h
@@ -43,7 +43,7 @@
#define QPLATFORM_GL_CONTEXT_H
#include <QtCore/qnamespace.h>
-#include <QtGui/QWindowFormat>
+#include <QtGui/qwindowformat_qpa.h>
QT_BEGIN_HEADER
@@ -51,36 +51,17 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
-class QPlatformGLContextPrivate;
-
-class Q_OPENGL_EXPORT QPlatformGLContext
+class Q_GUI_EXPORT QPlatformGLContext
{
-Q_DECLARE_PRIVATE(QPlatformGLContext);
-
public:
- explicit QPlatformGLContext();
- virtual ~QPlatformGLContext();
+ virtual ~QPlatformGLContext() {}
- virtual void makeCurrent();
- virtual void doneCurrent();
+ virtual void makeCurrent() = 0;
+ virtual void doneCurrent() = 0;
virtual void swapBuffers() = 0;
- virtual void* getProcAddress(const QString& procName) = 0;
+ virtual void *getProcAddress(const QString& procName) = 0;
virtual QWindowFormat windowFormat() const = 0;
-
- const static QPlatformGLContext *currentContext();
-
-protected:
- QScopedPointer<QPlatformGLContextPrivate> d_ptr;
-
-private:
- //hack to make it work with QGLContext::CurrentContext
- friend class QGLContext;
- friend class QWidgetPrivate;
- void *qGLContextHandle() const;
- void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *));
- void deleteQGLContext();
- Q_DISABLE_COPY(QPlatformGLContext);
};
QT_END_NAMESPACE
@@ -88,4 +69,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QPLATFORM_GL_INTEGRATION_P_H
+#endif // QPLATFORM_GL_CONTEXT_H
diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h
index 1517fc4fce5..43080d297ab 100644
--- a/src/gui/kernel/qplatformintegration_qpa.h
+++ b/src/gui/kernel/qplatformintegration_qpa.h
@@ -77,7 +77,7 @@ public:
// GraphicsSystem functions
virtual QPixmapData *createPixmapData(QPixmapData::PixelType type) const = 0;
- virtual QPlatformWindow *createPlatformWindow(QWindow *window, const QWindowFormat &format) const = 0;
+ virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0;
virtual QWindowSurface *createWindowSurface(QWindow *window, WId winId) const = 0;
// Window System functions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index f153860ba94..d1abc8f96fa 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -1761,10 +1761,6 @@ void QWidgetPrivate::createTLExtra()
static int count = 0;
qDebug() << "tlextra" << ++count;
#endif
-#if defined(Q_WS_QPA)
- x->window = 0;
- x->screenIndex = 0;
-#endif
}
}
diff --git a/src/gui/kernel/qwidget_qpa.cpp b/src/gui/kernel/qwidget_qpa.cpp
index b5a75155da4..efecb4407ce 100644
--- a/src/gui/kernel/qwidget_qpa.cpp
+++ b/src/gui/kernel/qwidget_qpa.cpp
@@ -90,24 +90,24 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
return; // we only care about real toplevels
QWindowSurface *surface = q->windowSurface();
-// QPlatformWindow *platformWindow = q->platformWindow();
-// if (!platformWindow) {
-// platformWindow = QApplicationPrivate::platformIntegration()->createPlatformWindow(q);
-// }
-// Q_ASSERT(platformWindow);
+ QWindow *win = topData()->window;
-// if (!surface ) {
-// if (platformWindow && q->platformWindowFormat().hasWindowSurface()) {
-// surface = QApplicationPrivate::platformIntegration()->createWindowSurface(q,platformWindow->winId());
-// } else {
-// q->setAttribute(Qt::WA_PaintOnScreen,true);
-// }
-// }
+ // translate window type
+// window->setWindowType();
+ win->create();
+
+ if (!surface ) {
+ if (win) {
+ surface = QApplicationPrivate::platformIntegration()->createWindowSurface(win, win->winId());
+ } else {
+ q->setAttribute(Qt::WA_PaintOnScreen,true);
+ }
+ }
// data.window_flags = q->windowHandle()->setWindowFlags(data.window_flags);
-// setWinId(q->platformWindow()->winId());
+ setWinId(win->winId());
//first check children. and create them if necessary
// q_createNativeChildrenAndSetParent(q->platformWindow(),q);
@@ -211,7 +211,7 @@ void QWidgetPrivate::setParent_sys(QWidget *newparent, Qt::WindowFlags f)
//qDebug() << "setParent_sys" << q << newparent << hex << f;
// if (QPlatformWindow *window = q->platformWindow())
// data.window_flags = window->setWindowFlags(data.window_flags);
- Q_ASSERT(false);
+// Q_ASSERT(false);
}
if (q->isWindow() || (!newparent || newparent->isVisible()) || explicitlyHidden)
@@ -705,6 +705,10 @@ void QWidgetPrivate::deleteSysExtra()
void QWidgetPrivate::createTLSysExtra()
{
+ Q_Q(QWidget);
+ extra->topextra->screenIndex = 0;
+ extra->topextra->window = new QWindow;
+ extra->topextra->window->setWidget(q);
}
void QWidgetPrivate::deleteTLSysExtra()
diff --git a/src/gui/kernel/qwindow_qpa.cpp b/src/gui/kernel/qwindow_qpa.cpp
index 15b0f9cd386..ad161793839 100644
--- a/src/gui/kernel/qwindow_qpa.cpp
+++ b/src/gui/kernel/qwindow_qpa.cpp
@@ -43,6 +43,8 @@
#include "qplatformwindow_qpa.h"
#include "qwindowformat_qpa.h"
+#include "qplatformglcontext_qpa.h"
+#include "qwindowcontext_qpa.h"
#include "qapplication_p.h"
@@ -53,9 +55,10 @@ QT_BEGIN_NAMESPACE
class QWindowPrivate : public QObjectPrivate
{
public:
- QWindowPrivate(QWindow::WindowTypes types)
+ QWindowPrivate()
: QObjectPrivate()
- , windowTypes(types)
+ , windowType(QWindow::Window)
+ , surfaceType(QWindow::RasterSurface)
, platformWindow(0)
, glContext(0)
, widget(0)
@@ -68,19 +71,25 @@ public:
}
- QWindow::WindowTypes windowTypes;
+ QWindow::WindowType windowType;
+ QWindow::SurfaceType surfaceType;
+
QPlatformWindow *platformWindow;
QWindowFormat requestedFormat;
QString windowTitle;
QRect geometry;
- QGLContext *glContext;
+ QWindowContext *glContext;
QWidget *widget;
};
-QWindow::QWindow(WindowTypes types, QWindow *parent)
- : QObject(*new QWindowPrivate(types), parent)
+QWindow::QWindow(QWindow *parent)
+ : QObject(*new QWindowPrivate(), parent)
{
+}
+QWindow::~QWindow()
+{
+ destroy();
}
QWidget *QWindow::widget() const
@@ -107,17 +116,16 @@ void QWindow::setVisible(bool visible)
void QWindow::create()
{
Q_D(QWindow);
- d->platformWindow = QApplicationPrivate::platformIntegration()->createPlatformWindow(this,d->requestedFormat);
+ d->platformWindow = QApplicationPrivate::platformIntegration()->createPlatformWindow(this);
Q_ASSERT(d->platformWindow);
}
WId QWindow::winId() const
{
Q_D(const QWindow);
- if(d->platformWindow) {
- return d->platformWindow->winId();
- }
- return 0;
+ if(!d->platformWindow)
+ const_cast<QWindow *>(this)->create();
+ return d->platformWindow->winId();
}
void QWindow::setParent(const QWindow *parent)
@@ -148,14 +156,31 @@ QWindowFormat QWindow::requestedWindowFormat() const
QWindowFormat QWindow::actualWindowFormat() const
{
+ return glContext()->handle()->windowFormat();
+}
+
+void QWindow::setSurfaceType(SurfaceType type)
+{
+ Q_D(QWindow);
+ d->surfaceType = type;
+}
+
+QWindow::SurfaceType QWindow::surfaceType() const
+{
Q_D(const QWindow);
- return d->requestedFormat;
+ return d->surfaceType;
+}
+
+void QWindow::setWindowType(WindowType type)
+{
+ Q_D(QWindow);
+ d->windowType = type;
}
-QWindow::WindowTypes QWindow::types() const
+QWindow::WindowType QWindow::type() const
{
Q_D(const QWindow);
- return d->windowTypes;
+ return d->windowType;
}
void QWindow::setWindowTitle(const QString &title)
@@ -262,9 +287,11 @@ void QWindow::setWindowIcon(const QImage &icon) const
qDebug() << "unimplemented:" << __FILE__ << __LINE__;
}
-QGLContext * QWindow::glContext() const
+QWindowContext * QWindow::glContext() const
{
Q_D(const QWindow);
+ if (!d->glContext)
+ const_cast<QWindowPrivate *>(d)->glContext = new QWindowContext(const_cast<QWindow *>(this));
return d->glContext;
}
@@ -281,13 +308,22 @@ QWindowFormat QWindow::format() const
void QWindow::destroy()
{
+ Q_D(QWindow);
//JA, this will be solved later....
// if (QGLContext *context = extra->topextra->window->glContext()) {
// context->deleteQGLContext();
Q_ASSERT(false);
+ delete d->glContext;
+ d->glContext = 0;
// }
}
+QPlatformWindow *QWindow::handle() const
+{
+ Q_D(const QWindow);
+ return d->platformWindow;
+}
+
void QWindow::showMinimized()
{
qDebug() << "unimplemented:" << __FILE__ << __LINE__;
diff --git a/src/gui/kernel/qwindow_qpa.h b/src/gui/kernel/qwindow_qpa.h
index d745fb0b4cd..d9bd2950d11 100644
--- a/src/gui/kernel/qwindow_qpa.h
+++ b/src/gui/kernel/qwindow_qpa.h
@@ -53,7 +53,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
class QWindowPrivate;
-class QGLContext;
class QWidget;
class QResizeEvent;
@@ -66,6 +65,9 @@ class QMouseEvent;
class QWheelEvent;
#endif
+class QPlatformWindow;
+class QWindowContext;
+
class Q_GUI_EXPORT QWindow : public QObject
{
Q_OBJECT
@@ -75,16 +77,25 @@ class Q_GUI_EXPORT QWindow : public QObject
public:
enum WindowType {
- Window = 0x00000001,
- Dialog = 0x00000002,
- Popup = 0x00000004,
- ToolTip = 0x00000008
+ Window,
+ Dialog,
+ Popup,
+ Tool,
+ SplashScreen,
+ ToolTip,
+ Sheet,
+ Drawer
+ };
+
+ enum SurfaceType {
+ RasterSurface,
+ OpenGLSurface
};
- Q_DECLARE_FLAGS(WindowTypes, WindowType)
- QWindow(QWindow::WindowTypes types = Window, QWindow *parent = 0);
+ QWindow(QWindow *parent = 0);
+ virtual ~QWindow();
- // to be removed at some poitn in the future
+ // to be removed at some point in the future
QWidget *widget() const;
void setWidget(QWidget *widget);
@@ -98,7 +109,11 @@ public:
QWindowFormat requestedWindowFormat() const;
QWindowFormat actualWindowFormat() const;
- WindowTypes types() const;
+ void setSurfaceType(SurfaceType type);
+ SurfaceType surfaceType() const;
+
+ void setWindowType(WindowType type);
+ WindowType type() const;
QString windowTitle() const;
@@ -119,13 +134,15 @@ public:
void setWindowIcon(const QImage &icon) const;
- QGLContext *glContext() const;
+ QWindowContext *glContext() const;
void setRequestFormat(const QWindowFormat &format);
QWindowFormat format() const;
void destroy();
+ QPlatformWindow *handle() const;
+
public Q_SLOTS:
inline void show() { setVisible(true); }
inline void hide() { setVisible(false); }
@@ -166,8 +183,6 @@ private:
Q_DISABLE_COPY(QWindow)
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QWindow::WindowTypes)
-
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/gui/kernel/qwindowcontext_qpa.cpp b/src/gui/kernel/qwindowcontext_qpa.cpp
new file mode 100644
index 00000000000..3dd48704cea
--- /dev/null
+++ b/src/gui/kernel/qwindowcontext_qpa.cpp
@@ -0,0 +1,200 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation ([email protected])
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at [email protected].
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qplatformglcontext_qpa.h"
+#include "qwindowcontext_qpa.h"
+
+#include <QtCore/QThreadStorage>
+#include <QtCore/QThread>
+
+#include <QDebug>
+
+class QWindowThreadContext
+{
+public:
+ ~QWindowThreadContext() {
+ if (context)
+ context->doneCurrent();
+ }
+ QWindowContext *context;
+};
+
+static QThreadStorage<QWindowThreadContext *> qwindow_context_storage;
+
+class QWindowContextPrivate
+{
+public:
+ QWindowContextPrivate()
+ :qGLContextHandle(0)
+ {
+ }
+
+ virtual ~QWindowContextPrivate()
+ {
+ //do not delete the QGLContext handle here as it is deleted in
+ //QWidgetPrivate::deleteTLSysExtra()
+ }
+ void *qGLContextHandle;
+ void (*qGLContextDeleteFunction)(void *handle);
+ QPlatformGLContext *platformGLContext;
+ static QWindowContext *staticSharedContext;
+
+ static void setCurrentContext(QWindowContext *context);
+};
+
+QWindowContext *QWindowContextPrivate::staticSharedContext = 0;
+
+void QWindowContextPrivate::setCurrentContext(QWindowContext *context)
+{
+ QWindowThreadContext *threadContext = qwindow_context_storage.localData();
+ if (!threadContext) {
+ if (!QThread::currentThread()) {
+ qWarning("No QTLS available. currentContext wont work");
+ return;
+ }
+ threadContext = new QWindowThreadContext;
+ qwindow_context_storage.setLocalData(threadContext);
+ }
+ threadContext->context = context;
+}
+
+/*!
+ Returns the last context which called makeCurrent. This function is thread aware.
+*/
+QWindowContext* QWindowContext::currentContext()
+{
+ QWindowThreadContext *threadContext = qwindow_context_storage.localData();
+ if(threadContext) {
+ return threadContext->context;
+ }
+ return 0;
+}
+
+QPlatformGLContext *QWindowContext::handle() const
+{
+ Q_D(const QWindowContext);
+ return d->platformGLContext;
+}
+
+/*!
+ All subclasses needs to specify the platformWindow. It can be a null window.
+*/
+QWindowContext::QWindowContext(QWindow *window)
+ :d_ptr(new QWindowContextPrivate())
+{
+ Q_D(QWindowContext);
+ Q_ASSERT(window);
+ if (!window->handle())
+ window->create();
+ d->platformGLContext = window->handle()->glContext();
+}
+
+/*!
+ If this is the current context for the thread, doneCurrent is called
+*/
+QWindowContext::~QWindowContext()
+{
+ if (QWindowContext::currentContext() == this) {
+ doneCurrent();
+ }
+
+}
+
+/*!
+ Reimplement in subclass to do makeCurrent on native GL context
+*/
+void QWindowContext::makeCurrent()
+{
+ Q_D(QWindowContext);
+ QWindowContextPrivate::setCurrentContext(this);
+ d->platformGLContext->makeCurrent();
+}
+
+/*!
+ Reimplement in subclass to release current context.
+ Typically this is calling makeCurrent with 0 "surface"
+*/
+void QWindowContext::doneCurrent()
+{
+ Q_D(QWindowContext);
+ d->platformGLContext->doneCurrent();
+ QWindowContextPrivate::setCurrentContext(0);
+}
+
+void QWindowContext::swapBuffers()
+{
+ Q_D(QWindowContext);
+ d->platformGLContext->swapBuffers();
+}
+
+void (*QWindowContext::getProcAddress(const QByteArray &procName)) ()
+{
+ Q_D(QWindowContext);
+ void *result = d->platformGLContext->getProcAddress(QString::fromAscii(procName.constData()));
+ return (void (*)())result;
+}
+
+/*
+ internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant
+ have any type information.
+*/
+void *QWindowContext::qGLContextHandle() const
+{
+ Q_D(const QWindowContext);
+ return d->qGLContextHandle;
+}
+
+void QWindowContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *))
+{
+ Q_D(QWindowContext);
+ d->qGLContextHandle = handle;
+ d->qGLContextDeleteFunction = qGLContextDeleteFunction;
+}
+
+void QWindowContext::deleteQGLContext()
+{
+ Q_D(QWindowContext);
+ if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
+ d->qGLContextDeleteFunction(d->qGLContextHandle);
+ d->qGLContextDeleteFunction = 0;
+ d->qGLContextHandle = 0;
+ }
+}
diff --git a/src/gui/kernel/qwindowcontext_qpa.h b/src/gui/kernel/qwindowcontext_qpa.h
new file mode 100644
index 00000000000..c16666a7f4d
--- /dev/null
+++ b/src/gui/kernel/qwindowcontext_qpa.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation ([email protected])
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at [email protected].
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWINDOWCONTEXT_H
+#define QWINDOWCONTEXT_H
+
+#include <QtCore/qnamespace.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Gui)
+
+class QWindowContextPrivate;
+class QPlatformGLContext;
+
+class Q_GUI_EXPORT QWindowContext
+{
+Q_DECLARE_PRIVATE(QWindowContext);
+public:
+ ~QWindowContext();
+
+ void makeCurrent();
+ void doneCurrent();
+ void swapBuffers();
+ void (*getProcAddress(const QByteArray &procName)) ();
+
+ static QWindowContext *currentContext();
+
+ QPlatformGLContext *handle() const;
+
+private:
+ QWindowContext(QWindow *window);
+
+ QScopedPointer<QWindowContextPrivate> d_ptr;
+
+ //hack to make it work with QGLContext::CurrentContext
+ friend class QGLContext;
+ friend class QWidgetPrivate;
+ friend class QWindow;
+ void *qGLContextHandle() const;
+ void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *));
+ void deleteQGLContext();
+ Q_DISABLE_COPY(QWindowContext);
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QWINDOWCONTEXT_H
diff --git a/src/gui/kernel/qwindowformat_qpa.cpp b/src/gui/kernel/qwindowformat_qpa.cpp
index 831e1a91b81..03ccba7b075 100644
--- a/src/gui/kernel/qwindowformat_qpa.cpp
+++ b/src/gui/kernel/qwindowformat_qpa.cpp
@@ -41,6 +41,8 @@
#include "qwindowformat_qpa.h"
+#include "qplatformglcontext_qpa.h"
+
#include <QtCore/QDebug>
class QWindowFormatPrivate
@@ -49,9 +51,13 @@ public:
QWindowFormatPrivate()
: ref(1)
, opts(QWindowFormat::DoubleBuffer | QWindowFormat::WindowSurface)
+ , redBufferSize(-1)
+ , greenBufferSize(-1)
+ , blueBufferSize(-1)
+ , alphaBufferSize(-1)
, depthSize(-1)
, stencilSize(-1)
- , colorFormat(QWindowFormat::RGB888)
+ , swapBehavior(QWindowFormat::DefaultSwapBehavior)
, numSamples(-1)
, sharedContext(0)
{
@@ -60,9 +66,12 @@ public:
QWindowFormatPrivate(const QWindowFormatPrivate *other)
: ref(1),
opts(other->opts),
+ redBufferSize(other->redBufferSize),
+ greenBufferSize(other->greenBufferSize),
+ blueBufferSize(other->blueBufferSize),
+ alphaBufferSize(other->alphaBufferSize),
depthSize(other->depthSize),
stencilSize(other->stencilSize),
- colorFormat(other->colorFormat),
swapBehavior(other->swapBehavior),
numSamples(other->numSamples),
sharedContext(other->sharedContext)
@@ -70,12 +79,15 @@ public:
}
QAtomicInt ref;
QWindowFormat::FormatOptions opts;
+ int redBufferSize;
+ int greenBufferSize;
+ int blueBufferSize;
+ int alphaBufferSize;
int depthSize;
int stencilSize;
- QWindowFormat::ColorFormat colorFormat;
QWindowFormat::SwapBehavior swapBehavior;
int numSamples;
- QPlatformGLContext *sharedContext;
+ QWindowContext *sharedContext;
};
QWindowFormat::QWindowFormat()
@@ -193,12 +205,12 @@ void QWindowFormat::setSamples(int numSamples)
-void QWindowFormat::setSharedContext(QPlatformGLContext *context)
+void QWindowFormat::setSharedContext(QWindowContext *context)
{
d->sharedContext = context;
}
-QPlatformGLContext *QWindowFormat::sharedGLContext() const
+QWindowContext *QWindowFormat::sharedContext() const
{
return d->sharedContext;
}
@@ -268,15 +280,19 @@ int QWindowFormat::depthBufferSize() const
return d->depthSize;
}
-void QWindowFormat::setColorFormat(ColorFormat format)
+void QWindowFormat::setSwapBehavior(SwapBehavior behavior)
{
- detach();
- d->colorFormat = format;
+ d->swapBehavior = behavior;
+}
+
+QWindowFormat::SwapBehavior QWindowFormat::swapBehavior() const
+{
+ return d->swapBehavior;
}
-QWindowFormat::ColorFormat QWindowFormat::colorFormat() const
+bool QWindowFormat::hasAlpha() const
{
- return d->colorFormat;
+ return d->alphaBufferSize > 0;
}
/*!
@@ -300,12 +316,55 @@ int QWindowFormat::stencilBufferSize() const
return d->stencilSize;
}
+int QWindowFormat::redBufferSize() const
+{
+ return d->redBufferSize;
+}
+
+int QWindowFormat::greenBufferSize() const
+{
+ return d->greenBufferSize;
+}
+
+int QWindowFormat::blueBufferSize() const
+{
+ return d->blueBufferSize;
+}
+
+int QWindowFormat::alphaBufferSize() const
+{
+ return d->alphaBufferSize;
+}
+
+void QWindowFormat::setRedBufferSize(int size)
+{
+ d->redBufferSize = size;
+}
+
+void QWindowFormat::setGreenBufferSize(int size)
+{
+ d->greenBufferSize = size;
+}
+
+void QWindowFormat::setBlueBufferSize(int size)
+{
+ d->blueBufferSize = size;
+}
+
+void QWindowFormat::setAlphaBufferSize(int size)
+{
+ d->alphaBufferSize = size;
+}
+
bool operator==(const QWindowFormat& a, const QWindowFormat& b)
{
return (a.d == b.d) || ((int) a.d->opts == (int) b.d->opts
&& a.d->stencilSize == b.d->stencilSize
+ && a.d->redBufferSize == b.d->redBufferSize
+ && a.d->greenBufferSize == b.d->greenBufferSize
+ && a.d->blueBufferSize == b.d->blueBufferSize
+ && a.d->alphaBufferSize == b.d->alphaBufferSize
&& a.d->depthSize == b.d->depthSize
- && a.d->colorFormat == b.d->colorFormat
&& a.d->numSamples == b.d->numSamples
&& a.d->swapBehavior == b.d->swapBehavior
&& a.d->sharedContext == b.d->sharedContext);
@@ -332,8 +391,11 @@ QDebug operator<<(QDebug dbg, const QWindowFormat &f)
dbg.nospace() << "QWindowFormat("
<< "options " << d->opts
<< ", depthBufferSize " << d->depthSize
+ << ", redBufferSize " << d->redBufferSize
+ << ", greenBufferSize " << d->greenBufferSize
+ << ", blueBufferSize " << d->blueBufferSize
+ << ", alphaBufferSize " << d->alphaBufferSize
<< ", stencilBufferSize " << d->stencilSize
- << ", colorFormat " << d->colorFormat
<< ", samples " << d->numSamples
<< ", swapBehavior " << d->swapBehavior
<< ", sharedContext " << d->sharedContext
diff --git a/src/gui/kernel/qwindowformat_qpa.h b/src/gui/kernel/qwindowformat_qpa.h
index a1fdc9f5762..9bc2ccdfaab 100644
--- a/src/gui/kernel/qwindowformat_qpa.h
+++ b/src/gui/kernel/qwindowformat_qpa.h
@@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Gui)
+class QWindowContext;
class QWindowFormatPrivate;
class Q_GUI_EXPORT QWindowFormat
@@ -60,15 +61,6 @@ public:
};
Q_DECLARE_FLAGS(FormatOptions, FormatOption)
- enum ColorFormat {
- InvalidColorFormat,
- RGB565,
- RGBA5658,
- RGBA5551,
- RGB888,
- RGBA8888
- };
-
enum SwapBehavior {
DefaultSwapBehavior,
SingleBuffer,
@@ -94,20 +86,28 @@ public:
void setStencilBufferSize(int size);
int stencilBufferSize() const;
+ void setRedBufferSize(int size);
+ int redBufferSize() const;
+ void setGreenBufferSize(int size);
+ int greenBufferSize() const;
+ void setBlueBufferSize(int size);
+ int blueBufferSize() const;
+ void setAlphaBufferSize(int size);
+ int alphaBufferSize() const;
+
void setSamples(int numSamples);
int samples() const;
void setSwapBehavior(SwapBehavior behavior);
SwapBehavior swapBehavior() const;
- void setColorFormat(ColorFormat format);
- ColorFormat colorFormat() const;
+ bool hasAlpha() const;
void setProfile(OpenGLContextProfile profile);
OpenGLContextProfile profile() const;
- void setSharedContext(QPlatformGLContext *context);
- QPlatformGLContext *sharedGLContext() const;
+ void setSharedContext(QWindowContext *context);
+ QWindowContext *sharedContext() const;
bool stereo() const;
void setStereo(bool enable);