GameControllerGamepadProvider.h [plain text]
#pragma once
#if ENABLE(GAMEPAD)
#include "GamepadProvider.h"
#include <wtf/HashMap.h>
#include <wtf/RetainPtr.h>
#include <wtf/RunLoop.h>
OBJC_CLASS GCController;
OBJC_CLASS NSObject;
namespace WebCore {
class GameControllerGamepad;
class GamepadProviderClient;
class GameControllerGamepadProvider : public GamepadProvider {
WTF_MAKE_NONCOPYABLE(GameControllerGamepadProvider);
friend class NeverDestroyed<GameControllerGamepadProvider>;
public:
WEBCORE_EXPORT static GameControllerGamepadProvider& singleton();
WEBCORE_EXPORT void startMonitoringGamepads(GamepadProviderClient&) final;
WEBCORE_EXPORT void stopMonitoringGamepads(GamepadProviderClient&) final;
const Vector<PlatformGamepad*>& platformGamepads() final { return m_gamepadVector; }
WEBCORE_EXPORT void stopMonitoringInput();
WEBCORE_EXPORT void startMonitoringInput();
void gamepadHadInput(GameControllerGamepad&, bool hadButtonPresses);
void prewarmGameControllerDevicesIfNecessary();
void makeInvisibleGamepadsVisible();
size_t numberOfConnectedGamepads() const { return m_gamepadMap.size(); };
#if !HAVE(GCCONTROLLER_HID_DEVICE_CHECK)
static bool willHandleVendorAndProduct(uint16_t vendorID, uint16_t productID);
#endif
private:
GameControllerGamepadProvider();
enum class ConnectionVisibility {
Visible,
Invisible,
};
void controllerDidConnect(GCController *, ConnectionVisibility);
void controllerDidDisconnect(GCController *);
unsigned indexForNewlyConnectedDevice();
void inputNotificationTimerFired();
HashMap<CFTypeRef, std::unique_ptr<GameControllerGamepad>> m_gamepadMap;
Vector<PlatformGamepad*> m_gamepadVector;
HashSet<PlatformGamepad*> m_invisibleGamepads;
RetainPtr<NSObject> m_connectObserver;
RetainPtr<NSObject> m_disconnectObserver;
RunLoop::Timer<GameControllerGamepadProvider> m_inputNotificationTimer;
bool m_shouldMakeInvisibleGamepadsVisible { false };
};
}
#endif // ENABLE(GAMEPAD)