summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaglcontext.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-09-05 12:18:59 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2018-09-09 22:13:28 +0000
commitc0e94fa0cd2a2e6216dae5da0dde289fb689d22d (patch)
treed4def9da2ba6be0cb0352817062247a2192c1f9e /src/plugins/platforms/cocoa/qcocoaglcontext.mm
parent85917c4b72a498e86d6dd057a5b6df26c0565fc4 (diff)
macOS: Use NSOpenGLContext's drawable directly to track active drawable
We don't need a separate QWindow pointer to keep track of the active window, it's recorded already by the NSOpenGLContext's drawable. And we don't need to juggle the drawable when the window is hidden, the drawable is still valid after the window is re-shown, and we call update on every frame (for now) anyways, which will reconfigure the drawable if needed. Change-Id: I199b6c027226dd239c13ecc4aba86986ca09a1eb Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaglcontext.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaglcontext.mm35
1 files changed, 5 insertions, 30 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
index cf4ecd335c..c90f093836 100644
--- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm
+++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm
@@ -318,9 +318,6 @@ void QCocoaGLContext::updateSurfaceFormat()
QCocoaGLContext::~QCocoaGLContext()
{
- if (m_currentWindow && m_currentWindow.data()->handle())
- static_cast<QCocoaWindow *>(m_currentWindow.data()->handle())->setCurrentContext(0);
-
[m_context release];
}
@@ -372,20 +369,15 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface)
// on the previously set drawable.
qCDebug(lcQpaOpenGLContext) << "Clearing current drawable" << m_context.view << "for" << m_context;
[m_context clearDrawable];
- m_currentWindow.clear();
return true;
}
Q_ASSERT(surface->surface()->surfaceClass() == QSurface::Window);
- QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
+ QNSView *view = qnsview_cast(static_cast<QCocoaWindow *>(surface)->view());
- if (window == m_currentWindow.data())
+ if (view == m_context.view)
return true;
- Q_ASSERT(window->handle());
- QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
- NSView *view = cocoaWindow->view();
-
if ((m_context.view = view) != view) {
qCInfo(lcQpaOpenGLContext) << "Failed to set" << view << "as drawable for" << m_context;
return false;
@@ -393,12 +385,6 @@ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface)
qCInfo(lcQpaOpenGLContext) << "Set drawable for" << m_context << "to" << m_context.view;
- if (m_currentWindow && m_currentWindow.data()->handle())
- static_cast<QCocoaWindow *>(m_currentWindow.data()->handle())->setCurrentContext(0);
-
- m_currentWindow = window;
-
- cocoaWindow->setCurrentContext(this);
return true;
}
@@ -435,24 +421,13 @@ void QCocoaGLContext::doneCurrent()
qCDebug(lcQpaOpenGLContext) << "Clearing current context"
<< [NSOpenGLContext currentContext] << "in" << QThread::currentThread();
- if (m_currentWindow && m_currentWindow.data()->handle())
- static_cast<QCocoaWindow *>(m_currentWindow.data()->handle())->setCurrentContext(nullptr);
-
- m_currentWindow.clear();
+ // Note: We do not need to clear the current drawable here.
+ // As long as there is no current context, GL calls will
+ // do nothing.
[NSOpenGLContext clearCurrentContext];
}
-void QCocoaGLContext::windowWasHidden()
-{
- // If the window is hidden, we need to unset the m_currentWindow
- // variable so that succeeding makeCurrent's will not abort prematurely
- // because of the optimization in setDrawable.
- // Doing a full doneCurrent here is not preferable, because the GL context
- // might be rendering in a different thread at this time.
- m_currentWindow.clear();
-}
-
QSurfaceFormat QCocoaGLContext::format() const
{
return m_format;