Fixed Issue #17907 by providing a new API to disable linking view to context
- Added new Get/SetConnectContextToNSView flag that controls whether the NSOpenGLContext created by VTK is linked to the NSView (that could be created by VTK or merely provided to VTK). It defaults to true, preserving VTK's existing behaviour. When false, setView: is never invoked on the context, thus never linking it to the NSView. This is desirable when rendering into a CAOpenGLLayer, where one wants the context linked to the CAOpenGLLayer, not the NSView. Notably, in macOS 10.15.4 (but not any older version) macOS now crashes in this scenario (Issue #17907 (closed)).
- updated SimpleCocoaVTK example to use SetConnectContextToNSView(false) where it demonstrates using CAOpenGLLayer, thus fixing the 10.15.4 crash there.
- vtkCocoaRenderWindow::InitializeFromCurrentContext was calling this->SetContextId() to update the context, which is the main point of the method. Now it also calls this->SetPixelFormat() which seems more correct since the new context could have a different pixelFormat.
- vtkCocoaRenderWindow::InitializeFromCurrentContext used to check if the current context was related to an NSView, and if not, do nothing. But now that not being related to an NSView is a normal case, this check was removed.
- Changed vtkCocoaRenderWindow::InitializeFromCurrentContext to no longer call SetWindowId (the NSView) and SetRootWindow (the NSWindow).
- The changes to vtkCocoaRenderWindow::InitializeFromCurrentContext allow the SimpleCocoaVTK example to no longer skip to the superclass implementation.
Closes: #17907 (closed)
Backport: release:HEAD^2
Edited by David Gobbi