From 75711510b1ad7d4ac4434ad41a0ed71cfc0344dc Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Thu, 19 Jan 2012 12:51:43 +0100 Subject: Improve QSurface / QWindow API a bit and use that to avoid errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iadba1c3a7b8e6bc7f145455132cefed2a905c11d Reviewed-by: Samuel Rødal --- examples/opengl/hellogl_es/glwindow.cpp | 2 ++ src/gui/kernel/qopenglcontext.cpp | 11 ++++++++ src/gui/kernel/qplatformsurface_qpa.cpp | 4 +-- src/gui/kernel/qplatformsurface_qpa.h | 6 ++--- src/gui/kernel/qsurface.cpp | 47 ++++++++++++++++++++++++++++++--- src/gui/kernel/qsurface.h | 25 +++++++++++++----- src/gui/kernel/qwindow.h | 1 - tests/auto/gui/qopengl/tst_qopengl.cpp | 9 +++++++ 8 files changed, 90 insertions(+), 15 deletions(-) diff --git a/examples/opengl/hellogl_es/glwindow.cpp b/examples/opengl/hellogl_es/glwindow.cpp index 6be4e63a20..d94d0d62cc 100644 --- a/examples/opengl/hellogl_es/glwindow.cpp +++ b/examples/opengl/hellogl_es/glwindow.cpp @@ -64,6 +64,8 @@ inline void Normalize(qreal &x, qreal &y, qreal &z) GLWindow::GLWindow() { + setSurfaceType(OpenGLSurface); + qtLogo = true; createdVertices = 0; createdNormals = 0; diff --git a/src/gui/kernel/qopenglcontext.cpp b/src/gui/kernel/qopenglcontext.cpp index f6481d3bb0..1b6d1d34c4 100644 --- a/src/gui/kernel/qopenglcontext.cpp +++ b/src/gui/kernel/qopenglcontext.cpp @@ -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; diff --git a/src/gui/kernel/qplatformsurface_qpa.cpp b/src/gui/kernel/qplatformsurface_qpa.cpp index 56b8f615c0..aeb73da2a3 100644 --- a/src/gui/kernel/qplatformsurface_qpa.cpp +++ b/src/gui/kernel/qplatformsurface_qpa.cpp @@ -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) { } diff --git a/src/gui/kernel/qplatformsurface_qpa.h b/src/gui/kernel/qplatformsurface_qpa.h index b57bbea6ea..af23ad3a85 100644 --- a/src/gui/kernel/qplatformsurface_qpa.h +++ b/src/gui/kernel/qplatformsurface_qpa.h @@ -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; }; diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp index 24079c55ab..eb2676802b 100644 --- a/src/gui/kernel/qsurface.cpp +++ b/src/gui/kernel/qsurface.cpp @@ -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; } diff --git a/src/gui/kernel/qsurface.h b/src/gui/kernel/qsurface.h index fd8eaaf058..a8900fde33 100644 --- a/src/gui/kernel/qsurface.h +++ b/src/gui/kernel/qsurface.h @@ -45,6 +45,8 @@ #include #include +#include + 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; + + virtual QSize size() const = 0; + +protected: + QSurface(SurfaceClass type); - SurfaceType m_type; + SurfaceClass m_type; - friend class QWindow; + QSurfacePrivate *m_reserved; }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index 4e6a8591d8..98b468b142 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -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); diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 0304376fb6..e8374b0cae 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -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(); -- cgit v1.2.3