From b8833ccc31b57724a14349e0efbac727a8fb5b56 Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Thu, 8 Dec 2022 13:45:45 +0100 Subject: [PATCH] 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. Change-Id: I02f4f48db3dcc3802dd56aa816988847fc5d4603 Reviewed-by: Laszlo Agocs (cherry picked from commit f0e98e35a1a0eb842548d008c1524a1e436bc934) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhimetal.mm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm index 45bb1296b0d..cc27cb44908 100644 --- a/src/gui/rhi/qrhimetal.mm +++ b/src/gui/rhi/qrhimetal.mm @@ -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;