UI: Fix Qt call on UI thread from graphics thread

Calling `devicePixelRatioF` from any thread but the main UI thread
triggers thread-safety warnings at runtime on macOS, because Qt uses
NSView calls to determine the value.

NSView calls are only allowed to be made from the main thread on macOS,
so instead the value is stored as a property of the OBSQTDisplay at
initialization, to be retrieved from the preview object later.

Static functions that do not have access to the preview object have the
pixel ratio passed in their call signature.
This commit is contained in:
PatTheMav
2022-07-29 20:31:13 +02:00
committed by Patrick Heyer
parent 37526e9ac9
commit f1cf3ff141
3 changed files with 31 additions and 22 deletions

View File

@@ -319,7 +319,9 @@ OBSBasic::OBSBasic(QWidget *parent)
ResizePreview(ovi.base_width, ovi.base_height);
UpdateContextBarVisibility();
dpi = devicePixelRatioF();
};
dpi = devicePixelRatioF();
connect(windowHandle(), &QWindow::screenChanged, displayResize);
connect(ui->preview, &OBSQTDisplay::DisplayResized, displayResize);
@@ -10241,3 +10243,8 @@ void OBSBasic::UpdatePreviewSpacingHelpers()
drawSpacingHelpers = config_get_bool(
App()->GlobalConfig(), "BasicWindow", "SpacingHelpersEnabled");
}
float OBSBasic::GetDevicePixelRatio()
{
return dpi;
}