Metal rhi: Cast layer bounds to int before multiplying by scale factor

In qrhimetal, we were setting the current pixel size by multiplying
the width/height of the CAMetal layer bounds, which are floats, with
the scale factor, and then rounded these to the nearest integers by
converting from QSizeF to QSize.

This caused problems, namely a crash when trying to resize a modal view
controller on iOS, because Metal expected the height of the render pass
to be equal to (int)height * scaleFactor. So looks like we were relying
on the truncated rather than rounded value of the height for this.

To fix, cast the layer width/height to int before multiplying with the
scale factor, to be consistent.

Pick-to: 6.5
Change-Id: I02f4f48db3dcc3802dd56aa816988847fc5d4603
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Doris Verria 2022-12-08 13:45:45 +01:00 committed by Laszlo Agocs
parent a46a77a8b4
commit f0e98e35a1

View File

@ -5483,10 +5483,11 @@ QSize QMetalSwapChain::surfacePixelSize()
if (!layer)
layer = layerForWindow(m_window);
CGSize layerSize = layer.bounds.size;
layerSize.width *= layer.contentsScale;
layerSize.height *= layer.contentsScale;
return QSizeF::fromCGSize(layerSize).toSize();
int height = (int)layer.bounds.size.height;
int width = (int)layer.bounds.size.width;
width *= layer.contentsScale;
height *= layer.contentsScale;
return QSize(width, height);
}
bool QMetalSwapChain::isFormatSupported(Format f)
@ -5592,7 +5593,9 @@ bool QMetalSwapChain::createOrResize()
// Now set the layer's drawableSize which will stay set to the same value
// until the next createOrResize(), thus ensuring atomicity with regards to
// the drawable size in frames.
CGSize layerSize = d->layer.bounds.size;
int width = (int)d->layer.bounds.size.width;
int height = (int)d->layer.bounds.size.height;
CGSize layerSize = CGSizeMake(width, height);
layerSize.width *= d->layer.contentsScale;
layerSize.height *= d->layer.contentsScale;
d->layer.drawableSize = layerSize;