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:
parent
6181676ca6
commit
75711510b1
@ -64,6 +64,8 @@ inline void Normalize(qreal &x, qreal &y, qreal &z)
|
|||||||
|
|
||||||
GLWindow::GLWindow()
|
GLWindow::GLWindow()
|
||||||
{
|
{
|
||||||
|
setSurfaceType(OpenGLSurface);
|
||||||
|
|
||||||
qtLogo = true;
|
qtLogo = true;
|
||||||
createdVertices = 0;
|
createdVertices = 0;
|
||||||
createdNormals = 0;
|
createdNormals = 0;
|
||||||
|
@ -288,6 +288,12 @@ bool QOpenGLContext::makeCurrent(QSurface *surface)
|
|||||||
if (!surface->surfaceHandle())
|
if (!surface->surfaceHandle())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (surface->surfaceType() != QSurface::OpenGLSurface) {
|
||||||
|
qWarning() << "QOpenGLContext::makeBuffers() called with non-opengl surface";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
|
if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
|
||||||
QOpenGLContextPrivate::setCurrentContext(this);
|
QOpenGLContextPrivate::setCurrentContext(this);
|
||||||
d->surface = surface;
|
d->surface = surface;
|
||||||
@ -354,6 +360,11 @@ void QOpenGLContext::swapBuffers(QSurface *surface)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (surface->surfaceType() != QSurface::OpenGLSurface) {
|
||||||
|
qWarning() << "QOpenGLContext::swapBuffers() called with non-opengl surface";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QPlatformSurface *surfaceHandle = surface->surfaceHandle();
|
QPlatformSurface *surfaceHandle = surface->surfaceHandle();
|
||||||
if (!surfaceHandle)
|
if (!surfaceHandle)
|
||||||
return;
|
return;
|
||||||
|
@ -43,12 +43,12 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
QSurface::SurfaceType QPlatformSurface::surfaceType() const
|
QSurface::SurfaceClass QPlatformSurface::surfaceClass() const
|
||||||
{
|
{
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlatformSurface::QPlatformSurface(QSurface::SurfaceType type) : m_type(type)
|
QPlatformSurface::QPlatformSurface(QSurface::SurfaceClass type) : m_type(type)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ class Q_GUI_EXPORT QPlatformSurface
|
|||||||
public:
|
public:
|
||||||
virtual QSurfaceFormat format() const = 0;
|
virtual QSurfaceFormat format() const = 0;
|
||||||
|
|
||||||
QSurface::SurfaceType surfaceType() const;
|
QSurface::SurfaceClass surfaceClass() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPlatformSurface(QSurface::SurfaceType type);
|
QPlatformSurface(QSurface::SurfaceClass type);
|
||||||
|
|
||||||
QSurface::SurfaceType m_type;
|
QSurface::SurfaceClass m_type;
|
||||||
|
|
||||||
friend class QPlatformWindow;
|
friend class QPlatformWindow;
|
||||||
};
|
};
|
||||||
|
@ -43,12 +43,53 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
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;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
#include <QtCore/qnamespace.h>
|
#include <QtCore/qnamespace.h>
|
||||||
#include <QtGui/qsurfaceformat.h>
|
#include <QtGui/qsurfaceformat.h>
|
||||||
|
|
||||||
|
#include <QtCore/qsize.h>
|
||||||
|
|
||||||
QT_BEGIN_HEADER
|
QT_BEGIN_HEADER
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -52,26 +54,37 @@ QT_BEGIN_NAMESPACE
|
|||||||
|
|
||||||
class QPlatformSurface;
|
class QPlatformSurface;
|
||||||
|
|
||||||
|
class QSurfacePrivate;
|
||||||
|
|
||||||
class Q_GUI_EXPORT QSurface
|
class Q_GUI_EXPORT QSurface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum SurfaceType {
|
enum SurfaceClass {
|
||||||
Window
|
Window
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum SurfaceType {
|
||||||
|
RasterSurface,
|
||||||
|
OpenGLSurface
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~QSurface();
|
virtual ~QSurface();
|
||||||
|
|
||||||
SurfaceType surfaceType() const;
|
SurfaceClass surfaceClass() const;
|
||||||
|
|
||||||
virtual QSurfaceFormat format() const = 0;
|
virtual QSurfaceFormat format() const = 0;
|
||||||
virtual QPlatformSurface *surfaceHandle() const = 0;
|
virtual QPlatformSurface *surfaceHandle() const = 0;
|
||||||
|
|
||||||
private:
|
virtual SurfaceType surfaceType() const = 0;
|
||||||
QSurface(SurfaceType type);
|
|
||||||
|
|
||||||
SurfaceType m_type;
|
virtual QSize size() const = 0;
|
||||||
|
|
||||||
friend class QWindow;
|
protected:
|
||||||
|
QSurface(SurfaceClass type);
|
||||||
|
|
||||||
|
SurfaceClass m_type;
|
||||||
|
|
||||||
|
QSurfacePrivate *m_reserved;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -93,7 +93,6 @@ class Q_GUI_EXPORT QWindow : public QObject, public QSurface
|
|||||||
Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
|
Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation WRITE reportContentOrientationChange NOTIFY contentOrientationChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum SurfaceType { RasterSurface, OpenGLSurface };
|
|
||||||
|
|
||||||
QWindow(QScreen *screen = 0);
|
QWindow(QScreen *screen = 0);
|
||||||
QWindow(QWindow *parent);
|
QWindow(QWindow *parent);
|
||||||
|
@ -130,6 +130,7 @@ struct SharedResource : public QOpenGLSharedResource
|
|||||||
void tst_QOpenGL::sharedResourceCleanup()
|
void tst_QOpenGL::sharedResourceCleanup()
|
||||||
{
|
{
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 10, 10);
|
window.setGeometry(0, 0, 10, 10);
|
||||||
window.create();
|
window.create();
|
||||||
|
|
||||||
@ -152,6 +153,7 @@ void tst_QOpenGL::sharedResourceCleanup()
|
|||||||
QOpenGLContext *ctx2 = new QOpenGLContext;
|
QOpenGLContext *ctx2 = new QOpenGLContext;
|
||||||
ctx2->setShareContext(ctx);
|
ctx2->setShareContext(ctx);
|
||||||
ctx2->create();
|
ctx2->create();
|
||||||
|
|
||||||
delete ctx;
|
delete ctx;
|
||||||
|
|
||||||
resource->free();
|
resource->free();
|
||||||
@ -191,6 +193,7 @@ void tst_QOpenGL::sharedResourceCleanup()
|
|||||||
void tst_QOpenGL::multiGroupSharedResourceCleanup()
|
void tst_QOpenGL::multiGroupSharedResourceCleanup()
|
||||||
{
|
{
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 10, 10);
|
window.setGeometry(0, 0, 10, 10);
|
||||||
window.create();
|
window.create();
|
||||||
|
|
||||||
@ -212,6 +215,7 @@ void tst_QOpenGL::multiGroupSharedResourceCleanup()
|
|||||||
void tst_QOpenGL::multiGroupSharedResourceCleanupCustom()
|
void tst_QOpenGL::multiGroupSharedResourceCleanupCustom()
|
||||||
{
|
{
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 10, 10);
|
window.setGeometry(0, 0, 10, 10);
|
||||||
window.create();
|
window.create();
|
||||||
|
|
||||||
@ -348,6 +352,7 @@ void qt_opengl_check_test_pattern(const QImage& img)
|
|||||||
void tst_QOpenGL::fboSimpleRendering()
|
void tst_QOpenGL::fboSimpleRendering()
|
||||||
{
|
{
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 10, 10);
|
window.setGeometry(0, 0, 10, 10);
|
||||||
window.create();
|
window.create();
|
||||||
QOpenGLContext ctx;
|
QOpenGLContext ctx;
|
||||||
@ -391,6 +396,7 @@ void tst_QOpenGL::fboRendering()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 10, 10);
|
window.setGeometry(0, 0, 10, 10);
|
||||||
window.create();
|
window.create();
|
||||||
QOpenGLContext ctx;
|
QOpenGLContext ctx;
|
||||||
@ -430,6 +436,7 @@ void tst_QOpenGL::fboRendering()
|
|||||||
void tst_QOpenGL::fboHandleNulledAfterContextDestroyed()
|
void tst_QOpenGL::fboHandleNulledAfterContextDestroyed()
|
||||||
{
|
{
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 10, 10);
|
window.setGeometry(0, 0, 10, 10);
|
||||||
window.create();
|
window.create();
|
||||||
|
|
||||||
@ -459,6 +466,7 @@ void tst_QOpenGL::openGLPaintDevice()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 128, 128);
|
window.setGeometry(0, 0, 128, 128);
|
||||||
window.create();
|
window.create();
|
||||||
|
|
||||||
@ -506,6 +514,7 @@ void tst_QOpenGL::openGLPaintDevice()
|
|||||||
void tst_QOpenGL::aboutToBeDestroyed()
|
void tst_QOpenGL::aboutToBeDestroyed()
|
||||||
{
|
{
|
||||||
QWindow window;
|
QWindow window;
|
||||||
|
window.setSurfaceType(QWindow::OpenGLSurface);
|
||||||
window.setGeometry(0, 0, 128, 128);
|
window.setGeometry(0, 0, 128, 128);
|
||||||
window.create();
|
window.create();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user