Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event support, use for disconnection and inputs #20

Merged
merged 4 commits into from Jul 22, 2019
Merged

Add event support, use for disconnection and inputs #20

merged 4 commits into from Jul 22, 2019

Conversation

@Manishearth
Copy link
Member

Manishearth commented Jul 19, 2019

Allow the device to send events back to script
r? @asajeffrey

@Manishearth Manishearth force-pushed the events branch 5 times, most recently from 834d906 to b7d5165 Jul 19, 2019
@Manishearth Manishearth changed the title Add event support, use for disconnection Add event support, use for disconnection and inputs Jul 19, 2019
@Manishearth
Copy link
Member Author

Manishearth commented Jul 20, 2019

Okay, session ending is a total mess. We need:

  • The ability for JS to request the session to end, and get an event when the session is fully shut down
  • The ability for the device to decide it needs to end, and send the same event.
  • The ability for mock APIs to ask the device to shut down and notice when it's done

Currently, there are a bunch of things preventing this from happening:

  • Mock events are only processed if there is an rAF. There usually isn't in the tests
  • The device has no way to end the loop since it can't access it. Simply signalling disconnectedness as done here doesn't work since something needs to wake up the loop
  • There's no way for the headless device to "return" its receiver to the headless device

I think this will need a bunch of changes to work right.

I think we should just land this PR and servo/servo#23814 first as it improves some of the tests and makes them less flaky, then overhaul how we do mocking. The changes we need:

  • Don't have multiple mock discovery objects, just have a single one
  • Provide session objects with "quitter"s that loop back to their own event loop
  • route mock events through the main device event loop, perhaps as a core part of the API (Session.send_mock())

This will change a lot of things, thus the preference for landing the progress we have so far as-is to deal with intermittents.

Copy link
Member

asajeffrey left a comment

OK, I agree that this isn't perfect, but can land. I had a bunch of niggles but none of them are show-stoppers.

fn connected(&mut self) -> bool;

/// Quit the session
fn quit(&mut self);

This comment has been minimized.

@asajeffrey

asajeffrey Jul 22, 2019

Member

Can we just make this the Drop code for the device?

This comment has been minimized.

@Manishearth

Manishearth Jul 22, 2019

Author Member

Then XRSession would have to store an Option<Session> for no good reason.

fn set_event_callback(&mut self, callback: Box<dyn EventCallback>);

/// Whether the device is still connected
fn connected(&mut self) -> bool;

This comment has been minimized.

@asajeffrey

asajeffrey Jul 22, 2019

Member

Should this be an event rather than a flag that is polled?

This comment has been minimized.

@Manishearth

Manishearth Jul 22, 2019

Author Member

This is the communication issue I need to fix

/// Input source disconnected
RemoveInput(InputId),
/// Session ended by device
SessionEnd,

This comment has been minimized.

@asajeffrey

asajeffrey Jul 22, 2019

Member

Should there be an event for the device being disconnected too? Blur / focus events?

This comment has been minimized.

@Manishearth

Manishearth Jul 22, 2019

Author Member

Same thing as SessionEnd from the POV of the device IMO.

Blur/Focus yes, I just haven't gotten to it yet.

This comment has been minimized.

@Manishearth

Manishearth Jul 22, 2019

Author Member

We should probably have VisibilityStateChange instead


fn quit(&mut self) {
self.connected = false;
self.events.callback(Event::SessionEnd);

This comment has been minimized.

@asajeffrey

asajeffrey Jul 22, 2019

Member

Only send this event if the device is currently connected?

struct HeadlessDevice {
gl: Rc<dyn Gl>,
floor_transform: TypedRigidTransform3D<f32, Native, Floor>,
viewer_origin: TypedRigidTransform3D<f32, Viewer, Native>,
views: Views,
receiver: Receiver<MockDeviceMsg>,
events: EventBuffer,
inputs: Vec<InputInfo>,
disconnect_callbacks: Vec<Sender<()>>,

This comment has been minimized.

@asajeffrey

asajeffrey Jul 22, 2019

Member

Why is disconnect treated differently from the other events?

This comment has been minimized.

@Manishearth

Manishearth Jul 22, 2019

Author Member

The mock API requires we signal disconnection to have succeeded.

} else {
for callback in self.disconnect_callbacks.drain(..) {
let _ = callback.send(());
}

This comment has been minimized.

@asajeffrey

asajeffrey Jul 22, 2019

Member

Calling this method has a side-effect? I wasn't expecting that!

This comment has been minimized.

@Manishearth

Manishearth Jul 22, 2019

Author Member

Yeah, this isn't ideal, I want to change this in a followup.

@Manishearth
Copy link
Member Author

Manishearth commented Jul 22, 2019

@bors-servo r=asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

📌 Commit 4acb8fb has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

Testing commit 4acb8fb with merge 944bc16...

bors-servo added a commit that referenced this pull request Jul 22, 2019
Add event support, use for disconnection and inputs

Allow the device to send events back to script
r? @asajeffrey
@Manishearth
Copy link
Member Author

Manishearth commented Jul 22, 2019

@bors-servo r=asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

📌 Commit c3f0aa2 has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

Testing commit c3f0aa2 with merge 57f8ab8...

bors-servo added a commit that referenced this pull request Jul 22, 2019
Add event support, use for disconnection and inputs

Allow the device to send events back to script
r? @asajeffrey
@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

💔 Test failed - checks-travis

@Manishearth
Copy link
Member Author

Manishearth commented Jul 22, 2019

@bors-servo r=asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

📌 Commit bd38449 has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

Testing commit 0b1ec62 with merge 7c06970...

bors-servo added a commit that referenced this pull request Jul 22, 2019
Add event support, use for disconnection and inputs

Allow the device to send events back to script
r? @asajeffrey
@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

☀️ Test successful - checks-travis
State: approved= try=False

@Manishearth
Copy link
Member Author

Manishearth commented Jul 22, 2019

@bors-servo r=asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

📌 Commit 0b1ec62 has been approved by asajeffrey

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

Testing commit 0b1ec62 with merge 6603553...

bors-servo added a commit that referenced this pull request Jul 22, 2019
Add event support, use for disconnection and inputs

Allow the device to send events back to script
r? @asajeffrey
@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2019

☀️ Test successful - checks-travis
Approved by: asajeffrey
Pushing 6603553 to master...

@bors-servo bors-servo merged commit 0b1ec62 into master Jul 22, 2019
5 checks passed
5 checks passed
Travis CI - Branch Build Passed
Details
Travis CI - Pull Request Build Passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
homu Test successful
Details
bors-servo added a commit to servo/servo that referenced this pull request Jul 23, 2019
Partial support for events in WebXR

Needs servo/webxr#20

r? @asajeffrey

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23814)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Jul 23, 2019
Partial support for events in WebXR

Needs servo/webxr#20

r? @asajeffrey

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23814)
<!-- Reviewable:end -->
@Manishearth Manishearth deleted the events branch Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.