[Webkit-unassigned] [Bug 279094] [macOS] Send playEffect() twice to Gamepad.actuator and it cannot stop with reset()
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Wed Sep 4 09:13:26 PDT 2024
https://bugs.webkit.org/show_bug.cgi?id=279094
--- Comment #2 from Basuke Suzuki <basuke at apple.com> ---
commit a63922a80e01fb65438cf6b77c9323e974bb9c4d
Author: Basuke Suzuki <basuke at apple.com>
Date: Tue Sep 3 17:22:13 2024 -0700
It worked. But not perfect
diff --git a/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.h b/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.h
index 0f89fd968954..ee6aa4de5601 100644
--- a/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.h
+++ b/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.h
@@ -81,6 +81,8 @@ private:
bool m_failedToStartRightTriggerEngine { false };
std::unique_ptr<GameControllerHapticEffect> m_currentDualRumbleEffect;
std::unique_ptr<GameControllerHapticEffect> m_currentTriggerRumbleEffect;
+ bool m_preventDualRumbleFinishNotification { false };
+ bool m_preventTriggerRumbleFinishNotification { false };
};
} // namespace WebCore
diff --git a/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.mm b/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.mm
index 435a62e6949a..b878619b6e64 100644
--- a/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.mm
+++ b/Source/WebCore/platform/gamepad/cocoa/GameControllerHapticEngines.mm
@@ -85,8 +85,17 @@ void GameControllerHapticEngines::playEffect(GamepadHapticEffectType type, const
if (!newEffect)
return completionHandler(false);
- if (currentEffect)
+ if (currentEffect) {
+ switch (type) {
+ case GamepadHapticEffectType::DualRumble:
+ m_preventDualRumbleFinishNotification = true;
+ break;
+ case GamepadHapticEffectType::TriggerRumble:
+ m_preventTriggerRumbleFinishNotification = true;
+ break;
+ }
currentEffect->stop();
+ }
currentEffect = WTFMove(newEffect);
ensureStarted(type, [weakThis = WeakPtr { *this }, type, effect = WeakPtr { *currentEffect }, completionHandler = WTFMove(completionHandler)](bool success) mutable {
@@ -135,9 +144,20 @@ void GameControllerHapticEngines::ensureStarted(GamepadHapticEffectType effectTy
}
completionHandler(success);
});
- auto startEngine = [weakThis = WeakPtr { *this }](CHHapticEngine *engine, CompletionHandler<void(bool)>&& completionHandler, std::function<void()>&& playersFinished) mutable {
- [engine startWithCompletionHandler:makeBlockPtr([weakThis = WTFMove(weakThis), engine, completionHandler = WTFMove(completionHandler), playersFinished](NSError* error) mutable {
- ensureOnMainRunLoop([completionHandler = WTFMove(completionHandler), success = !error]() mutable {
+ auto startEngine = [weakThis = WeakPtr { *this }, effectType](CHHapticEngine *engine, CompletionHandler<void(bool)>&& completionHandler, std::function<void()>&& playersFinished) mutable {
+ [engine startWithCompletionHandler:makeBlockPtr([weakThis = WTFMove(weakThis), engine, effectType, completionHandler = WTFMove(completionHandler), playersFinished](NSError* error) mutable {
+ ensureOnMainRunLoop([completionHandler = WTFMove(completionHandler), effectType, weakThis = WTFMove(weakThis), success = !error]() mutable {
+ if (weakThis) {
+ switch (effectType) {
+ case GamepadHapticEffectType::DualRumble:
+ weakThis->m_preventDualRumbleFinishNotification = false;
+ break;
+ case GamepadHapticEffectType::TriggerRumble:
+ weakThis->m_preventTriggerRumbleFinishNotification = false;
+ break;
+ }
+ }
+
completionHandler(success);
});
if (error)
@@ -156,14 +176,14 @@ void GameControllerHapticEngines::ensureStarted(GamepadHapticEffectType effectTy
if (weakThis)
weakThis->m_failedToStartLeftHandleEngine = !success;
}, [weakThis = WeakPtr { *this }] {
- if (weakThis && weakThis->m_currentDualRumbleEffect)
+ if (weakThis && weakThis->m_currentDualRumbleEffect && !weakThis->m_preventDualRumbleFinishNotification)
weakThis->m_currentDualRumbleEffect->leftEffectFinishedPlaying();
});
startEngine(m_rightHandleEngine.get(), [weakThis = WeakPtr { *this }, callbackAggregator](bool success) {
if (weakThis)
weakThis->m_failedToStartRightHandleEngine = !success;
}, [weakThis = WeakPtr { *this }] {
- if (weakThis && weakThis->m_currentDualRumbleEffect)
+ if (weakThis && weakThis->m_currentDualRumbleEffect && !weakThis->m_preventDualRumbleFinishNotification)
weakThis->m_currentDualRumbleEffect->rightEffectFinishedPlaying();
});
break;
@@ -172,14 +192,14 @@ void GameControllerHapticEngines::ensureStarted(GamepadHapticEffectType effectTy
if (weakThis)
weakThis->m_failedToStartLeftTriggerEngine = !success;
}, [weakThis = WeakPtr { *this }] {
- if (weakThis && weakThis->m_currentTriggerRumbleEffect)
+ if (weakThis && weakThis->m_currentTriggerRumbleEffect && !weakThis->m_preventTriggerRumbleFinishNotification)
weakThis->m_currentTriggerRumbleEffect->leftEffectFinishedPlaying();
});
startEngine(m_rightTriggerEngine.get(), [weakThis = WeakPtr { *this }, callbackAggregator](bool success) {
if (weakThis)
weakThis->m_failedToStartRightTriggerEngine = !success;
}, [weakThis = WeakPtr { *this }] {
- if (weakThis && weakThis->m_currentTriggerRumbleEffect)
+ if (weakThis && weakThis->m_currentTriggerRumbleEffect && !weakThis->m_preventTriggerRumbleFinishNotification)
weakThis->m_currentTriggerRumbleEffect->rightEffectFinishedPlaying();
});
break;
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20240904/fa5b1939/attachment-0001.htm>
More information about the webkit-unassigned
mailing list