From: Gunnar Sletta Date: Thu, 19 Jan 2012 11:51:43 +0000 (+0100) Subject: Improve QSurface / QWindow API a bit and use that to avoid errors X-Git-Tag: qt-v5.0.0-alpha1~1363 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75711510b1ad7d4ac4434ad41a0ed71cfc0344dc;p=profile%2Fivi%2Fqtbase.git Improve QSurface / QWindow API a bit and use that to avoid errors Change-Id: Iadba1c3a7b8e6bc7f145455132cefed2a905c11d Reviewed-by: Samuel Rødal --- diff --git a/examples/opengl/hellogl_es/glwindow.cpp b/examples/opengl/hellogl_es/glwindow.cpp index 6be4e63..d94d0d6 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 f6481d3..1b6d1d3 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 56b8f61..aeb73da 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 b57bbea..af23ad3 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 24079c5..eb26768 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 fd8eaaf..a8900fd 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 4e6a859..98b468b 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 0304376..e8374b0 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();