Auto merge of #26312 - jdm:webxr-debug, r=Manishearth

Provide feedback when OpenXR can't start

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26213
- [x] These changes do not require tests because it's testing an edge case in an environment we can't test on CI
This commit is contained in:
bors-servo 2020-04-24 21:03:55 -04:00 committed by GitHub
commit 8c73fb997a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 26 deletions

4
Cargo.lock generated
View file

@ -6422,7 +6422,7 @@ dependencies = [
[[package]] [[package]]
name = "webxr" name = "webxr"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/webxr#836a08e1168e3a2b0b0fa12d7987603d5fc79002" source = "git+https://github.com/servo/webxr#6ead41b15b0c72ef8bd98af0c09f4fefec888aac"
dependencies = [ dependencies = [
"android_injected_glue", "android_injected_glue",
"bindgen", "bindgen",
@ -6445,7 +6445,7 @@ dependencies = [
[[package]] [[package]]
name = "webxr-api" name = "webxr-api"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/servo/webxr#836a08e1168e3a2b0b0fa12d7987603d5fc79002" source = "git+https://github.com/servo/webxr#6ead41b15b0c72ef8bd98af0c09f4fefec888aac"
dependencies = [ dependencies = [
"euclid", "euclid",
"ipc-channel", "ipc-channel",

View file

@ -267,7 +267,8 @@ impl XRSystem {
) { ) {
let session = match response { let session = match response {
Ok(session) => session, Ok(session) => session,
Err(_) => { Err(e) => {
warn!("Error requesting XR session: {:?}", e);
if mode != XRSessionMode::Inline { if mode != XRSessionMode::Inline {
self.pending_immersive_session.set(false); self.pending_immersive_session.set(false);
} }

View file

@ -810,7 +810,7 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
} }
struct GlThread(WebGlExecutor); struct GlThread(WebGlExecutor);
impl webxr::openxr::GlThread for GlThread { impl openxr::GlThread for GlThread {
fn execute(&self, runnable: Box<dyn FnOnce(&surfman::Device) + Send>) { fn execute(&self, runnable: Box<dyn FnOnce(&surfman::Device) + Send>) {
let _ = self.0.send(runnable); let _ = self.0.send(runnable);
} }
@ -819,12 +819,27 @@ impl EmbedderMethods for ServoEmbedderCallbacks {
} }
} }
let discovery = webxr::openxr::OpenXrDiscovery::new( if openxr::create_instance().is_ok() {
Box::new(GlThread(executor)), let discovery = openxr::OpenXrDiscovery::new(
Box::new(ProviderRegistration(surface_providers)), Box::new(GlThread(executor)),
Box::new(ContextMenuCallback(embedder_proxy)), Box::new(ProviderRegistration(surface_providers)),
); Box::new(ContextMenuCallback(embedder_proxy)),
registry.register(discovery); );
registry.register(discovery);
} else {
let msg =
"Cannot initialize OpenXR - please ensure runtime is installed and enabled in \
the OpenXR developer portal app.\n\nImmersive mode will not function until \
this error is fixed.";
let (sender, _receiver) = ipc::channel().unwrap();
embedder_proxy.send((
None,
EmbedderMsg::Prompt(
PromptDefinition::Alert(msg.to_owned(), sender),
PromptOrigin::Trusted,
),
));
}
} }
#[cfg(not(feature = "uwp"))] #[cfg(not(feature = "uwp"))]

View file

@ -161,21 +161,31 @@ Servo::Servo(hstring url, hstring args, GLsizei width, GLsizei height,
sServo = this; // FIXME; sServo = this; // FIXME;
#ifdef _DEBUG #ifndef _DEBUG
auto current = winrt::Windows::Storage::ApplicationData::Current(); char buffer[1024];
auto filePath = std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt"; bool logToFile = GetEnvironmentVariableA("FirefoxRealityLogStdout", buffer,
sLogHandle = sizeof(buffer)) != 0;
CreateFile2(filePath.c_str(), GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr); #else
if (sLogHandle == INVALID_HANDLE_VALUE) bool logToFile = true;
throw std::runtime_error("Failed to open the log file: error code " +
std::to_string(GetLastError()));
if (SetFilePointer(sLogHandle, 0, nullptr, FILE_END) ==
INVALID_SET_FILE_POINTER)
throw std::runtime_error(
"Failed to set file pointer to the end of file: error code " +
std::to_string(GetLastError()));
#endif #endif
if (logToFile) {
auto current = winrt::Windows::Storage::ApplicationData::Current();
auto filePath =
std::wstring(current.LocalFolder().Path()) + L"\\stdout.txt";
sLogHandle =
CreateFile2(filePath.c_str(), GENERIC_WRITE, 0, CREATE_ALWAYS, nullptr);
if (sLogHandle == INVALID_HANDLE_VALUE) {
throw std::runtime_error("Failed to open the log file: error code " +
std::to_string(GetLastError()));
}
if (SetFilePointer(sLogHandle, 0, nullptr, FILE_END) ==
INVALID_SET_FILE_POINTER) {
throw std::runtime_error(
"Failed to set file pointer to the end of file: error code " +
std::to_string(GetLastError()));
}
}
capi::CHostCallbacks c; capi::CHostCallbacks c;
c.on_load_started = &on_load_started; c.on_load_started = &on_load_started;

View file

@ -453,10 +453,10 @@ ServoControl::PromptSync(hstring title, hstring message, hstring primaryButton,
dialog.PrimaryButtonText(primaryButton); dialog.PrimaryButtonText(primaryButton);
if (secondaryButton.has_value()) { if (secondaryButton.has_value()) {
dialog.IsPrimaryButtonEnabled(true); dialog.IsSecondaryButtonEnabled(true);
dialog.SecondaryButtonText(*secondaryButton); dialog.SecondaryButtonText(*secondaryButton);
} else { } else {
dialog.IsPrimaryButtonEnabled(false); dialog.IsSecondaryButtonEnabled(false);
} }
auto titleBlock = Controls::TextBlock(); auto titleBlock = Controls::TextBlock();