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:
Maurice Kalinowski
2016-05-20 14:21:42 +02:00
parent 6d5f375644
commit c0319d1cfb

View File

@@ -1121,6 +1121,8 @@ bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes)
if (d->status == QCamera::UnloadedStatus)
return false;
bool result = false;
HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([modes, &result, d, this]() {
ComPtr<IFocusSettings> focusSettings;
ComPtr<IInspectable> 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;
} else {
emit error(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera focus modes."));
return false;
result = false;
return S_OK;
}
hr = focusSettings->put_Mode(mode);
Q_ASSERT_SUCCEEDED(hr);
@@ -1159,8 +1162,13 @@ bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes)
hr = d->focusControl.As(&focusControl2);
Q_ASSERT_SUCCEEDED(hr);
hr = focusControl2->Configure(focusSettings.Get());
RETURN_FALSE_IF_FAILED("Failed to configure camera focus control");
return true;
result = SUCCEEDED(hr);
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)
@@ -1224,7 +1232,11 @@ bool QWinRTCameraControl::focus()
if (!d->focusControl || status == AsyncStatus::Started)
return false;
QEventDispatcherWinRT::runOnXamlThread([&d, &hr]() {
hr = d->focusControl->FocusAsync(&d->focusOperation);
Q_ASSERT_SUCCEEDED(hr);
return S_OK;
});
const long errorCode = HRESULT_CODE(hr);
if (errorCode == ERROR_OPERATION_IN_PROGRESS
|| errorCode == ERROR_WRITE_PROTECT) {