macOS: Add support for non-window backed offscreen surfaces

The modern approach to offscreen rendering on macOS is via FBOs, which
means there's no reason to allocate an NSView and corresponding NSWindow
just for that. In the offscreen case the NSOpenGLContext has a nil-view.

Change-Id: I2d1d407069af4d5283e6f56fba83db8eaf694ac6
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
bb10
Tor Arne Vestbø 2017-10-05 18:01:21 +02:00
parent a520c179b8
commit ed9340a926
3 changed files with 27 additions and 2 deletions

View File

@ -218,6 +218,9 @@ void QCocoaGLContext::windowWasHidden()
void QCocoaGLContext::swapBuffers(QPlatformSurface *surface)
{
if (surface->surface()->surfaceClass() == QSurface::Offscreen)
return; // Nothing to do
QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
setActiveWindow(window);
@ -229,11 +232,13 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
Q_ASSERT(surface->surface()->supportsOpenGL());
QMacAutoReleasePool pool;
[m_context makeCurrentContext];
if (surface->surface()->surfaceClass() == QSurface::Offscreen)
return true;
QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
setActiveWindow(window);
[m_context makeCurrentContext];
update();
return true;
}

View File

@ -77,6 +77,7 @@ public:
bool hasCapability(QPlatformIntegration::Capability cap) const Q_DECL_OVERRIDE;
QPlatformWindow *createPlatformWindow(QWindow *window) const Q_DECL_OVERRIDE;
QPlatformWindow *createForeignWindow(QWindow *window, WId nativeHandle) const Q_DECL_OVERRIDE;
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const Q_DECL_OVERRIDE;
#endif

View File

@ -56,6 +56,7 @@
#include <qpa/qplatforminputcontextfactory_p.h>
#include <qpa/qplatformaccessibility.h>
#include <qpa/qplatforminputcontextfactory_p.h>
#include <qpa/qplatformoffscreensurface.h>
#include <QtCore/qcoreapplication.h>
#include <QtGui/private/qcoregraphics_p.h>
@ -331,6 +332,24 @@ QPlatformWindow *QCocoaIntegration::createForeignWindow(QWindow *window, WId nat
return new QCocoaWindow(window, nativeHandle);
}
class QCocoaOffscreenSurface : public QPlatformOffscreenSurface
{
public:
QCocoaOffscreenSurface(QOffscreenSurface *offscreenSurface) : QPlatformOffscreenSurface(offscreenSurface) {}
QSurfaceFormat format() const override
{
Q_ASSERT(offscreenSurface());
return offscreenSurface()->requestedFormat();
}
bool isValid() const override { return true; }
};
QPlatformOffscreenSurface *QCocoaIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
{
return new QCocoaOffscreenSurface(surface);
}
#ifndef QT_NO_OPENGL
QPlatformOpenGLContext *QCocoaIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{