diff options
Diffstat (limited to 'src/core/hle/service/hid/resource_manager.cpp')
-rw-r--r-- | src/core/hle/service/hid/resource_manager.cpp | 161 |
1 files changed, 94 insertions, 67 deletions
diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index 6c6cbd802..1f41e645d 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -10,18 +10,23 @@ #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/hid/controllers/applet_resource.h" +#include "core/hle/service/hid/controllers/capture_button.h" #include "core/hle/service/hid/controllers/console_six_axis.h" +#include "core/hle/service/hid/controllers/debug_mouse.h" #include "core/hle/service/hid/controllers/debug_pad.h" +#include "core/hle/service/hid/controllers/digitizer.h" #include "core/hle/service/hid/controllers/gesture.h" +#include "core/hle/service/hid/controllers/home_button.h" #include "core/hle/service/hid/controllers/keyboard.h" #include "core/hle/service/hid/controllers/mouse.h" #include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/palma.h" #include "core/hle/service/hid/controllers/seven_six_axis.h" -#include "core/hle/service/hid/controllers/shared_memory_format.h" #include "core/hle/service/hid/controllers/six_axis.h" -#include "core/hle/service/hid/controllers/stubbed.h" +#include "core/hle/service/hid/controllers/sleep_button.h" #include "core/hle/service/hid/controllers/touchscreen.h" +#include "core/hle/service/hid/controllers/types/shared_memory_format.h" +#include "core/hle/service/hid/controllers/unique_pad.h" namespace Service::HID { @@ -46,42 +51,13 @@ void ResourceManager::Initialize() { } system.HIDCore().ReloadInputDevices(); - is_initialized = true; -} - -void ResourceManager::InitializeController(u64 aruid) { - SharedMemoryFormat* shared_memory = nullptr; - const auto result = applet_resource->GetSharedMemoryFormat(&shared_memory, aruid); - if (result.IsError()) { - return; - } - debug_pad = std::make_shared<DebugPad>(system.HIDCore(), shared_memory->debug_pad); - mouse = std::make_shared<Mouse>(system.HIDCore(), shared_memory->mouse); - debug_mouse = std::make_shared<DebugMouse>(system.HIDCore(), shared_memory->debug_mouse); - keyboard = std::make_shared<Keyboard>(system.HIDCore(), shared_memory->keyboard); - unique_pad = std::make_shared<UniquePad>(system.HIDCore(), shared_memory->unique_pad.header); - npad = std::make_shared<NPad>(system.HIDCore(), shared_memory->npad, service_context); - gesture = std::make_shared<Gesture>(system.HIDCore(), shared_memory->gesture); - touch_screen = std::make_shared<TouchScreen>(system.HIDCore(), shared_memory->touch_screen); + InitializeHidCommonSampler(); + InitializeTouchScreenSampler(); + InitializeConsoleSixAxisSampler(); + InitializeAHidSampler(); - palma = std::make_shared<Palma>(system.HIDCore(), service_context); - - home_button = std::make_shared<HomeButton>(system.HIDCore(), shared_memory->home_button.header); - sleep_button = - std::make_shared<SleepButton>(system.HIDCore(), shared_memory->sleep_button.header); - capture_button = - std::make_shared<CaptureButton>(system.HIDCore(), shared_memory->capture_button.header); - digitizer = std::make_shared<Digitizer>(system.HIDCore(), shared_memory->digitizer.header); - - six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad); - console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore(), shared_memory->console); - seven_six_axis = std::make_shared<SevenSixAxis>(system); - - // Homebrew doesn't try to activate some controllers, so we activate them by default - npad->Activate(); - six_axis->Activate(); - touch_screen->Activate(); + is_initialized = true; } std::shared_ptr<AppletResource> ResourceManager::GetAppletResource() const { @@ -153,28 +129,77 @@ std::shared_ptr<UniquePad> ResourceManager::GetUniquePad() const { } Result ResourceManager::CreateAppletResource(u64 aruid) { - if (aruid == 0) { + if (aruid == SystemAruid) { const auto result = RegisterCoreAppletResource(); if (result.IsError()) { return result; } - return GetNpad()->Activate(); + return GetNpad()->ActivateNpadResource(); } const auto result = CreateAppletResourceImpl(aruid); if (result.IsError()) { return result; } - return GetNpad()->Activate(aruid); + + // Homebrew doesn't try to activate some controllers, so we activate them by default + npad->Activate(); + six_axis->Activate(); + touch_screen->Activate(); + + return GetNpad()->ActivateNpadResource(aruid); } Result ResourceManager::CreateAppletResourceImpl(u64 aruid) { std::scoped_lock lock{shared_mutex}; - const auto result = applet_resource->CreateAppletResource(aruid); - if (result.IsSuccess()) { - InitializeController(aruid); - } - return result; + return applet_resource->CreateAppletResource(aruid); +} + +void ResourceManager::InitializeHidCommonSampler() { + debug_pad = std::make_shared<DebugPad>(system.HIDCore()); + mouse = std::make_shared<Mouse>(system.HIDCore()); + debug_mouse = std::make_shared<DebugMouse>(system.HIDCore()); + keyboard = std::make_shared<Keyboard>(system.HIDCore()); + unique_pad = std::make_shared<UniquePad>(system.HIDCore()); + npad = std::make_shared<NPad>(system.HIDCore(), service_context); + gesture = std::make_shared<Gesture>(system.HIDCore()); + home_button = std::make_shared<HomeButton>(system.HIDCore()); + sleep_button = std::make_shared<SleepButton>(system.HIDCore()); + capture_button = std::make_shared<CaptureButton>(system.HIDCore()); + digitizer = std::make_shared<Digitizer>(system.HIDCore()); + + palma = std::make_shared<Palma>(system.HIDCore(), service_context); + six_axis = std::make_shared<SixAxis>(system.HIDCore(), npad); + + debug_pad->SetAppletResource(applet_resource, &shared_mutex); + digitizer->SetAppletResource(applet_resource, &shared_mutex); + keyboard->SetAppletResource(applet_resource, &shared_mutex); + npad->SetNpadExternals(applet_resource, &shared_mutex); + six_axis->SetAppletResource(applet_resource, &shared_mutex); + mouse->SetAppletResource(applet_resource, &shared_mutex); + debug_mouse->SetAppletResource(applet_resource, &shared_mutex); + home_button->SetAppletResource(applet_resource, &shared_mutex); + sleep_button->SetAppletResource(applet_resource, &shared_mutex); + capture_button->SetAppletResource(applet_resource, &shared_mutex); +} + +void ResourceManager::InitializeTouchScreenSampler() { + gesture = std::make_shared<Gesture>(system.HIDCore()); + touch_screen = std::make_shared<TouchScreen>(system.HIDCore()); + + touch_screen->SetAppletResource(applet_resource, &shared_mutex); + gesture->SetAppletResource(applet_resource, &shared_mutex); +} + +void ResourceManager::InitializeConsoleSixAxisSampler() { + console_six_axis = std::make_shared<ConsoleSixAxis>(system.HIDCore()); + seven_six_axis = std::make_shared<SevenSixAxis>(system); + + console_six_axis->SetAppletResource(applet_resource, &shared_mutex); +} + +void ResourceManager::InitializeAHidSampler() { + // TODO } Result ResourceManager::RegisterCoreAppletResource() { @@ -189,7 +214,11 @@ Result ResourceManager::UnregisterCoreAppletResource() { Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) { std::scoped_lock lock{shared_mutex}; - return applet_resource->RegisterAppletResourceUserId(aruid, bool_value); + auto result = applet_resource->RegisterAppletResourceUserId(aruid, bool_value); + if (result.IsSuccess()) { + result = npad->RegisterAppletResourceUserId(aruid); + } + return result; } void ResourceManager::UnregisterAppletResourceUserId(u64 aruid) { @@ -227,8 +256,7 @@ void ResourceManager::EnableTouchScreen(u64 aruid, bool is_enabled) { applet_resource->EnableTouchScreen(aruid, is_enabled); } -void ResourceManager::UpdateControllers(std::uintptr_t user_data, - std::chrono::nanoseconds ns_late) { +void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); debug_pad->OnUpdate(core_timing); digitizer->OnUpdate(core_timing); @@ -241,20 +269,19 @@ void ResourceManager::UpdateControllers(std::uintptr_t user_data, capture_button->OnUpdate(core_timing); } -void ResourceManager::UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { +void ResourceManager::UpdateNpad(std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); npad->OnUpdate(core_timing); } -void ResourceManager::UpdateMouseKeyboard(std::uintptr_t user_data, - std::chrono::nanoseconds ns_late) { +void ResourceManager::UpdateMouseKeyboard(std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); mouse->OnUpdate(core_timing); debug_mouse->OnUpdate(core_timing); keyboard->OnUpdate(core_timing); } -void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { +void ResourceManager::UpdateMotion(std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); six_axis->OnUpdate(core_timing); seven_six_axis->OnUpdate(core_timing); @@ -273,34 +300,34 @@ IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<Resource // Register update callbacks npad_update_event = Core::Timing::CreateEvent( "HID::UpdatePadCallback", - [this, resource](std::uintptr_t user_data, s64 time, std::chrono::nanoseconds ns_late) - -> std::optional<std::chrono::nanoseconds> { + [this, resource]( + s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> { const auto guard = LockService(); - resource->UpdateNpad(user_data, ns_late); + resource->UpdateNpad(ns_late); return std::nullopt; }); default_update_event = Core::Timing::CreateEvent( "HID::UpdateDefaultCallback", - [this, resource](std::uintptr_t user_data, s64 time, std::chrono::nanoseconds ns_late) - -> std::optional<std::chrono::nanoseconds> { + [this, resource]( + s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> { const auto guard = LockService(); - resource->UpdateControllers(user_data, ns_late); + resource->UpdateControllers(ns_late); return std::nullopt; }); mouse_keyboard_update_event = Core::Timing::CreateEvent( "HID::UpdateMouseKeyboardCallback", - [this, resource](std::uintptr_t user_data, s64 time, std::chrono::nanoseconds ns_late) - -> std::optional<std::chrono::nanoseconds> { + [this, resource]( + s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> { const auto guard = LockService(); - resource->UpdateMouseKeyboard(user_data, ns_late); + resource->UpdateMouseKeyboard(ns_late); return std::nullopt; }); motion_update_event = Core::Timing::CreateEvent( "HID::UpdateMotionCallback", - [this, resource](std::uintptr_t user_data, s64 time, std::chrono::nanoseconds ns_late) - -> std::optional<std::chrono::nanoseconds> { + [this, resource]( + s64 time, std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> { const auto guard = LockService(); - resource->UpdateMotion(user_data, ns_late); + resource->UpdateMotion(ns_late); return std::nullopt; }); @@ -314,10 +341,10 @@ IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<Resource } IAppletResource::~IAppletResource() { - system.CoreTiming().UnscheduleEvent(npad_update_event, 0); - system.CoreTiming().UnscheduleEvent(default_update_event, 0); - system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event, 0); - system.CoreTiming().UnscheduleEvent(motion_update_event, 0); + system.CoreTiming().UnscheduleEvent(npad_update_event); + system.CoreTiming().UnscheduleEvent(default_update_event); + system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event); + system.CoreTiming().UnscheduleEvent(motion_update_event); resource_manager->FreeAppletResourceId(aruid); } |