summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2022-12-08 13:45:45 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2022-12-13 12:41:29 +0000
commitf0e98e35a1a0eb842548d008c1524a1e436bc934 (patch)
tree3d061a2839ca7d7734396bc9ab451b001439fe9b /src/gui/rhi
parenta46a77a8b4c755c72168a57a1140af5d940257ae (diff)
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>
Diffstat (limited to 'src/gui/rhi')
-rw-r--r--src/gui/rhi/qrhimetal.mm13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/gui/rhi/qrhimetal.mm b/src/gui/rhi/qrhimetal.mm
index 45bb1296b0..cc27cb4490 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;