summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qnsview_drawing.mm
Commit message (Collapse)AuthorAgeFilesLines
* Fix warning from unused parameterVolker Hilsheimer2020-08-261-0/+1
| | | | | Change-Id: I2e31d43492f94edf4030fdbd88c1000396bdf250 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Remove support for surface-backed viewsTor Arne Vestbø2020-08-181-53/+8
| | | | | | | | | | | | | Our deployment target is 10.14, which enables layer-backing by default, and our layer-backing support nowadays is stable enough that we don't need to maintain any of the old code paths for compatibility. The wantsBestResolutionOpenGLSurface property on NSView is only relevant for surface-backed views, so we no longer need to deal with it. Change-Id: I8aef4ac99371113d463ac35eee648a8a2fd1ea72 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Only use one macro per lineLars Schmertmann2020-07-031-1/+3
| | | | | | | | | Also add a ; where it is missing. Task-number: QTBUG-82978 Change-Id: Ic5d2a07363c25ab641d234baca89bc62238458cb Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* macOS: Improve handling of wantsBestResolutionOpenGLSurfaceTor Arne Vestbø2019-10-241-11/+0
| | | | | | | | | | | | | | | | | | | | | We were disabling wantsBestResolutionOpenGLSurface whenever we detected the Apple software renderer, but this isn't needed when layer-backed, and did in fact result in the exact same visual result as the bug the code was working around -- only rendering to a quarter of the viewport. We now apply the workaround only when software rendering is combined with surface-backed views. The logic has also been improved to not rely on string comparison to look for the software renderer, but instead uses the renderer ID that the context provides. Since tweaking the wantsBestResolutionOpenGLSurface is only relevant when using a window for GL rendering the logic has been moved into QCocoaGLContext. Change-Id: I021aaefbb7a9782bc8ee3c9703da246510326d50 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Simplify Objective-C namespacingTor Arne Vestbø2019-10-151-1/+1
| | | | | | | | | | | | | | | | We only need to use the QT_MANGLE_NAMESPACE macro when declaring the interface of the class. As long as we couple that with an alias declaration using QT_NAMESPACE_ALIAS_OBJC_CLASS, any further uses of the class name can be un-namespaced, including declaring categories on the class. The only snag with QT_NAMESPACE_ALIAS_OBJC_CLASS is that it can only be used once per class and translation unit, so forward declarations get hairy, but we can avoid that by just including the headers instead. Change-Id: I333bcd18fe1e18d81fbd560b0941c98b1c32460e Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* macOS: Avoid automatic resizing of layers by fixing them to top-leftTor Arne Vestbø2019-09-281-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | When a layer is resized, e.g. during a window resize, the contents of the layer may lag behind if the client doesn't fill the layer in response to the window resize and corresponding expose event. The default behavior is for Core Animation to stretch the content to fill the layer, but this results in the content "jumping" back and forth when the content then picks up the new size and fills the layer. Instead we tell Core Animation to fix the content to the top left corner. If a layer is sized up without a corresponding layer contents update this will result in missing/transparent pixels in the bottom or right part of the layer, explicitly showing what the result of the missing paint is. During debugging we also highlight this area by adding a magenta background color to the layer. Conversely, if the layer is sized down we don't need to resize it, we can just keep the fixed top left position, and the content will stay in place during the resize. This allows for optimizations during window resizing, where we don't need to allocate new buffers if the old buffer is larger than the new one. Change-Id: I265b57e3a0ddff8bbcda3af5d670cd8c3b00b181 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Resolve layer contents scale based on DPRTor Arne Vestbø2019-09-281-2/+30
| | | | | Change-Id: I32de4610a2aebbc7e0adcad9bb3440683cae5906 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Improve layer delegate setupTor Arne Vestbø2019-09-281-1/+7
| | | | | | | | We should detect the cases where there's already a delegate, and setting up the delegate before the layer is added makes sense. Change-Id: I67896cbc96d11ce9a3826fd8aa0e5e104a83a21c Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Flesh out and clarify layer setupTor Arne Vestbø2019-09-281-18/+50
| | | | | Change-Id: I10d972254c02de8789e64c8503861d51764a1633 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Propagate drawRect: dirty bounding rect as fallbackTor Arne Vestbø2019-09-281-3/+4
| | | | | Change-Id: I333e2bfe4a25bfbfebef7b2ec30a600fd441c9a9 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Gather QNSView draw callbacks togetherTor Arne Vestbø2019-09-281-39/+51
| | | | | | Change-Id: I29881b379481287b4938e47fc06405c918aa39a3 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Don't update Metal layer's drawableSize automaticallyTor Arne Vestbø2019-09-231-21/+2
| | | | | | | | | | | | | Like our other rendering code paths, the Metal path should allow the user to resize their surface when they see fit. This is the case today with e.g QBackingStore::resize() and QOpenGLPaintDevice::setSize(). [ChangeLog][macOS] The drawableSize of Metal layers is no longer updated automatically on window resize or screen change. Update the size manually in response to resizeEvent(), or at the start of each frame, as needed. Change-Id: I9ed6d4326d0e0a3f4e3c63984d3b193e8bb77cae Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Handle backing property changes in a single placeTor Arne Vestbø2019-09-231-8/+12
| | | | | Change-Id: I70d57632a1756f74249f64d4d4c405cb3120a179 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Merge remote-tracking branch 'origin/5.12' into 5.13Friedemann Kleint2019-05-141-0/+9
|\ | | | | | | Change-Id: Id3d16035c9692af42e9c1bf512218f3c836ae2eb
| * macOS: Guard against display on non-main threadsTor Arne Vestbø2019-05-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | AppKit will in some cases ask our view to display on secondary threads if we call APIs that are only supposed to be called on the main thread, such as -[NSOpenGLContext setView:] or -[NSOpenGLContext update]. Forwarding this display-request is bad, as QtGui expects all window system events to come on the main thread, and we can easily deadlock client code such as the Qt Quick threaded renderer. Change-Id: I1daeabf1dca6ca8ba908d3998b444a2089681e3a Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Liang Qi2019-04-161-0/+1
|\| | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qlocale.qdoc tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp Done-with: Edward Welbourne <edward.welbourne@qt.io> Done-with: Volker Hilsheimer <volker.hilsheimer@qt.io> Change-Id: I88e0757b2d020f0a244714c87844631df4b3fd13
| * macOS: set layer.delegate when setting a layerMorten Johan Sørvig2019-04-101-0/+1
| | | | | | | | | | | | | | Fixes flicker with Qt 5.12.2 on macOS 10.14.4. Change-Id: Ibb866d4339ecafae5fb573a653a2fb0f6238d704 Reviewed-by: Andy Shaw <andy.shaw@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-04-041-0/+2
|\| | | | | | | Change-Id: Ia7328524f2cd9d5995ac8705f0fe0bf570b2e831
| * macOS: Disable explicit layerContentsPlacementTor Arne Vestbø2019-04-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It was needed to allow lazy resize of the backingstore IOSurfaces, but that feature hasn't been enabled yet, and explicitly setting the layer's contents placement to NSViewLayerContentsPlacementTopLeft resulted in the layer animating when the window was moved from screens of different scale factors. We need to investigate this further, but in the meantime fix the visual regression by disabling the explicit layer contents placement. Change-Id: I63ea1eab9cf3fa6480e88844918ed98e6aa72620 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* | Merge remote-tracking branch 'origin/5.12' into 5.13Qt Forward Merge Bot2019-03-201-0/+7
|\| | | | | | | | | | | | | | | | | | | Conflicts: src/gui/kernel/qplatformintegration.cpp src/gui/kernel/qplatformintegration.h src/plugins/platforms/wasm/qwasmintegration.cpp src/plugins/platforms/xcb/qxcbconnection_screens.cpp Change-Id: I15063d42e9a1e226d9d2d2d372f75141b84c5c1b
| * macOS: Add IOSurface based backingstore for layer-backed viewsTor Arne Vestbø2019-03-141-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The naïve approach used for layer-backing in the past caused a detach of the backingstore QImage on each beginPaint, since the image was assigned to the layer via a CGImageRef that participated in the QImage implicit sharing (and had to, so we couldn't get around that). We now use IOSurfaces, wrapped in a QPlatformGraphicsBuffer abstraction. The surfaces can be assigned to the layer's content the same way images could, but allows us to reason more closely about whether or a buffer is in use, and increases the chance that we will have a zero-copy path to the screen. Unless the window has requested a surface format with single buffering we use a dynamic swap chain of buffers. In most situations there will be two buffers in play, one assigned to the layer and one ready to paint to, but during resize and some other situations the buffers will grow temporarily to accommodate the increased back-pressure. Since QBackingStore is documented as having single-buffer behavior, we take care to persist content between the buffers before every swap. By doing this before swapping, instead of before each paint, we can avoid preserving areas that will be painted to anyways, and will in many situations (such as blinking cursors e.g.) end up not persisting anything. The RasterGL surface case is handled by reading out the buffer data and doing a manual texture upload. In the future we can support direct texture access via CGLTexImageIOSurface2D, but this requires QPlatformBackingStore::composeAndFlush to learn how to support other targets than GL_TEXTURE_2D, as CGLTexImageIOSurface2D only works with GL_TEXTURE_RECTANGLE_ARB targets. Fixes: QTBUG-48763 Fixes: QTBUG-72360 Fixes: QTBUG-71162 Change-Id: Ica12f69b244e54d0fd31c929730d15657c286af8 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* | Fix can not -> cannotRobert Loehning2019-02-251-1/+1
|/ | | | | Change-Id: Ie9992f67ca59aff662a4be046ace08640e7c2714 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
* macOS: Only enable layer-backed views on 10.14 if built against 10.14 SDKTor Arne Vestbø2018-11-091-10/+51
| | | | | | | | | | | | | | Instead of explicitly enabling layer-backing for Qt 5.12 on all macOS version, we follow the macOS default to enable it for 10.14 if the application binary was built against the 10.14 SDK. Aligning ourselves with Apple's switch to forced layer-backing means we have an easier story when it comes to supporting different runtime configurations. Fixes: QTBUG-71499 Change-Id: I34ee49b3daeb6ed8df444a3759d3573ebc9ea30f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Propagate [NSOpenGLContext setView:] failuresTor Arne Vestbø2018-08-031-30/+2
| | | | | | | | | | | | | | | | | Instead of trying to mask situations where [NSOpenGLContext setView:] will fail (such as calling it for a view that's not part of a window yet, or part of a window that hasn't been shown), we report the error up through the API, so that QOpenGLContext::makeCurrent() will return false. This is documented to occur e.g. when "the surface is not exposed, or the graphics hardware is not available due to e.g. the application being suspended." QGLWidget was taught how to deal with this situation in cc27a50e. Other Qt APIs seem to handle it fine, but if regressions occur they should be fixable though the same logic as in cc27a50e. Change-Id: I92775fc165444696b6c5b44fa0e28ce3c4ad2190 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
* macOS: Remove dead updateRequest code based on setNeedsDisplayTor Arne Vestbø2018-07-091-35/+1
| | | | | | | We're no longer using this code path for QWindow::requestUpdate() Change-Id: I000304a4f1a6ea2c3a4e8268ae978dedd968e07c Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Remove declarative override of -[NSView wantsLayer]Alexandru Croitor2018-07-051-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | The -[NSView setWantsLayer:] method may have side effects that extend beyond just setting an internal boolean property, so we need to ensure it gets called. This was observed on e.g. macOS 10.12.5, where the method ends up creating the internal backing layer. On later macOS versions the method just emits KVO notifications for wantsLayer, but these may in turn result in similar logic being triggered. The issue was masked somewhat by AppKit itself calling the method from e.g. -[NSWindow setContentView:], so we still got the backing layer created. The problem appeared when running binaries built against an older SDK (10.6 in this case), which triggered AppKit to not call -[NSView setWantsLayer:], due to __NSViewLayerBackWindowFrame() in that case returning false. This change removes the overridden -[NSView wantsLayer], and replaces it with an explicit call to -[NSView setWantsLayer] when creating a new QNSView, essentially revering c8c8cc790a315710b0dae2282dc32. Task-number: PYSIDE-724 Task-number: PYSIDE-734 Change-Id: Idaff4ed38838311b37da4925b1eec241e077dbcc Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Make layer-backed mode the defaultTor Arne Vestbø2018-05-311-2/+2
| | | | | | | | | | | | | | | | | | QWindows are still backed by NSViews, but these views render to a CoreAnimation layer instead of directly to the top level NSWindow. This is the direction Apple is going (and is the only available option on iOS/tvOS), so we want to move away from the existing code path as soon as possible. The default can be reversed by setting QT_MAC_WANTS_LAYER=0, or the _q_mac_wantsLayer property on QWindow. [ChangeLog][macOS] Layer-backed mode is now the default for QWindow. Change-Id: Ibb9cc7541b179cad215d0daee14aeb1b54be614c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Minor metal support nits/cleanupsTor Arne Vestbø2018-05-301-3/+2
| | | | | | Change-Id: I840426ebf35b0fec64e92386fc3e1cabd91ced25 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Add QSurfaceType::MetalSurfaceMorten Johan Sørvig2018-05-111-5/+9
| | | | | | | | | | | | | | | | | | | | Add API to activate previously added Metal layer implementation. This provides minimal support, and unlike VulkanSurface there is no separate QWindow subclass. What this does do is configure the QWindow to use a Metal layer, and to send expose/update events when the layer content should be redrawn. Qt will also update the layer’s drawableSize and contentsScale when needed. Application code can make use of this by accessing the QWindow layer, which will be a CAMetalLayer: CAMetalLayer *metalLayer = reinterpret_cast<CAMetalLayer *>( reinterpret_cast<NSView *>(window->winId()).layer); Change-Id: I514f5186133c3e610fd4e53ca91fe9c85c6d016e Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* macOS: Experimental Vulkan support via MoltenVKMorten Johan Sørvig2018-05-081-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for QSurface::VulkanSurface and QVulkanWindow. Usage: 1) Build MoltenVK according to instructions 2) Configure Qt: ./configure -I /path/to/MoltenVK/Package/Release/MoltenVK/include 3) export QT_VULKAN_LIB=/path/to/MoltenVK/Package/Release/MoltenVK/macOS/libMoltenVK. Implement support for QSurface::VulkanSurface by enabling layer mode for QNSView and then creating a CAMetalLayer, which the MoltenVK translation layer can run on. MoltenVK provides an implementation of the Vulcan API, which means that the platform integration is similar to other platforms: implement a QCocoaVulkanInstance where we pass the QNSView instance to the vkCreateMacOSSurfaceMVK Vulkan surface constructor function. Using Vulkan directly without QVulkanWindow is possible, but not tested. We currently load libMoltenVK at run-time and use the existing QT_VULKAN_LIB environment variable to set its path. For deployment purposes it would be better to link against MoltenVK.frameworkm, but this Task-number: QTBUG-66966 Change-Id: I04ec6289c40b199dca9fed32902b5d2ad4e9c030 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* Merge remote-tracking branch 'origin/5.11' into devLiang Qi2018-05-031-1/+1
| | | | | | | | | | | | Conflicts: examples/widgets/graphicsview/elasticnodes/graphwidget.cpp examples/widgets/graphicsview/elasticnodes/node.cpp examples/widgets/graphicsview/elasticnodes/node.h src/plugins/platforms/cocoa/qnsview.mm src/plugins/platforms/cocoa/qnsview_drawing.mm src/widgets/kernel/qmacgesturerecognizer_p.h Change-Id: I13cf06bac75d48d779d8ee7b5c91bfc976f2a32c
* Provide QPlatformWindow::hasPendingUpdateRequest() helper functionTor Arne Vestbø2018-04-171-4/+2
| | | | | | | So that platform plugins don't need to dive into QWindowPrivate. Change-Id: Ia2d94b3e9236e4a68857e6afe7af063f1b0d0aeb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* macOS: Add logging when delivering update requestsTor Arne Vestbø2018-04-171-1/+0
| | | | | Change-Id: I2144e39c69fe79c0a31d5fb708abe4b20169d27a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Cocoa: Add QNSView Metal Layer supportMorten Johan Sørvig2018-04-121-2/+58
| | | | | | | | | | | | | | | | | Make sure the layer is updated on window resize and screen change. Add a support test and print a warning if we try to create a Metal layer without Metal system support. This test should ideally be done earlier, before configuring the QWindow to use Metal. Link against the Metal framework: The minimum deployment target is already 10.11 so this does not add additional deployment requirements. Change-Id: I0a38e824d0b6042bb52520dfaf0958ce21bb40b8 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Move delivery of update requests into QPlatformWindowTor Arne Vestbø2018-03-291-1/+1
| | | | | | | | | | | | Having deliverUpdateRequest in QWindowPrivate was a bit awkward and asymmetric to the QPlatformWindow::requestUpdate() API. Keeping them together follows the existing pattern of plumbing things through the platform window, and also allows us to move away from platform plugins relying on QWindowPrivate implementation details. Change-Id: Ib131ccdd1c2bdd6ff1c8d95facbc3f6f88a1abcf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* macOS: Make [QNSView wantsLayer] declarativeTor Arne Vestbø2018-03-211-0/+12
| | | | | Change-Id: Ib5dc8178293d13542a54d51484181debd57580f5 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
* macOS: Remove stray qDebug in [QNSView setNeedsDisplayInRect:]Tor Arne Vestbø2018-03-201-1/+0
| | | | | Change-Id: Ia253edf84bc0c890f291499ed2635d8287b18327 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
* macOS: Do layer updates via the CALayerDelegate protocolTor Arne Vestbø2018-03-201-6/+3
| | | | | | | | | | | | | | | The updateLayer function is only called when the layer is a _NSViewBackingLayer instance, which is what the default implementation of [NSView makeBackingLayer] returns. Once we move to optionally returning a CAMetalLayer, we need to use the more generic displayLayer: API, so we do that now as a first step. This matches the way we draw and send expose events on iOS. Change-Id: I49721ff005ca9dfddebff645705f96b5ab46abb4 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
* macOS: Move QNSView drawing related functionality to its own fileTor Arne Vestbø2018-03-201-0/+162
Change-Id: Iaeaa5c57368445a1fd67d110823c919aa7173a7a Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>