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

Gamepad: Implement GamepadHapticActuator #32046

Merged
merged 27 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bebef47
Implement Servo side of GamepadHapticActuator
msub2 Mar 6, 2024
ec18ed7
Get build working
msub2 Mar 7, 2024
99de588
Create effect handling on embedder side
msub2 Mar 10, 2024
93a9b6e
Update tracing for GamepadHapticEffect
msub2 Apr 9, 2024
c19fa6b
Update gilrs to point to commit with effect complete event
msub2 Apr 9, 2024
986b72b
Implement playing and preempting haptic effects
msub2 Apr 9, 2024
831a30b
Update IDL to add trigger rumble
msub2 Apr 10, 2024
71fddec
Update WPT expectations
msub2 Apr 10, 2024
fb8fab5
Handle stopping haptic effects from reset()
msub2 Apr 10, 2024
3709393
./mach fmt, fix test-tidy issues
msub2 Apr 10, 2024
eda10b4
Add extra validity checks for trigger rumble
msub2 Apr 10, 2024
2f191d6
Retrieve supported haptic effects from embedder
msub2 Apr 10, 2024
f0aef54
Fix test expectations
msub2 Apr 11, 2024
e85deca
Add missing spec link, pin gilrs commit
msub2 Apr 11, 2024
c3f65bd
servoshell cargo formatting
msub2 Apr 11, 2024
2735098
Fix Cargo.toml
msub2 Jun 27, 2024
cddb537
Additional comments, realm proof, naming
msub2 Jun 30, 2024
dd5ac03
./mach fmt
msub2 Jul 3, 2024
2b41cd0
Update gilrs rev to gilrs-core 0.5.12 release
msub2 Jul 4, 2024
c380489
Implement sequence ids for gamepad haptic promises
msub2 Jul 5, 2024
e75786d
Take playing effect promise instead of cloning
msub2 Jul 6, 2024
b107d72
Implement listener for reset function
msub2 Jul 14, 2024
aca6d77
Fix Cargo.lock
msub2 Jul 14, 2024
fe63c74
Restructure IPC listeners, add comments, handle visibility change
msub2 Jul 16, 2024
d70e784
Check that haptic effect still exists before handling ff completion e…
msub2 Jul 18, 2024
e9c8cf3
Visibility steps, add InRealm bindings for promises
msub2 Jul 19, 2024
ec8e661
Add Gamepad EmbedderMsg arms to egl servo_glue
msub2 Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/constellation/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ mod from_script {
Self::OnDevtoolsStarted(..) => target_variant!("OnDevtoolsStarted"),
Self::ReadyToPresent(..) => target_variant!("ReadyToPresent"),
Self::EventDelivered(..) => target_variant!("EventDelivered"),
Self::PlayGamepadHapticEffect(..) => target_variant!("PlayGamepadHapticEffect"),
Self::StopGamepadHapticEffect(..) => target_variant!("StopGamepadHapticEffect"),
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/bindings/codegen/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ DOMInterfaces = {
'CreateRenderPipelineAsync',
'CreateShaderModule' # Creates promise for compilation info
],
},

'GamepadHapticActuator': {
'inRealms': ['PlayEffect', 'Reset']
}

}
13 changes: 13 additions & 0 deletions components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4125,6 +4125,19 @@ impl Document {
// Step 6 Run any page visibility change steps which may be defined in other specifications, with visibility
// state and document. Any other specs' visibility steps will go here.

// <https://www.w3.org/TR/gamepad/#handling-visibility-change>
if visibility_state == DocumentVisibilityState::Hidden {
self.window
.Navigator()
.GetGamepads()
.iter_mut()
.for_each(|gamepad| {
if let Some(g) = gamepad {
g.vibration_actuator().handle_visibility_change();
}
});
}

// Step 7 Fire an event named visibilitychange at document, with its bubbles attribute initialized to true.
self.upcast::<EventTarget>()
.fire_bubbling_event(atom!("visibilitychange"));
Expand Down
29 changes: 27 additions & 2 deletions components/script/dom/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::cell::Cell;

use dom_struct::dom_struct;
use js::typedarray::{Float64, Float64Array};
use script_traits::GamepadUpdateType;
use script_traits::{GamepadSupportedHapticEffects, GamepadUpdateType};

use super::bindings::buffer_source::HeapBufferSource;
use crate::dom::bindings::codegen::Bindings::GamepadBinding::{GamepadHand, GamepadMethods};
Expand All @@ -20,6 +20,7 @@ use crate::dom::event::Event;
use crate::dom::eventtarget::EventTarget;
use crate::dom::gamepadbuttonlist::GamepadButtonList;
use crate::dom::gamepadevent::{GamepadEvent, GamepadEventType};
use crate::dom::gamepadhapticactuator::GamepadHapticActuator;
use crate::dom::gamepadpose::GamepadPose;
use crate::dom::globalscope::GlobalScope;
use crate::script_runtime::JSContext;
Expand Down Expand Up @@ -49,6 +50,7 @@ pub struct Gamepad {
axis_bounds: (f64, f64),
button_bounds: (f64, f64),
exposed: Cell<bool>,
vibration_actuator: Dom<GamepadHapticActuator>,
}

impl Gamepad {
Expand All @@ -65,6 +67,7 @@ impl Gamepad {
hand: GamepadHand,
axis_bounds: (f64, f64),
button_bounds: (f64, f64),
vibration_actuator: &GamepadHapticActuator,
) -> Gamepad {
Self {
reflector_: Reflector::new(),
Expand All @@ -81,6 +84,7 @@ impl Gamepad {
axis_bounds,
button_bounds,
exposed: Cell::new(false),
vibration_actuator: Dom::from_ref(vibration_actuator),
}
}

Expand All @@ -90,8 +94,16 @@ impl Gamepad {
id: String,
axis_bounds: (f64, f64),
button_bounds: (f64, f64),
supported_haptic_effects: GamepadSupportedHapticEffects,
) -> DomRoot<Gamepad> {
Self::new_with_proto(global, gamepad_id, id, axis_bounds, button_bounds)
Self::new_with_proto(
global,
gamepad_id,
id,
axis_bounds,
button_bounds,
supported_haptic_effects,
)
}

/// When we construct a new gamepad, we initialize the number of buttons and
Expand All @@ -105,8 +117,11 @@ impl Gamepad {
id: String,
axis_bounds: (f64, f64),
button_bounds: (f64, f64),
supported_haptic_effects: GamepadSupportedHapticEffects,
) -> DomRoot<Gamepad> {
let button_list = GamepadButtonList::init_buttons(global);
let vibration_actuator =
GamepadHapticActuator::new(global, gamepad_id, supported_haptic_effects);
let gamepad = reflect_dom_object_with_proto(
Box::new(Gamepad::new_inherited(
gamepad_id,
Expand All @@ -120,6 +135,7 @@ impl Gamepad {
GamepadHand::_empty,
axis_bounds,
button_bounds,
&vibration_actuator,
)),
global,
None,
Expand Down Expand Up @@ -165,6 +181,11 @@ impl GamepadMethods for Gamepad {
DomRoot::from_ref(&*self.buttons)
}

// https://w3c.github.io/gamepad/#dom-gamepad-vibrationactuator
fn VibrationActuator(&self) -> DomRoot<GamepadHapticActuator> {
DomRoot::from_ref(&*self.vibration_actuator)
}

// https://w3c.github.io/gamepad/extensions.html#gamepadhand-enum
fn Hand(&self) -> GamepadHand {
self.hand
Expand Down Expand Up @@ -286,6 +307,10 @@ impl Gamepad {
pub fn set_exposed(&self, exposed: bool) {
self.exposed.set(exposed);
}

pub fn vibration_actuator(&self) -> &GamepadHapticActuator {
&*self.vibration_actuator
}
}

/// <https://www.w3.org/TR/gamepad/#dfn-gamepad-user-gesture>
Expand Down
Loading