winrt: focus action has to happen in the xaml thread
Otherwise it will cause asserts and/or crashes. Change-Id: If8af4202395ae573b280744343dd853346a8c160 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
@@ -1121,6 +1121,8 @@ bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes)
|
|||||||
if (d->status == QCamera::UnloadedStatus)
|
if (d->status == QCamera::UnloadedStatus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([modes, &result, d, this]() {
|
||||||
ComPtr<IFocusSettings> focusSettings;
|
ComPtr<IFocusSettings> focusSettings;
|
||||||
ComPtr<IInspectable> focusSettingsObject;
|
ComPtr<IInspectable> focusSettingsObject;
|
||||||
HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_Devices_FocusSettings).Get(), &focusSettingsObject);
|
HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_Devices_FocusSettings).Get(), &focusSettingsObject);
|
||||||
@@ -1139,7 +1141,8 @@ bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes)
|
|||||||
mode = FocusMode_Single;
|
mode = FocusMode_Single;
|
||||||
} else {
|
} else {
|
||||||
emit error(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera focus modes."));
|
emit error(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera focus modes."));
|
||||||
return false;
|
result = false;
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
hr = focusSettings->put_Mode(mode);
|
hr = focusSettings->put_Mode(mode);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
@@ -1159,8 +1162,13 @@ bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes)
|
|||||||
hr = d->focusControl.As(&focusControl2);
|
hr = d->focusControl.As(&focusControl2);
|
||||||
Q_ASSERT_SUCCEEDED(hr);
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
hr = focusControl2->Configure(focusSettings.Get());
|
hr = focusControl2->Configure(focusSettings.Get());
|
||||||
RETURN_FALSE_IF_FAILED("Failed to configure camera focus control");
|
result = SUCCEEDED(hr);
|
||||||
return true;
|
RETURN_OK_IF_FAILED("Failed to configure camera focus control");
|
||||||
|
return S_OK;
|
||||||
|
});
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
Q_UNUSED(hr); // Silence release build
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QWinRTCameraControl::setFocusPoint(const QPointF &focusPoint)
|
bool QWinRTCameraControl::setFocusPoint(const QPointF &focusPoint)
|
||||||
@@ -1224,7 +1232,11 @@ bool QWinRTCameraControl::focus()
|
|||||||
if (!d->focusControl || status == AsyncStatus::Started)
|
if (!d->focusControl || status == AsyncStatus::Started)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
QEventDispatcherWinRT::runOnXamlThread([&d, &hr]() {
|
||||||
hr = d->focusControl->FocusAsync(&d->focusOperation);
|
hr = d->focusControl->FocusAsync(&d->focusOperation);
|
||||||
|
Q_ASSERT_SUCCEEDED(hr);
|
||||||
|
return S_OK;
|
||||||
|
});
|
||||||
const long errorCode = HRESULT_CODE(hr);
|
const long errorCode = HRESULT_CODE(hr);
|
||||||
if (errorCode == ERROR_OPERATION_IN_PROGRESS
|
if (errorCode == ERROR_OPERATION_IN_PROGRESS
|
||||||
|| errorCode == ERROR_WRITE_PROTECT) {
|
|| errorCode == ERROR_WRITE_PROTECT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user