macOS: Remove drawRect and use plain CALayer for raster windows

The drawRect callback was used when we were supporting both surface-
backed and layer-backed drawing, but nowadays we only support layer-
backed drawing.

However we couldn't just remove the implementation, as the default
backing layer of an NSView is an NSViewBackingLayer, which in its
override of [CALayer display] checks whether the view implements
drawRect, and if not bails out, which meant we never reached our
displayLayer callback from [CALayer display].

But, we don't need NSViewBackingLayer, as we handle layer updates
and draw callbacks in a more generic way, to support CAMetalLayer,
so instead we now use a plain CALayer as our backing layer for
raster windows.

Change-Id: I5b878ff51ca92dafcb80bf5a686ced13088cfa28
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2025-04-02 01:01:04 +02:00
parent 98e0a7e0a0
commit 1b5e22be23

View File

@ -85,7 +85,12 @@
}
}
return [super makeBackingLayer];
// We handle drawing via displayLayer instead of drawRect or updateLayer,
// as the latter two do not work for CAMetalLayer. And we handle content
// scale manually for the same reason. Which means we don't really need
// NSViewBackingLayer. In fact it just gets in the way, by assuming that
// if we don't have a drawRect function we "draw nothing".
return [CALayer layer];
}
/*
@ -200,21 +205,9 @@
// ----------------------- Draw callbacks -----------------------
/*
This method is called by AppKit for the non-layer case, where we are
drawing into the NSWindow's surface.
*/
- (void)drawRect:(NSRect)dirtyBoundingRect
{
Q_UNUSED(dirtyBoundingRect);
// As we are layer backed we shouldn't really end up here, but AppKit will
// in some cases call this method just because we implement it.
// FIXME: Remove drawRect and switch from displayLayer to updateLayer
qCWarning(lcQpaDrawing) << "[QNSView drawRect] called for layer backed view";
}
/*
This method is called by AppKit when we are layer-backed, where
we are drawing into the layer.
We set our view up as the layer's delegate, which means we get
first dibs on displaying the layer, without needing to go through
updateLayer or drawRect.
*/
- (void)displayLayer:(CALayer *)layer
{