Improve QSurface / QWindow API a bit and use that to avoid errors

Change-Id: Iadba1c3a7b8e6bc7f145455132cefed2a905c11d
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Gunnar Sletta 2012-01-19 12:51:43 +01:00 committed by Qt by Nokia
parent 6181676ca6
commit 75711510b1
8 changed files with 90 additions and 15 deletions

View File

@ -64,6 +64,8 @@ inline void Normalize(qreal &x, qreal &y, qreal &z)
GLWindow::GLWindow()
{
setSurfaceType(OpenGLSurface);
qtLogo = true;
createdVertices = 0;
createdNormals = 0;

View File

@ -288,6 +288,12 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
if (!surface->surfaceHandle())
return false;
if (surface->surfaceType() != QSurface::OpenGLSurface) {
qWarning() << "QOpenGLContext::makeBuffers() called with non-opengl surface";
return false;
}
if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
QOpenGLContextPrivate::setCurrentContext(this);
d->surface = surface;
@ -354,6 +360,11 @@ void QOpenGLContext::swapBuffers(QSurface *surface)
return;
}
if (surface->surfaceType() != QSurface::OpenGLSurface) {
qWarning() << "QOpenGLContext::swapBuffers() called with non-opengl surface";
return;
}
QPlatformSurface *surfaceHandle = surface->surfaceHandle();
if (!surfaceHandle)
return;

View File

@ -43,12 +43,12 @@
QT_BEGIN_NAMESPACE
QSurface::SurfaceType QPlatformSurface::surfaceType() const
QSurface::SurfaceClass QPlatformSurface::surfaceClass() const
{
return m_type;
}
QPlatformSurface::QPlatformSurface(QSurface::SurfaceType type) : m_type(type)
QPlatformSurface::QPlatformSurface(QSurface::SurfaceClass type) : m_type(type)
{
}

View File

@ -56,12 +56,12 @@ class Q_GUI_EXPORT QPlatformSurface
public:
virtual QSurfaceFormat format() const = 0;
QSurface::SurfaceType surfaceType() const;
QSurface::SurfaceClass surfaceClass() const;
private:
QPlatformSurface(QSurface::SurfaceType type);
QPlatformSurface(QSurface::SurfaceClass type);
QSurface::SurfaceType m_type;
QSurface::SurfaceClass m_type;
friend class QPlatformWindow;
};

View File

@ -43,12 +43,53 @@
QT_BEGIN_NAMESPACE
QSurface::QSurface(SurfaceType type)
: m_type(type)
/*!
\class QSurface
\brief The QSurface class is an abstraction of renderable surfaces in Qt.
The size of the surface is accessible with the size() function. The rendering
specific attributes of the surface are accessible through the format() function.
*/
/*!
\enum QSurface::SurfaceClass
The SurfaceClass enum describes the actual subclass of the surface.
\value Window The surface is an instance of QWindow.
*/
/*!
\enum QSurface::SurfaceType
The SurfaceType enum describes what type of surface the.
\value RasterSurface The surface is is composed of pixels and can be rendered to using
a software rasterizer like Qt's raster paint engine.
\value OpenGLSurface The surface is an OpenGL compatible surface and can be used
in conjunction with QOpenGLContext.
*/
/*!
QSize QSurface::size() const
Returns the size of the surface in pixels.
*/
QSurface::QSurface(SurfaceClass type)
: m_type(type), m_reserved(0)
{
}
QSurface::SurfaceType QSurface::surfaceType() const
QSurface::SurfaceClass QSurface::surfaceClass() const
{
return m_type;
}

View File

@ -45,6 +45,8 @@
#include <QtCore/qnamespace.h>
#include <QtGui/qsurfaceformat.h>
#include <QtCore/qsize.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
@ -52,26 +54,37 @@ QT_BEGIN_NAMESPACE
class QPlatformSurface;
class QSurfacePrivate;
class Q_GUI_EXPORT QSurface
{
public:
enum SurfaceType {
enum SurfaceClass {
Window
};
enum SurfaceType {
RasterSurface,
OpenGLSurface
};
virtual ~QSurface();
SurfaceType surfaceType() const;
SurfaceClass surfaceClass() const;
virtual QSurfaceFormat format() const = 0;
virtual QPlatformSurface *surfaceHandle() const = 0;
private:
QSurface(SurfaceType type);
virtual SurfaceType surfaceType() const = 0;
SurfaceType m_type;
virtual QSize size() const = 0;
friend class QWindow;
protected:
QSurface(SurfaceClass type);
SurfaceClass m_type;
QSurfacePrivate *m_reserved;
};
QT_END_NAMESPACE

View File

@ -93,7 +93,6 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
public:
enum SurfaceType { RasterSurface, OpenGLSurface };
QWindow(QScreen *screen = 0);
QWindow(QWindow *parent);

View File

@ -130,6 +130,7 @@ struct SharedResource : public QOpenGLSharedResource
void tst_QOpenGL::sharedResourceCleanup()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
@ -152,6 +153,7 @@ void tst_QOpenGL::sharedResourceCleanup()
QOpenGLContext *ctx2 = new QOpenGLContext;
ctx2->setShareContext(ctx);
ctx2->create();
delete ctx;
resource->free();
@ -191,6 +193,7 @@ void tst_QOpenGL::sharedResourceCleanup()
void tst_QOpenGL::multiGroupSharedResourceCleanup()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
@ -212,6 +215,7 @@ void tst_QOpenGL::multiGroupSharedResourceCleanup()
void tst_QOpenGL::multiGroupSharedResourceCleanupCustom()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
@ -348,6 +352,7 @@ void qt_opengl_check_test_pattern(const QImage& img)
void tst_QOpenGL::fboSimpleRendering()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
QOpenGLContext ctx;
@ -391,6 +396,7 @@ void tst_QOpenGL::fboRendering()
#endif
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
QOpenGLContext ctx;
@ -430,6 +436,7 @@ void tst_QOpenGL::fboRendering()
void tst_QOpenGL::fboHandleNulledAfterContextDestroyed()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 10, 10);
window.create();
@ -459,6 +466,7 @@ void tst_QOpenGL::openGLPaintDevice()
#endif
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 128, 128);
window.create();
@ -506,6 +514,7 @@ void tst_QOpenGL::openGLPaintDevice()
void tst_QOpenGL::aboutToBeDestroyed()
{
QWindow window;
window.setSurfaceType(QWindow::OpenGLSurface);
window.setGeometry(0, 0, 128, 128);
window.create();