early-access version 4098
This commit is contained in:
parent
c50aaf524d
commit
5095b4e18f
@ -36,6 +36,8 @@ option(YUZU_USE_BUNDLED_FFMPEG "Download/Build bundled FFmpeg" "${WIN32}")
|
||||
|
||||
option(YUZU_USE_EXTERNAL_VULKAN_HEADERS "Use Vulkan-Headers from externals" ON)
|
||||
|
||||
option(YUZU_USE_EXTERNAL_VULKAN_UTILITY_LIBRARIES "Use Vulkan-Utility-Libraries from externals" ON)
|
||||
|
||||
option(YUZU_USE_QT_MULTIMEDIA "Use QtMultimedia for Camera" OFF)
|
||||
|
||||
option(YUZU_USE_QT_WEB_ENGINE "Use QtWebEngine for web applet implementation" OFF)
|
||||
@ -308,6 +310,10 @@ if (NOT YUZU_USE_EXTERNAL_VULKAN_HEADERS)
|
||||
find_package(Vulkan 1.3.274 REQUIRED)
|
||||
endif()
|
||||
|
||||
if (NOT YUZU_USE_EXTERNAL_VULKAN_UTILITY_LIBRARIES)
|
||||
find_package(VulkanUtilityLibraries REQUIRED)
|
||||
endif()
|
||||
|
||||
if (ENABLE_LIBUSB)
|
||||
find_package(libusb 1.0.24 MODULE)
|
||||
endif()
|
||||
|
@ -1,7 +1,7 @@
|
||||
yuzu emulator early access
|
||||
=============
|
||||
|
||||
This is the source code for early-access 4097.
|
||||
This is the source code for early-access 4098.
|
||||
|
||||
## Legal Notice
|
||||
|
||||
|
5
externals/CMakeLists.txt
vendored
5
externals/CMakeLists.txt
vendored
@ -154,6 +154,11 @@ if (YUZU_USE_EXTERNAL_VULKAN_HEADERS)
|
||||
add_subdirectory(Vulkan-Headers)
|
||||
endif()
|
||||
|
||||
# Vulkan-Utility-Libraries
|
||||
if (YUZU_USE_EXTERNAL_VULKAN_UTILITY_LIBRARIES)
|
||||
add_subdirectory(Vulkan-Utility-Libraries)
|
||||
endif()
|
||||
|
||||
# TZDB (Time Zone Database)
|
||||
add_subdirectory(nx_tzdb)
|
||||
|
||||
|
@ -7,6 +7,7 @@ import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import org.yuzu.yuzu_emu.R
|
||||
import org.yuzu.yuzu_emu.databinding.CardDriverOptionBinding
|
||||
import org.yuzu.yuzu_emu.features.settings.model.StringSetting
|
||||
import org.yuzu.yuzu_emu.model.Driver
|
||||
@ -57,13 +58,9 @@ class DriverAdapter(private val driverViewModel: DriverViewModel) :
|
||||
title.text = model.title
|
||||
version.text = model.version
|
||||
description.text = model.description
|
||||
if (model.description.isNotEmpty()) {
|
||||
version.visibility = View.VISIBLE
|
||||
description.visibility = View.VISIBLE
|
||||
if (model.title != binding.root.context.getString(R.string.system_gpu_driver)) {
|
||||
buttonDelete.visibility = View.VISIBLE
|
||||
} else {
|
||||
version.visibility = View.GONE
|
||||
description.visibility = View.GONE
|
||||
buttonDelete.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
@ -303,8 +303,8 @@ void AppletManager::CreateAndInsertByFrontendAppletParameters(
|
||||
}
|
||||
|
||||
// Applet was started by frontend, so it is foreground.
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
|
||||
applet->focus_state = FocusState::InFocus;
|
||||
|
||||
this->InsertApplet(std::move(applet));
|
||||
|
@ -85,24 +85,26 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) {
|
||||
applet->library_applet_mode = mode;
|
||||
|
||||
// Set focus state
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
|
||||
switch (mode) {
|
||||
case LibraryAppletMode::AllForeground:
|
||||
case LibraryAppletMode::NoUI:
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
|
||||
applet->focus_state = FocusState::InFocus;
|
||||
applet->hid_registration.EnableAppletToGetInput(true);
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
|
||||
break;
|
||||
case LibraryAppletMode::AllForegroundInitiallyHidden:
|
||||
applet->system_buffer_manager.SetWindowVisibility(false);
|
||||
applet->focus_state = FocusState::NotInFocus;
|
||||
applet->hid_registration.EnableAppletToGetInput(false);
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
|
||||
break;
|
||||
case LibraryAppletMode::Background:
|
||||
case LibraryAppletMode::BackgroundIndirectDisplay:
|
||||
default:
|
||||
applet->focus_state = FocusState::Background;
|
||||
applet->hid_registration.EnableAppletToGetInput(true);
|
||||
applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,10 @@ namespace Service::HID {
|
||||
|
||||
void LoopProcess(Core::System& system) {
|
||||
auto server_manager = std::make_unique<ServerManager>(system);
|
||||
std::shared_ptr<ResourceManager> resource_manager = std::make_shared<ResourceManager>(system);
|
||||
std::shared_ptr<HidFirmwareSettings> firmware_settings =
|
||||
std::make_shared<HidFirmwareSettings>(system);
|
||||
std::shared_ptr<ResourceManager> resource_manager =
|
||||
std::make_shared<ResourceManager>(system, firmware_settings);
|
||||
|
||||
// TODO: Remove this hack when am is emulated properly.
|
||||
resource_manager->Initialize();
|
||||
@ -31,7 +32,7 @@ void LoopProcess(Core::System& system) {
|
||||
server_manager->RegisterNamedService(
|
||||
"hid", std::make_shared<IHidServer>(system, resource_manager, firmware_settings));
|
||||
server_manager->RegisterNamedService(
|
||||
"hid:dbg", std::make_shared<IHidDebugServer>(system, resource_manager));
|
||||
"hid:dbg", std::make_shared<IHidDebugServer>(system, resource_manager, firmware_settings));
|
||||
server_manager->RegisterNamedService(
|
||||
"hid:sys", std::make_shared<IHidSystemServer>(system, resource_manager, firmware_settings));
|
||||
|
||||
|
@ -1,27 +1,37 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "core/hle/service/hid/hid_debug_server.h"
|
||||
#include "core/hle/service/ipc_helpers.h"
|
||||
#include "hid_core/hid_types.h"
|
||||
#include "hid_core/resource_manager.h"
|
||||
#include "hid_core/resources/hid_firmware_settings.h"
|
||||
|
||||
#include "hid_core/resources/touch_screen/gesture.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource)
|
||||
: ServiceFramework{system_, "hid:dbg"}, resource_manager{resource} {
|
||||
IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
||||
std::shared_ptr<HidFirmwareSettings> settings)
|
||||
: ServiceFramework{system_, "hid:dbg"}, resource_manager{resource}, firmware_settings{
|
||||
settings} {
|
||||
// clang-format off
|
||||
static const FunctionInfo functions[] = {
|
||||
{0, nullptr, "DeactivateDebugPad"},
|
||||
{1, nullptr, "SetDebugPadAutoPilotState"},
|
||||
{2, nullptr, "UnsetDebugPadAutoPilotState"},
|
||||
{10, nullptr, "DeactivateTouchScreen"},
|
||||
{11, nullptr, "SetTouchScreenAutoPilotState"},
|
||||
{12, nullptr, "UnsetTouchScreenAutoPilotState"},
|
||||
{13, nullptr, "GetTouchScreenConfiguration"},
|
||||
{14, nullptr, "ProcessTouchScreenAutoTune"},
|
||||
{15, nullptr, "ForceStopTouchScreenManagement"},
|
||||
{16, nullptr, "ForceRestartTouchScreenManagement"},
|
||||
{17, nullptr, "IsTouchScreenManaged"},
|
||||
{10, &IHidDebugServer::DeactivateTouchScreen, "DeactivateTouchScreen"},
|
||||
{11, &IHidDebugServer::SetTouchScreenAutoPilotState, "SetTouchScreenAutoPilotState"},
|
||||
{12, &IHidDebugServer::UnsetTouchScreenAutoPilotState, "UnsetTouchScreenAutoPilotState"},
|
||||
{13, &IHidDebugServer::GetTouchScreenConfiguration, "GetTouchScreenConfiguration"},
|
||||
{14, &IHidDebugServer::ProcessTouchScreenAutoTune, "ProcessTouchScreenAutoTune"},
|
||||
{15, &IHidDebugServer::ForceStopTouchScreenManagement, "ForceStopTouchScreenManagement"},
|
||||
{16, &IHidDebugServer::ForceRestartTouchScreenManagement, "ForceRestartTouchScreenManagement"},
|
||||
{17, &IHidDebugServer::IsTouchScreenManaged, "IsTouchScreenManaged"},
|
||||
{20, nullptr, "DeactivateMouse"},
|
||||
{21, nullptr, "SetMouseAutoPilotState"},
|
||||
{22, nullptr, "UnsetMouseAutoPilotState"},
|
||||
@ -37,7 +47,7 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<Resource
|
||||
{60, nullptr, "ClearNpadSystemCommonPolicy"},
|
||||
{61, nullptr, "DeactivateNpad"},
|
||||
{62, nullptr, "ForceDisconnectNpad"},
|
||||
{91, nullptr, "DeactivateGesture"},
|
||||
{91, &IHidDebugServer::DeactivateGesture, "DeactivateGesture"},
|
||||
{110, nullptr, "DeactivateHomeButton"},
|
||||
{111, nullptr, "SetHomeButtonAutoPilotState"},
|
||||
{112, nullptr, "UnsetHomeButtonAutoPilotState"},
|
||||
@ -150,6 +160,170 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<Resource
|
||||
}
|
||||
|
||||
IHidDebugServer::~IHidDebugServer() = default;
|
||||
void IHidDebugServer::DeactivateTouchScreen(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
Result result = ResultSuccess;
|
||||
|
||||
if (!firmware_settings->IsDeviceManaged()) {
|
||||
result = GetResourceManager()->GetTouchScreen()->Deactivate();
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidDebugServer::SetTouchScreenAutoPilotState(HLERequestContext& ctx) {
|
||||
AutoPilotState auto_pilot{};
|
||||
auto_pilot.count = ctx.GetReadBufferNumElements<TouchState>();
|
||||
const auto buffer = ctx.ReadBuffer();
|
||||
|
||||
auto_pilot.count = std::min(auto_pilot.count, static_cast<u64>(auto_pilot.state.size()));
|
||||
memcpy(auto_pilot.state.data(), buffer.data(), auto_pilot.count * sizeof(TouchState));
|
||||
|
||||
LOG_INFO(Service_HID, "called, auto_pilot_count={}", auto_pilot.count);
|
||||
|
||||
const Result result =
|
||||
GetResourceManager()->GetTouchScreen()->SetTouchScreenAutoPilotState(auto_pilot);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidDebugServer::UnsetTouchScreenAutoPilotState(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
const Result result = GetResourceManager()->GetTouchScreen()->UnsetTouchScreenAutoPilotState();
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidDebugServer::GetTouchScreenConfiguration(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
|
||||
|
||||
Core::HID::TouchScreenConfigurationForNx touchscreen_config{};
|
||||
const Result result = GetResourceManager()->GetTouchScreen()->GetTouchScreenConfiguration(
|
||||
touchscreen_config, applet_resource_user_id);
|
||||
|
||||
if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 &&
|
||||
touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) {
|
||||
touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting;
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 6};
|
||||
rb.Push(result);
|
||||
rb.PushRaw(touchscreen_config);
|
||||
}
|
||||
|
||||
void IHidDebugServer::ProcessTouchScreenAutoTune(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
Result result = GetResourceManager()->GetTouchScreen()->ProcessTouchScreenAutoTune();
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidDebugServer::ForceStopTouchScreenManagement(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
if (!firmware_settings->IsDeviceManaged()) {
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
return;
|
||||
}
|
||||
|
||||
Result result = ResultSuccess;
|
||||
bool is_touch_active{};
|
||||
bool is_gesture_active{};
|
||||
auto touch_screen = GetResourceManager()->GetTouchScreen();
|
||||
auto gesture = GetResourceManager()->GetGesture();
|
||||
|
||||
if (firmware_settings->IsTouchI2cManaged()) {
|
||||
result = touch_screen->IsActive(is_touch_active);
|
||||
if (result.IsSuccess()) {
|
||||
result = gesture->IsActive(is_gesture_active);
|
||||
}
|
||||
if (result.IsSuccess() && is_touch_active) {
|
||||
result = touch_screen->Deactivate();
|
||||
}
|
||||
if (result.IsSuccess() && is_gesture_active) {
|
||||
result = gesture->Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidDebugServer::ForceRestartTouchScreenManagement(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
struct Parameters {
|
||||
u32 basic_gesture_id;
|
||||
INSERT_PADDING_WORDS_NOINIT(1);
|
||||
u64 applet_resource_user_id;
|
||||
};
|
||||
static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
|
||||
|
||||
const auto parameters{rp.PopRaw<Parameters>()};
|
||||
|
||||
LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}",
|
||||
parameters.basic_gesture_id, parameters.applet_resource_user_id);
|
||||
|
||||
Result result = ResultSuccess;
|
||||
auto touch_screen = GetResourceManager()->GetTouchScreen();
|
||||
auto gesture = GetResourceManager()->GetGesture();
|
||||
|
||||
if (firmware_settings->IsDeviceManaged() && firmware_settings->IsTouchI2cManaged()) {
|
||||
result = gesture->Activate();
|
||||
if (result.IsSuccess()) {
|
||||
result =
|
||||
gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id);
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
result = touch_screen->Activate();
|
||||
}
|
||||
if (result.IsSuccess()) {
|
||||
result = touch_screen->Activate(parameters.applet_resource_user_id);
|
||||
}
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidDebugServer::IsTouchScreenManaged(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
bool is_touch_active{};
|
||||
bool is_gesture_active{};
|
||||
|
||||
Result result = GetResourceManager()->GetTouchScreen()->IsActive(is_touch_active);
|
||||
if (result.IsSuccess()) {
|
||||
result = GetResourceManager()->GetGesture()->IsActive(is_gesture_active);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(result);
|
||||
rb.Push(is_touch_active | is_gesture_active);
|
||||
}
|
||||
|
||||
void IHidDebugServer::DeactivateGesture(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
Result result = ResultSuccess;
|
||||
|
||||
if (!firmware_settings->IsDeviceManaged()) {
|
||||
result = GetResourceManager()->GetGesture()->Deactivate();
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
std::shared_ptr<ResourceManager> IHidDebugServer::GetResourceManager() {
|
||||
resource_manager->Initialize();
|
||||
|
@ -11,16 +11,29 @@ class System;
|
||||
|
||||
namespace Service::HID {
|
||||
class ResourceManager;
|
||||
class HidFirmwareSettings;
|
||||
|
||||
class IHidDebugServer final : public ServiceFramework<IHidDebugServer> {
|
||||
public:
|
||||
explicit IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource);
|
||||
explicit IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource,
|
||||
std::shared_ptr<HidFirmwareSettings> settings);
|
||||
~IHidDebugServer() override;
|
||||
|
||||
private:
|
||||
void DeactivateTouchScreen(HLERequestContext& ctx);
|
||||
void SetTouchScreenAutoPilotState(HLERequestContext& ctx);
|
||||
void UnsetTouchScreenAutoPilotState(HLERequestContext& ctx);
|
||||
void GetTouchScreenConfiguration(HLERequestContext& ctx);
|
||||
void ProcessTouchScreenAutoTune(HLERequestContext& ctx);
|
||||
void ForceStopTouchScreenManagement(HLERequestContext& ctx);
|
||||
void ForceRestartTouchScreenManagement(HLERequestContext& ctx);
|
||||
void IsTouchScreenManaged(HLERequestContext& ctx);
|
||||
void DeactivateGesture(HLERequestContext& ctx);
|
||||
|
||||
std::shared_ptr<ResourceManager> GetResourceManager();
|
||||
|
||||
std::shared_ptr<ResourceManager> resource_manager;
|
||||
std::shared_ptr<HidFirmwareSettings> firmware_settings;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -989,8 +989,7 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) {
|
||||
}
|
||||
|
||||
if (result.IsSuccess()) {
|
||||
// TODO: Use gesture id here
|
||||
result = gesture->Activate(parameters.applet_resource_user_id);
|
||||
result = gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id);
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
@ -2449,14 +2448,22 @@ void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) {
|
||||
|
||||
void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto touchscreen_mode{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()};
|
||||
auto touchscreen_config{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called, touchscreen_mode={}, applet_resource_user_id={}",
|
||||
touchscreen_mode.mode, applet_resource_user_id);
|
||||
LOG_INFO(Service_HID, "called, touchscreen_config={}, applet_resource_user_id={}",
|
||||
touchscreen_config.mode, applet_resource_user_id);
|
||||
|
||||
if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 &&
|
||||
touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) {
|
||||
touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting;
|
||||
}
|
||||
|
||||
const Result result = GetResourceManager()->GetTouchScreen()->SetTouchScreenConfiguration(
|
||||
touchscreen_config, applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidServer::IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx) {
|
||||
@ -2484,11 +2491,12 @@ void IHidServer::SetTouchScreenResolution(HLERequestContext& ctx) {
|
||||
const auto height{rp.Pop<u32>()};
|
||||
const auto applet_resource_user_id{rp.Pop<u64>()};
|
||||
|
||||
GetResourceManager()->GetTouchScreen()->SetTouchscreenDimensions(width, height);
|
||||
|
||||
LOG_INFO(Service_HID, "called, width={}, height={}, applet_resource_user_id={}", width, height,
|
||||
applet_resource_user_id);
|
||||
|
||||
GetResourceManager()->GetTouchScreen()->SetTouchScreenResolution(width, height,
|
||||
applet_resource_user_id);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
@ -155,9 +155,9 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour
|
||||
{1133, nullptr, "StartUsbFirmwareUpdate"},
|
||||
{1134, nullptr, "GetUsbFirmwareUpdateState"},
|
||||
{1135, &IHidSystemServer::InitializeUsbFirmwareUpdateWithoutMemory, "InitializeUsbFirmwareUpdateWithoutMemory"},
|
||||
{1150, nullptr, "SetTouchScreenMagnification"},
|
||||
{1151, nullptr, "GetTouchScreenFirmwareVersion"},
|
||||
{1152, nullptr, "SetTouchScreenDefaultConfiguration"},
|
||||
{1150, &IHidSystemServer::SetTouchScreenMagnification, "SetTouchScreenMagnification"},
|
||||
{1151, &IHidSystemServer::GetTouchScreenFirmwareVersion, "GetTouchScreenFirmwareVersion"},
|
||||
{1152, &IHidSystemServer::SetTouchScreenDefaultConfiguration, "SetTouchScreenDefaultConfiguration"},
|
||||
{1153, &IHidSystemServer::GetTouchScreenDefaultConfiguration, "GetTouchScreenDefaultConfiguration"},
|
||||
{1154, nullptr, "IsFirmwareAvailableForNotification"},
|
||||
{1155, &IHidSystemServer::SetForceHandheldStyleVibration, "SetForceHandheldStyleVibration"},
|
||||
@ -845,12 +845,60 @@ void IHidSystemServer::InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContex
|
||||
rb.Push(ResultSuccess);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx) {
|
||||
LOG_WARNING(Service_HID, "(STUBBED) called");
|
||||
void IHidSystemServer::SetTouchScreenMagnification(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto point1x{rp.Pop<f32>()};
|
||||
const auto point1y{rp.Pop<f32>()};
|
||||
const auto point2x{rp.Pop<f32>()};
|
||||
const auto point2y{rp.Pop<f32>()};
|
||||
|
||||
Core::HID::TouchScreenConfigurationForNx touchscreen_config{
|
||||
.mode = Core::HID::TouchScreenModeForNx::Finger,
|
||||
};
|
||||
LOG_INFO(Service_HID, "called, point1=-({},{}), point2=({},{})", point1x, point1y, point2x,
|
||||
point2y);
|
||||
|
||||
const Result result = GetResourceManager()->GetTouchScreen()->SetTouchScreenMagnification(
|
||||
point1x, point1y, point2x, point2y);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetTouchScreenFirmwareVersion(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
Core::HID::FirmwareVersion firmware{};
|
||||
const auto result = GetResourceManager()->GetTouchScreenFirmwareVersion(firmware);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 6};
|
||||
rb.Push(result);
|
||||
rb.PushRaw(firmware);
|
||||
}
|
||||
|
||||
void IHidSystemServer::SetTouchScreenDefaultConfiguration(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
auto touchscreen_config{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()};
|
||||
|
||||
LOG_INFO(Service_HID, "called, touchscreen_config={}", touchscreen_config.mode);
|
||||
|
||||
if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 &&
|
||||
touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) {
|
||||
touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting;
|
||||
}
|
||||
|
||||
const Result result =
|
||||
GetResourceManager()->GetTouchScreen()->SetTouchScreenDefaultConfiguration(
|
||||
touchscreen_config);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(result);
|
||||
}
|
||||
|
||||
void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_HID, "called");
|
||||
|
||||
Core::HID::TouchScreenConfigurationForNx touchscreen_config{};
|
||||
const Result result =
|
||||
GetResourceManager()->GetTouchScreen()->GetTouchScreenDefaultConfiguration(
|
||||
touchscreen_config);
|
||||
|
||||
if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 &&
|
||||
touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) {
|
||||
@ -858,7 +906,7 @@ void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx
|
||||
}
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 6};
|
||||
rb.Push(ResultSuccess);
|
||||
rb.Push(result);
|
||||
rb.PushRaw(touchscreen_config);
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,9 @@ private:
|
||||
void FinalizeUsbFirmwareUpdate(HLERequestContext& ctx);
|
||||
void CheckUsbFirmwareUpdateRequired(HLERequestContext& ctx);
|
||||
void InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContext& ctx);
|
||||
void SetTouchScreenMagnification(HLERequestContext& ctx);
|
||||
void GetTouchScreenFirmwareVersion(HLERequestContext& ctx);
|
||||
void SetTouchScreenDefaultConfiguration(HLERequestContext& ctx);
|
||||
void GetTouchScreenDefaultConfiguration(HLERequestContext& ctx);
|
||||
void SetForceHandheldStyleVibration(HLERequestContext& ctx);
|
||||
void IsUsingCustomButtonConfig(HLERequestContext& ctx);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "common/vector_math.h"
|
||||
#include "core/hle/service/set/setting_formats/private_settings.h"
|
||||
#include "core/hle/service/set/settings_types.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Service::Set {
|
||||
|
||||
@ -257,8 +258,7 @@ struct SystemSettings {
|
||||
std::array<u8, 0x10> analog_stick_user_calibration_left;
|
||||
std::array<u8, 0x10> analog_stick_user_calibration_right;
|
||||
|
||||
// nn::settings::system::TouchScreenMode
|
||||
s32 touch_screen_mode;
|
||||
TouchScreenMode touch_screen_mode;
|
||||
INSERT_PADDING_BYTES(0x14); // Reserved
|
||||
|
||||
TvSettings tv_settings;
|
||||
|
@ -275,8 +275,8 @@ ISystemSettingsServer::ISystemSettingsServer(Core::System& system_)
|
||||
{184, nullptr, "SetPlatformRegion"},
|
||||
{185, &ISystemSettingsServer::GetHomeMenuSchemeModel, "GetHomeMenuSchemeModel"},
|
||||
{186, nullptr, "GetMemoryUsageRateFlag"},
|
||||
{187, nullptr, "GetTouchScreenMode"},
|
||||
{188, nullptr, "SetTouchScreenMode"},
|
||||
{187, &ISystemSettingsServer::GetTouchScreenMode, "GetTouchScreenMode"},
|
||||
{188, &ISystemSettingsServer::SetTouchScreenMode, "SetTouchScreenMode"},
|
||||
{189, nullptr, "GetButtonConfigSettingsFull"},
|
||||
{190, nullptr, "SetButtonConfigSettingsFull"},
|
||||
{191, nullptr, "GetButtonConfigSettingsEmbedded"},
|
||||
@ -1395,6 +1395,28 @@ void ISystemSettingsServer::GetHomeMenuSchemeModel(HLERequestContext& ctx) {
|
||||
rb.Push(0);
|
||||
}
|
||||
|
||||
void ISystemSettingsServer::GetTouchScreenMode(HLERequestContext& ctx) {
|
||||
TouchScreenMode touch_screen_mode{};
|
||||
auto res = GetTouchScreenMode(touch_screen_mode);
|
||||
|
||||
LOG_INFO(Service_SET, "called, touch_screen_mode={}", touch_screen_mode);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 3};
|
||||
rb.Push(res);
|
||||
rb.PushEnum(touch_screen_mode);
|
||||
}
|
||||
|
||||
void ISystemSettingsServer::SetTouchScreenMode(HLERequestContext& ctx) {
|
||||
IPC::RequestParser rp{ctx};
|
||||
const auto touch_screen_mode = rp.PopEnum<TouchScreenMode>();
|
||||
auto res = SetTouchScreenMode(touch_screen_mode);
|
||||
|
||||
LOG_INFO(Service_SET, "called, touch_screen_mode={}", touch_screen_mode);
|
||||
|
||||
IPC::ResponseBuilder rb{ctx, 2};
|
||||
rb.Push(res);
|
||||
}
|
||||
|
||||
void ISystemSettingsServer::GetFieldTestingFlag(HLERequestContext& ctx) {
|
||||
LOG_INFO(Service_SET, "called, field_testing_flag={}", m_system_settings.field_testing_flag);
|
||||
|
||||
@ -1670,4 +1692,15 @@ Result ISystemSettingsServer::SetUserSystemClockAutomaticCorrectionUpdatedTime(
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ISystemSettingsServer::GetTouchScreenMode(TouchScreenMode& touch_screen_mode) const {
|
||||
touch_screen_mode = m_system_settings.touch_screen_mode;
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
Result ISystemSettingsServer::SetTouchScreenMode(TouchScreenMode touch_screen_mode) {
|
||||
m_system_settings.touch_screen_mode = touch_screen_mode;
|
||||
SetSaveNeeded();
|
||||
R_SUCCEED();
|
||||
}
|
||||
|
||||
} // namespace Service::Set
|
||||
|
@ -74,6 +74,8 @@ public:
|
||||
Service::PSC::Time::SteadyClockTimePoint& out_time_point) const;
|
||||
Result SetUserSystemClockAutomaticCorrectionUpdatedTime(
|
||||
const Service::PSC::Time::SteadyClockTimePoint& time_point);
|
||||
Result GetTouchScreenMode(TouchScreenMode& touch_screen_mode) const;
|
||||
Result SetTouchScreenMode(TouchScreenMode touch_screen_mode);
|
||||
|
||||
private:
|
||||
void SetLanguageCode(HLERequestContext& ctx);
|
||||
@ -154,6 +156,8 @@ private:
|
||||
void GetChineseTraditionalInputMethod(HLERequestContext& ctx);
|
||||
void GetHomeMenuScheme(HLERequestContext& ctx);
|
||||
void GetHomeMenuSchemeModel(HLERequestContext& ctx);
|
||||
void GetTouchScreenMode(HLERequestContext& ctx);
|
||||
void SetTouchScreenMode(HLERequestContext& ctx);
|
||||
void GetFieldTestingFlag(HLERequestContext& ctx);
|
||||
void GetPanelCrcMode(HLERequestContext& ctx);
|
||||
void SetPanelCrcMode(HLERequestContext& ctx);
|
||||
|
@ -190,9 +190,9 @@ void Config::ReadTouchscreenValues() {
|
||||
Settings::values.touchscreen.rotation_angle =
|
||||
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_angle"), 0));
|
||||
Settings::values.touchscreen.diameter_x =
|
||||
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_x"), 15));
|
||||
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_x"), 90));
|
||||
Settings::values.touchscreen.diameter_y =
|
||||
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_y"), 15));
|
||||
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_y"), 90));
|
||||
}
|
||||
|
||||
void Config::ReadAudioValues() {
|
||||
@ -478,9 +478,9 @@ void Config::SaveTouchscreenValues() {
|
||||
WriteIntegerSetting(std::string("touchscreen_angle"), touchscreen.rotation_angle,
|
||||
std::make_optional(static_cast<u32>(0)));
|
||||
WriteIntegerSetting(std::string("touchscreen_diameter_x"), touchscreen.diameter_x,
|
||||
std::make_optional(static_cast<u32>(15)));
|
||||
std::make_optional(static_cast<u32>(90)));
|
||||
WriteIntegerSetting(std::string("touchscreen_diameter_y"), touchscreen.diameter_y,
|
||||
std::make_optional(static_cast<u32>(15)));
|
||||
std::make_optional(static_cast<u32>(90)));
|
||||
}
|
||||
|
||||
void Config::SaveMotionTouchValues() {
|
||||
|
@ -96,11 +96,17 @@ add_library(hid_core STATIC
|
||||
resources/system_buttons/home_button.h
|
||||
resources/system_buttons/sleep_button.cpp
|
||||
resources/system_buttons/sleep_button.h
|
||||
resources/system_buttons/system_button_types.h
|
||||
resources/touch_screen/gesture.cpp
|
||||
resources/touch_screen/gesture.h
|
||||
resources/touch_screen/gesture_types.h
|
||||
resources/touch_screen/gesture_handler.cpp
|
||||
resources/touch_screen/gesture_handler.h
|
||||
resources/touch_screen/touch_screen.cpp
|
||||
resources/touch_screen/touch_screen.h
|
||||
resources/touch_screen/touch_screen_driver.cpp
|
||||
resources/touch_screen/touch_screen_driver.h
|
||||
resources/touch_screen/touch_screen_resource.cpp
|
||||
resources/touch_screen/touch_screen_resource.h
|
||||
resources/touch_screen/touch_types.h
|
||||
resources/unique_pad/unique_pad.cpp
|
||||
resources/unique_pad/unique_pad.h
|
||||
|
@ -8,6 +8,10 @@
|
||||
namespace Service::HID {
|
||||
|
||||
constexpr Result PalmaResultSuccess{ErrorModule::HID, 0};
|
||||
|
||||
constexpr Result ResultTouchNotInitialized{ErrorModule::HID, 41};
|
||||
constexpr Result ResultTouchOverflow{ErrorModule::HID, 42};
|
||||
|
||||
constexpr Result NpadInvalidHandle{ErrorModule::HID, 100};
|
||||
constexpr Result NpadDeviceIndexOutOfRange{ErrorModule::HID, 107};
|
||||
|
||||
@ -23,6 +27,10 @@ constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
|
||||
constexpr Result ResultNfcIsNotReady{ErrorModule::HID, 461};
|
||||
constexpr Result ResultNfcXcdHandleIsNotInitialized{ErrorModule::HID, 464};
|
||||
constexpr Result ResultIrSensorIsNotReady{ErrorModule::HID, 501};
|
||||
|
||||
constexpr Result ResultGestureOverflow{ErrorModule::HID, 522};
|
||||
constexpr Result ResultGestureNotInitialized{ErrorModule::HID, 523};
|
||||
|
||||
constexpr Result ResultMcuIsNotReady{ErrorModule::HID, 541};
|
||||
|
||||
constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};
|
||||
|
@ -299,12 +299,6 @@ enum class GyroscopeZeroDriftMode : u32 {
|
||||
Tight = 2,
|
||||
};
|
||||
|
||||
// This is nn::settings::system::TouchScreenMode
|
||||
enum class TouchScreenMode : u32 {
|
||||
Stylus = 0,
|
||||
Standard = 1,
|
||||
};
|
||||
|
||||
// This is nn::hid::TouchScreenModeForNx
|
||||
enum class TouchScreenModeForNx : u8 {
|
||||
UseSystemSetting,
|
||||
@ -354,18 +348,6 @@ struct TouchAttribute {
|
||||
};
|
||||
static_assert(sizeof(TouchAttribute) == 0x4, "TouchAttribute is an invalid size");
|
||||
|
||||
// This is nn::hid::TouchState
|
||||
struct TouchState {
|
||||
u64 delta_time{};
|
||||
TouchAttribute attribute{};
|
||||
u32 finger{};
|
||||
Common::Point<u32> position{};
|
||||
u32 diameter_x{};
|
||||
u32 diameter_y{};
|
||||
u32 rotation_angle{};
|
||||
};
|
||||
static_assert(sizeof(TouchState) == 0x28, "Touchstate is an invalid size");
|
||||
|
||||
struct TouchFinger {
|
||||
u64 last_touch{};
|
||||
Common::Point<float> position{};
|
||||
@ -437,6 +419,16 @@ struct LedPattern {
|
||||
};
|
||||
};
|
||||
|
||||
struct SleepButtonState {
|
||||
union {
|
||||
u64 raw{};
|
||||
|
||||
// Buttons
|
||||
BitField<0, 1, u64> sleep;
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(SleepButtonState) == 0x8, "SleepButtonState has incorrect size.");
|
||||
|
||||
struct HomeButtonState {
|
||||
union {
|
||||
u64 raw{};
|
||||
@ -743,4 +735,14 @@ struct UniquePadId {
|
||||
};
|
||||
static_assert(sizeof(UniquePadId) == 0x8, "UniquePadId is an invalid size");
|
||||
|
||||
// This is nn::hid::system::FirmwareVersion
|
||||
struct FirmwareVersion {
|
||||
u8 major;
|
||||
u8 minor;
|
||||
u8 micro;
|
||||
u8 revision;
|
||||
std::array<char, 0xc> device_identifier;
|
||||
};
|
||||
static_assert(sizeof(FirmwareVersion) == 0x10, "FirmwareVersion is an invalid size");
|
||||
|
||||
} // namespace Core::HID
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "hid_core/resources/applet_resource.h"
|
||||
#include "hid_core/resources/debug_pad/debug_pad.h"
|
||||
#include "hid_core/resources/digitizer/digitizer.h"
|
||||
#include "hid_core/resources/hid_firmware_settings.h"
|
||||
#include "hid_core/resources/keyboard/keyboard.h"
|
||||
#include "hid_core/resources/mouse/debug_mouse.h"
|
||||
#include "hid_core/resources/mouse/mouse.h"
|
||||
@ -29,6 +30,8 @@
|
||||
#include "hid_core/resources/system_buttons/sleep_button.h"
|
||||
#include "hid_core/resources/touch_screen/gesture.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_driver.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_resource.h"
|
||||
#include "hid_core/resources/unique_pad/unique_pad.h"
|
||||
#include "hid_core/resources/vibration/gc_vibration_device.h"
|
||||
#include "hid_core/resources/vibration/n64_vibration_device.h"
|
||||
@ -45,12 +48,16 @@ constexpr auto default_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; //
|
||||
constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz)
|
||||
constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
|
||||
|
||||
ResourceManager::ResourceManager(Core::System& system_)
|
||||
: system{system_}, service_context{system_, "hid"} {
|
||||
ResourceManager::ResourceManager(Core::System& system_,
|
||||
std::shared_ptr<HidFirmwareSettings> settings)
|
||||
: firmware_settings{settings}, system{system_}, service_context{system_, "hid"} {
|
||||
applet_resource = std::make_shared<AppletResource>(system);
|
||||
}
|
||||
|
||||
ResourceManager::~ResourceManager() = default;
|
||||
ResourceManager::~ResourceManager() {
|
||||
system.CoreTiming().UnscheduleEvent(touch_update_event);
|
||||
input_event->Finalize();
|
||||
};
|
||||
|
||||
void ResourceManager::Initialize() {
|
||||
if (is_initialized) {
|
||||
@ -59,7 +66,9 @@ void ResourceManager::Initialize() {
|
||||
|
||||
system.HIDCore().ReloadInputDevices();
|
||||
|
||||
handheld_config = std::make_shared<HandheldConfig>();
|
||||
input_event = service_context.CreateEvent("ResourceManager:InputEvent");
|
||||
|
||||
InitializeHandheldConfig();
|
||||
InitializeHidCommonSampler();
|
||||
InitializeTouchScreenSampler();
|
||||
InitializeConsoleSixAxisSampler();
|
||||
@ -154,6 +163,7 @@ Result ResourceManager::CreateAppletResource(u64 aruid) {
|
||||
npad->Activate();
|
||||
six_axis->Activate();
|
||||
touch_screen->Activate();
|
||||
gesture->Activate();
|
||||
|
||||
return GetNpad()->ActivateNpadResource(aruid);
|
||||
}
|
||||
@ -163,6 +173,17 @@ Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
|
||||
return applet_resource->CreateAppletResource(aruid);
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeHandheldConfig() {
|
||||
handheld_config = std::make_shared<HandheldConfig>();
|
||||
handheld_config->is_handheld_hid_enabled = true;
|
||||
handheld_config->is_joycon_rail_enabled = true;
|
||||
handheld_config->is_force_handheld_style_vibration = false;
|
||||
handheld_config->is_force_handheld = false;
|
||||
if (firmware_settings->IsHandheldForced()) {
|
||||
handheld_config->is_joycon_rail_enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeHidCommonSampler() {
|
||||
debug_pad = std::make_shared<DebugPad>(system.HIDCore());
|
||||
mouse = std::make_shared<Mouse>(system.HIDCore());
|
||||
@ -170,7 +191,6 @@ void ResourceManager::InitializeHidCommonSampler() {
|
||||
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());
|
||||
@ -185,7 +205,8 @@ void ResourceManager::InitializeHidCommonSampler() {
|
||||
|
||||
const auto settings =
|
||||
system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", true);
|
||||
npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config, settings);
|
||||
npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config, input_event,
|
||||
&input_mutex, settings);
|
||||
|
||||
six_axis->SetAppletResource(applet_resource, &shared_mutex);
|
||||
mouse->SetAppletResource(applet_resource, &shared_mutex);
|
||||
@ -196,11 +217,25 @@ void ResourceManager::InitializeHidCommonSampler() {
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeTouchScreenSampler() {
|
||||
gesture = std::make_shared<Gesture>(system.HIDCore());
|
||||
touch_screen = std::make_shared<TouchScreen>(system.HIDCore());
|
||||
// This is nn.hid.TouchScreenSampler
|
||||
touch_resource = std::make_shared<TouchResource>(system);
|
||||
touch_driver = std::make_shared<TouchDriver>(system.HIDCore());
|
||||
touch_screen = std::make_shared<TouchScreen>(touch_resource);
|
||||
gesture = std::make_shared<Gesture>(touch_resource);
|
||||
|
||||
touch_screen->SetAppletResource(applet_resource, &shared_mutex);
|
||||
gesture->SetAppletResource(applet_resource, &shared_mutex);
|
||||
touch_update_event = Core::Timing::CreateEvent(
|
||||
"HID::TouchUpdateCallback",
|
||||
[this](s64 time,
|
||||
std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
|
||||
touch_resource->OnTouchUpdate(time);
|
||||
return std::nullopt;
|
||||
});
|
||||
|
||||
touch_resource->SetTouchDriver(touch_driver);
|
||||
touch_resource->SetAppletResource(applet_resource, &shared_mutex);
|
||||
touch_resource->SetInputEvent(input_event, &input_mutex);
|
||||
touch_resource->SetHandheldConfig(handheld_config);
|
||||
touch_resource->SetTimerEvent(touch_update_event);
|
||||
}
|
||||
|
||||
void ResourceManager::InitializeConsoleSixAxisSampler() {
|
||||
@ -388,13 +423,15 @@ Result ResourceManager::SendVibrationValue(u64 aruid,
|
||||
return result;
|
||||
}
|
||||
|
||||
Result ResourceManager::GetTouchScreenFirmwareVersion(Core::HID::FirmwareVersion& firmware) const {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) {
|
||||
auto& core_timing = system.CoreTiming();
|
||||
debug_pad->OnUpdate(core_timing);
|
||||
digitizer->OnUpdate(core_timing);
|
||||
unique_pad->OnUpdate(core_timing);
|
||||
gesture->OnUpdate(core_timing);
|
||||
touch_screen->OnUpdate(core_timing);
|
||||
palma->OnUpdate(core_timing);
|
||||
home_button->OnUpdate(core_timing);
|
||||
sleep_button->OnUpdate(core_timing);
|
||||
|
@ -11,6 +11,7 @@ class System;
|
||||
}
|
||||
|
||||
namespace Core::HID {
|
||||
struct FirmwareVersion;
|
||||
struct VibrationDeviceHandle;
|
||||
struct VibrationValue;
|
||||
struct VibrationDeviceInfo;
|
||||
@ -21,8 +22,9 @@ struct EventType;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class KEvent;
|
||||
class KSharedMemory;
|
||||
}
|
||||
} // namespace Kernel
|
||||
|
||||
namespace Service::HID {
|
||||
class AppletResource;
|
||||
@ -33,6 +35,7 @@ class DebugMouse;
|
||||
class DebugPad;
|
||||
class Digitizer;
|
||||
class Gesture;
|
||||
class HidFirmwareSettings;
|
||||
class HomeButton;
|
||||
class Keyboard;
|
||||
class Mouse;
|
||||
@ -42,6 +45,8 @@ class SevenSixAxis;
|
||||
class SixAxis;
|
||||
class SleepButton;
|
||||
class TouchScreen;
|
||||
class TouchDriver;
|
||||
class TouchResource;
|
||||
class UniquePad;
|
||||
class NpadVibrationBase;
|
||||
class NpadN64VibrationDevice;
|
||||
@ -52,7 +57,7 @@ struct HandheldConfig;
|
||||
class ResourceManager {
|
||||
|
||||
public:
|
||||
explicit ResourceManager(Core::System& system_);
|
||||
explicit ResourceManager(Core::System& system_, std::shared_ptr<HidFirmwareSettings> settings);
|
||||
~ResourceManager();
|
||||
|
||||
void Initialize();
|
||||
@ -102,6 +107,8 @@ public:
|
||||
Result SendVibrationValue(u64 aruid, const Core::HID::VibrationDeviceHandle& handle,
|
||||
const Core::HID::VibrationValue& value);
|
||||
|
||||
Result GetTouchScreenFirmwareVersion(Core::HID::FirmwareVersion& firmware) const;
|
||||
|
||||
void UpdateControllers(std::chrono::nanoseconds ns_late);
|
||||
void UpdateNpad(std::chrono::nanoseconds ns_late);
|
||||
void UpdateMouseKeyboard(std::chrono::nanoseconds ns_late);
|
||||
@ -109,6 +116,7 @@ public:
|
||||
|
||||
private:
|
||||
Result CreateAppletResourceImpl(u64 aruid);
|
||||
void InitializeHandheldConfig();
|
||||
void InitializeHidCommonSampler();
|
||||
void InitializeTouchScreenSampler();
|
||||
void InitializeConsoleSixAxisSampler();
|
||||
@ -117,37 +125,46 @@ private:
|
||||
bool is_initialized{false};
|
||||
|
||||
mutable std::recursive_mutex shared_mutex;
|
||||
std::shared_ptr<AppletResource> applet_resource = nullptr;
|
||||
std::shared_ptr<AppletResource> applet_resource{nullptr};
|
||||
|
||||
std::shared_ptr<CaptureButton> capture_button = nullptr;
|
||||
std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
|
||||
std::shared_ptr<DebugMouse> debug_mouse = nullptr;
|
||||
std::shared_ptr<DebugPad> debug_pad = nullptr;
|
||||
std::shared_ptr<Digitizer> digitizer = nullptr;
|
||||
std::shared_ptr<Gesture> gesture = nullptr;
|
||||
std::shared_ptr<HomeButton> home_button = nullptr;
|
||||
std::shared_ptr<Keyboard> keyboard = nullptr;
|
||||
std::shared_ptr<Mouse> mouse = nullptr;
|
||||
std::shared_ptr<NPad> npad = nullptr;
|
||||
std::shared_ptr<Palma> palma = nullptr;
|
||||
std::shared_ptr<SevenSixAxis> seven_six_axis = nullptr;
|
||||
std::shared_ptr<SixAxis> six_axis = nullptr;
|
||||
std::shared_ptr<SleepButton> sleep_button = nullptr;
|
||||
std::shared_ptr<TouchScreen> touch_screen = nullptr;
|
||||
std::shared_ptr<UniquePad> unique_pad = nullptr;
|
||||
mutable std::mutex input_mutex;
|
||||
Kernel::KEvent* input_event{nullptr};
|
||||
|
||||
std::shared_ptr<HandheldConfig> handheld_config = nullptr;
|
||||
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
|
||||
std::shared_ptr<HidFirmwareSettings> firmware_settings{nullptr};
|
||||
|
||||
std::shared_ptr<CaptureButton> capture_button{nullptr};
|
||||
std::shared_ptr<ConsoleSixAxis> console_six_axis{nullptr};
|
||||
std::shared_ptr<DebugMouse> debug_mouse{nullptr};
|
||||
std::shared_ptr<DebugPad> debug_pad{nullptr};
|
||||
std::shared_ptr<Digitizer> digitizer{nullptr};
|
||||
std::shared_ptr<HomeButton> home_button{nullptr};
|
||||
std::shared_ptr<Keyboard> keyboard{nullptr};
|
||||
std::shared_ptr<Mouse> mouse{nullptr};
|
||||
std::shared_ptr<NPad> npad{nullptr};
|
||||
std::shared_ptr<Palma> palma{nullptr};
|
||||
std::shared_ptr<SevenSixAxis> seven_six_axis{nullptr};
|
||||
std::shared_ptr<SixAxis> six_axis{nullptr};
|
||||
std::shared_ptr<SleepButton> sleep_button{nullptr};
|
||||
std::shared_ptr<UniquePad> unique_pad{nullptr};
|
||||
|
||||
// TODO: Create these resources
|
||||
// std::shared_ptr<AudioControl> audio_control = nullptr;
|
||||
// std::shared_ptr<ButtonConfig> button_config = nullptr;
|
||||
// std::shared_ptr<Config> config = nullptr;
|
||||
// std::shared_ptr<Connection> connection = nullptr;
|
||||
// std::shared_ptr<CustomConfig> custom_config = nullptr;
|
||||
// std::shared_ptr<Digitizer> digitizer = nullptr;
|
||||
// std::shared_ptr<Hdls> hdls = nullptr;
|
||||
// std::shared_ptr<PlayReport> play_report = nullptr;
|
||||
// std::shared_ptr<Rail> rail = nullptr;
|
||||
// std::shared_ptr<AudioControl> audio_control{nullptr};
|
||||
// std::shared_ptr<ButtonConfig> button_config{nullptr};
|
||||
// std::shared_ptr<Config> config{nullptr};
|
||||
// std::shared_ptr<Connection> connection{nullptr};
|
||||
// std::shared_ptr<CustomConfig> custom_config{nullptr};
|
||||
// std::shared_ptr<Digitizer> digitizer{nullptr};
|
||||
// std::shared_ptr<Hdls> hdls{nullptr};
|
||||
// std::shared_ptr<PlayReport> play_report{nullptr};
|
||||
// std::shared_ptr<Rail> rail{nullptr};
|
||||
|
||||
// Touch Resources
|
||||
std::shared_ptr<Gesture> gesture{nullptr};
|
||||
std::shared_ptr<TouchScreen> touch_screen{nullptr};
|
||||
std::shared_ptr<TouchResource> touch_resource{nullptr};
|
||||
std::shared_ptr<TouchDriver> touch_driver{nullptr};
|
||||
std::shared_ptr<Core::Timing::EventType> touch_update_event{nullptr};
|
||||
|
||||
Core::System& system;
|
||||
KernelHelpers::ServiceContext service_context;
|
||||
@ -162,12 +179,12 @@ public:
|
||||
private:
|
||||
void GetSharedMemoryHandle(HLERequestContext& ctx);
|
||||
|
||||
std::shared_ptr<Core::Timing::EventType> npad_update_event;
|
||||
std::shared_ptr<Core::Timing::EventType> default_update_event;
|
||||
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
|
||||
std::shared_ptr<Core::Timing::EventType> motion_update_event;
|
||||
std::shared_ptr<Core::Timing::EventType> npad_update_event{nullptr};
|
||||
std::shared_ptr<Core::Timing::EventType> default_update_event{nullptr};
|
||||
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event{nullptr};
|
||||
std::shared_ptr<Core::Timing::EventType> motion_update_event{nullptr};
|
||||
|
||||
u64 aruid;
|
||||
u64 aruid{};
|
||||
std::shared_ptr<ResourceManager> resource_manager;
|
||||
};
|
||||
|
||||
|
@ -118,6 +118,12 @@ void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||
data[index].aruid = 0;
|
||||
|
||||
registration_list.flag[index] = RegistrationStatus::PendingDelete;
|
||||
|
||||
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||
if (registration_list.flag[i] == RegistrationStatus::Initialized) {
|
||||
active_aruid = registration_list.aruid[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppletResource::FreeAppletResourceId(u64 aruid) {
|
||||
|
@ -13,11 +13,12 @@
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
} // namespace Core
|
||||
|
||||
namespace Kernel {
|
||||
class KEvent;
|
||||
class KSharedMemory;
|
||||
}
|
||||
} // namespace Kernel
|
||||
|
||||
namespace Service::HID {
|
||||
struct SharedMemoryFormat;
|
||||
@ -73,7 +74,8 @@ struct AppletResourceHolder {
|
||||
std::recursive_mutex* shared_mutex{nullptr};
|
||||
NPadResource* shared_npad_resource{nullptr};
|
||||
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
|
||||
long* handle_1;
|
||||
Kernel::KEvent* input_event{nullptr};
|
||||
std::mutex* input_mutex{nullptr};
|
||||
};
|
||||
|
||||
class AppletResource {
|
||||
|
@ -1081,11 +1081,14 @@ void NPad::UnregisterAppletResourceUserId(u64 aruid) {
|
||||
void NPad::SetNpadExternals(std::shared_ptr<AppletResource> resource,
|
||||
std::recursive_mutex* shared_mutex,
|
||||
std::shared_ptr<HandheldConfig> handheld_config,
|
||||
Kernel::KEvent* input_event, std::mutex* input_mutex,
|
||||
std::shared_ptr<Service::Set::ISystemSettingsServer> settings) {
|
||||
applet_resource_holder.applet_resource = resource;
|
||||
applet_resource_holder.shared_mutex = shared_mutex;
|
||||
applet_resource_holder.shared_npad_resource = &npad_resource;
|
||||
applet_resource_holder.handheld_config = handheld_config;
|
||||
applet_resource_holder.input_event = input_event;
|
||||
applet_resource_holder.input_mutex = input_mutex;
|
||||
|
||||
vibration_handler.SetSettingsService(settings);
|
||||
|
||||
|
@ -133,6 +133,7 @@ public:
|
||||
void SetNpadExternals(std::shared_ptr<AppletResource> resource,
|
||||
std::recursive_mutex* shared_mutex,
|
||||
std::shared_ptr<HandheldConfig> handheld_config,
|
||||
Kernel::KEvent* input_event, std::mutex* input_mutex,
|
||||
std::shared_ptr<Service::Set::ISystemSettingsServer> settings);
|
||||
|
||||
AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
|
||||
@ -206,9 +207,6 @@ private:
|
||||
std::array<AbstractPad, MaxSupportedNpadIdTypes> abstracted_pads;
|
||||
NpadVibration vibration_handler{};
|
||||
|
||||
Kernel::KEvent* input_event{nullptr};
|
||||
std::mutex* input_mutex{nullptr};
|
||||
|
||||
std::atomic<u64> press_state{};
|
||||
std::array<std::array<NpadControllerData, MaxSupportedNpadIdTypes>, AruidIndexMax>
|
||||
controller_data{};
|
||||
|
@ -72,6 +72,12 @@ void NPadResource::UnregisterAppletResourceUserId(u64 aruid) {
|
||||
state[aruid_index] = {};
|
||||
registration_list.flag[aruid_index] = RegistrationStatus::PendingDelete;
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < AruidIndexMax; i++) {
|
||||
if (registration_list.flag[i] == RegistrationStatus::Initialized) {
|
||||
active_data_aruid = registration_list.aruid[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NPadResource::DestroyStyleSetUpdateEvents(u64 aruid) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "hid_core/resources/mouse/mouse_types.h"
|
||||
#include "hid_core/resources/npad/npad_types.h"
|
||||
#include "hid_core/resources/ring_lifo.h"
|
||||
#include "hid_core/resources/system_buttons/system_button_types.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
@ -75,24 +76,24 @@ static_assert(sizeof(DigitizerSharedMemoryFormat) == 0x1000,
|
||||
|
||||
// This is nn::hid::detail::HomeButtonSharedMemoryFormat
|
||||
struct HomeButtonSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x1E0);
|
||||
Lifo<HomeButtonState, HidEntryCount> home_lifo{};
|
||||
INSERT_PADDING_BYTES(0x48);
|
||||
};
|
||||
static_assert(sizeof(HomeButtonSharedMemoryFormat) == 0x200,
|
||||
"HomeButtonSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::SleepButtonSharedMemoryFormat
|
||||
struct SleepButtonSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x1E0);
|
||||
Lifo<SleepButtonState, HidEntryCount> sleep_lifo{};
|
||||
INSERT_PADDING_BYTES(0x48);
|
||||
};
|
||||
static_assert(sizeof(SleepButtonSharedMemoryFormat) == 0x200,
|
||||
"SleepButtonSharedMemoryFormat is an invalid size");
|
||||
|
||||
// This is nn::hid::detail::CaptureButtonSharedMemoryFormat
|
||||
struct CaptureButtonSharedMemoryFormat {
|
||||
CommonHeader header;
|
||||
INSERT_PADDING_BYTES(0x1E0);
|
||||
Lifo<CaptureButtonState, HidEntryCount> capture_lifo{};
|
||||
INSERT_PADDING_BYTES(0x48);
|
||||
};
|
||||
static_assert(sizeof(CaptureButtonSharedMemoryFormat) == 0x200,
|
||||
"CaptureButtonSharedMemoryFormat is an invalid size");
|
||||
|
@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/core_timing.h"
|
||||
#include "hid_core/frontend/emulated_controller.h"
|
||||
#include "hid_core/hid_core.h"
|
||||
#include "hid_core/resources/applet_resource.h"
|
||||
#include "hid_core/resources/shared_memory_format.h"
|
||||
#include "hid_core/resources/system_buttons/capture_button.h"
|
||||
@ -17,10 +19,6 @@ void CaptureButton::OnInit() {}
|
||||
void CaptureButton::OnRelease() {}
|
||||
|
||||
void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!smart_update) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
@ -29,11 +27,21 @@ void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& header = data->shared_memory_format->capture_button.header;
|
||||
header.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
header.total_entry_count = 17;
|
||||
header.entry_count = 0;
|
||||
header.last_entry_index = 0;
|
||||
auto& shared_memory = data->shared_memory_format->capture_button;
|
||||
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory.capture_lifo.buffer_count = 0;
|
||||
shared_memory.capture_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& last_entry = shared_memory.capture_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
|
||||
auto* controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1);
|
||||
next_state.buttons.raw = controller->GetHomeButtons().raw;
|
||||
|
||||
shared_memory.capture_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "hid_core/resources/controller_base.h"
|
||||
#include "hid_core/resources/system_buttons/system_button_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
@ -22,6 +23,6 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
bool smart_update{};
|
||||
CaptureButtonState next_state{};
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -2,6 +2,8 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "core/core_timing.h"
|
||||
#include "hid_core/frontend/emulated_controller.h"
|
||||
#include "hid_core/hid_core.h"
|
||||
#include "hid_core/resources/applet_resource.h"
|
||||
#include "hid_core/resources/shared_memory_format.h"
|
||||
#include "hid_core/resources/system_buttons/home_button.h"
|
||||
@ -17,10 +19,6 @@ void HomeButton::OnInit() {}
|
||||
void HomeButton::OnRelease() {}
|
||||
|
||||
void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!smart_update) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
@ -29,11 +27,21 @@ void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& header = data->shared_memory_format->home_button.header;
|
||||
header.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
header.total_entry_count = 17;
|
||||
header.entry_count = 0;
|
||||
header.last_entry_index = 0;
|
||||
auto& shared_memory = data->shared_memory_format->home_button;
|
||||
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory.home_lifo.buffer_count = 0;
|
||||
shared_memory.home_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& last_entry = shared_memory.home_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
|
||||
auto* controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1);
|
||||
next_state.buttons.raw = controller->GetHomeButtons().raw;
|
||||
|
||||
shared_memory.home_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "hid_core/resources/controller_base.h"
|
||||
#include "hid_core/resources/system_buttons/system_button_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
@ -22,6 +23,6 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
bool smart_update{};
|
||||
HomeButtonState next_state{};
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
@ -17,10 +17,6 @@ void SleepButton::OnInit() {}
|
||||
void SleepButton::OnRelease() {}
|
||||
|
||||
void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
if (!smart_update) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
@ -29,11 +25,20 @@ void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& header = data->shared_memory_format->capture_button.header;
|
||||
header.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
header.total_entry_count = 17;
|
||||
header.entry_count = 0;
|
||||
header.last_entry_index = 0;
|
||||
auto& shared_memory = data->shared_memory_format->sleep_button;
|
||||
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory.sleep_lifo.buffer_count = 0;
|
||||
shared_memory.sleep_lifo.buffer_tail = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& last_entry = shared_memory.sleep_lifo.ReadCurrentEntry().state;
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
|
||||
next_state.buttons.raw = 0;
|
||||
|
||||
shared_memory.sleep_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "hid_core/resources/controller_base.h"
|
||||
#include "hid_core/resources/system_buttons/system_button_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
@ -22,6 +23,6 @@ public:
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
|
||||
private:
|
||||
bool smart_update{};
|
||||
SleepButtonState next_state{};
|
||||
};
|
||||
} // namespace Service::HID
|
||||
|
31
src/hid_core/resources/system_buttons/system_button_types.h
Executable file
31
src/hid_core/resources/system_buttons/system_button_types.h
Executable file
@ -0,0 +1,31 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hid_core/hid_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
// This is nn::hid::system::SleepButtonState
|
||||
struct SleepButtonState {
|
||||
s64 sampling_number{};
|
||||
Core::HID::SleepButtonState buttons;
|
||||
};
|
||||
static_assert(sizeof(SleepButtonState) == 0x10, "SleepButtonState is an invalid size");
|
||||
|
||||
// This is nn::hid::system::HomeButtonState
|
||||
struct HomeButtonState {
|
||||
s64 sampling_number{};
|
||||
Core::HID::HomeButtonState buttons;
|
||||
};
|
||||
static_assert(sizeof(HomeButtonState) == 0x10, "HomeButtonState is an invalid size");
|
||||
|
||||
// This is nn::hid::system::SleepButtonState
|
||||
struct CaptureButtonState {
|
||||
s64 sampling_number{};
|
||||
Core::HID::CaptureButtonState buttons;
|
||||
};
|
||||
static_assert(sizeof(CaptureButtonState) == 0x10, "CaptureButtonState is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
@ -1,366 +1,53 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "common/math_util.h"
|
||||
#include "common/settings.h"
|
||||
#include "core/frontend/emu_window.h"
|
||||
#include "hid_core/frontend/emulated_console.h"
|
||||
#include "hid_core/hid_core.h"
|
||||
#include "hid_core/resources/applet_resource.h"
|
||||
#include "hid_core/resources/shared_memory_format.h"
|
||||
#include "hid_core/resources/touch_screen/gesture.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_resource.h"
|
||||
|
||||
namespace Service::HID {
|
||||
// HW is around 700, value is set to 400 to make it easier to trigger with mouse
|
||||
constexpr f32 swipe_threshold = 400.0f; // Threshold in pixels/s
|
||||
constexpr f32 angle_threshold = 0.015f; // Threshold in radians
|
||||
constexpr f32 pinch_threshold = 0.5f; // Threshold in pixels
|
||||
constexpr f32 press_delay = 0.5f; // Time in seconds
|
||||
constexpr f32 double_tap_delay = 0.35f; // Time in seconds
|
||||
|
||||
constexpr f32 Square(s32 num) {
|
||||
return static_cast<f32>(num * num);
|
||||
}
|
||||
Gesture::Gesture(std::shared_ptr<TouchResource> resource) : touch_resource{resource} {}
|
||||
|
||||
Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) {
|
||||
console = hid_core.GetEmulatedConsole();
|
||||
}
|
||||
Gesture::~Gesture() = default;
|
||||
|
||||
void Gesture::OnInit() {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
Result Gesture::Activate() {
|
||||
std::scoped_lock lock{mutex};
|
||||
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
// TODO: Result result = CreateThread();
|
||||
Result result = ResultSuccess;
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
shared_memory = &data->shared_memory_format->gesture;
|
||||
shared_memory->gesture_lifo.buffer_count = 0;
|
||||
shared_memory->gesture_lifo.buffer_tail = 0;
|
||||
force_update = true;
|
||||
result = touch_resource->ActivateGesture();
|
||||
|
||||
if (result.IsError()) {
|
||||
// TODO: StopThread();
|
||||
}
|
||||
|
||||
void Gesture::OnRelease() {}
|
||||
|
||||
void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
std::scoped_lock shared_lock{*shared_mutex};
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
|
||||
shared_memory = &data->shared_memory_format->gesture;
|
||||
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory->gesture_lifo.buffer_count = 0;
|
||||
shared_memory->gesture_lifo.buffer_tail = 0;
|
||||
return;
|
||||
Result Gesture::Activate(u64 aruid, u32 basic_gesture_id) {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->ActivateGesture(aruid, basic_gesture_id);
|
||||
}
|
||||
|
||||
ReadTouchInput();
|
||||
Result Gesture::Deactivate() {
|
||||
std::scoped_lock lock{mutex};
|
||||
const auto result = touch_resource->DeactivateGesture();
|
||||
|
||||
GestureProperties gesture = GetGestureProperties();
|
||||
f32 time_difference =
|
||||
static_cast<f32>(shared_memory->gesture_lifo.timestamp - last_update_timestamp) /
|
||||
(1000 * 1000 * 1000);
|
||||
|
||||
// Only update if necessary
|
||||
if (!ShouldUpdateGesture(gesture, time_difference)) {
|
||||
return;
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
last_update_timestamp = shared_memory->gesture_lifo.timestamp;
|
||||
UpdateGestureSharedMemory(gesture, time_difference);
|
||||
// TODO: return StopThread();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void Gesture::ReadTouchInput() {
|
||||
if (!Settings::values.touchscreen.enabled) {
|
||||
fingers = {};
|
||||
return;
|
||||
}
|
||||
|
||||
const auto touch_status = console->GetTouch();
|
||||
for (std::size_t id = 0; id < fingers.size(); ++id) {
|
||||
fingers[id] = touch_status[id];
|
||||
}
|
||||
}
|
||||
|
||||
bool Gesture::ShouldUpdateGesture(const GestureProperties& gesture, f32 time_difference) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
if (force_update) {
|
||||
force_update = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update if coordinates change
|
||||
for (size_t id = 0; id < MAX_POINTS; id++) {
|
||||
if (gesture.points[id] != last_gesture.points[id]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update on press and hold event after 0.5 seconds
|
||||
if (last_entry.type == GestureType::Touch && last_entry.point_count == 1 &&
|
||||
time_difference > press_delay) {
|
||||
return enable_press_and_tap;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_difference) {
|
||||
GestureType type = GestureType::Idle;
|
||||
GestureAttribute attributes{};
|
||||
|
||||
const auto& last_entry = shared_memory->gesture_lifo.ReadCurrentEntry().state;
|
||||
|
||||
// Reset next state to default
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
next_state.delta = {};
|
||||
next_state.vel_x = 0;
|
||||
next_state.vel_y = 0;
|
||||
next_state.direction = GestureDirection::None;
|
||||
next_state.rotation_angle = 0;
|
||||
next_state.scale = 0;
|
||||
|
||||
if (gesture.active_points > 0) {
|
||||
if (last_gesture.active_points == 0) {
|
||||
NewGesture(gesture, type, attributes);
|
||||
} else {
|
||||
UpdateExistingGesture(gesture, type, time_difference);
|
||||
}
|
||||
} else {
|
||||
EndGesture(gesture, last_gesture, type, attributes, time_difference);
|
||||
}
|
||||
|
||||
// Apply attributes
|
||||
next_state.detection_count = gesture.detection_count;
|
||||
next_state.type = type;
|
||||
next_state.attributes = attributes;
|
||||
next_state.pos = gesture.mid_point;
|
||||
next_state.point_count = static_cast<s32>(gesture.active_points);
|
||||
next_state.points = gesture.points;
|
||||
last_gesture = gesture;
|
||||
|
||||
shared_memory->gesture_lifo.WriteNextEntry(next_state);
|
||||
}
|
||||
|
||||
void Gesture::NewGesture(GestureProperties& gesture, GestureType& type,
|
||||
GestureAttribute& attributes) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
|
||||
gesture.detection_count++;
|
||||
type = GestureType::Touch;
|
||||
|
||||
// New touch after cancel is not considered new
|
||||
if (last_entry.type != GestureType::Cancel) {
|
||||
attributes.is_new_touch.Assign(1);
|
||||
enable_press_and_tap = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Gesture::UpdateExistingGesture(GestureProperties& gesture, GestureType& type,
|
||||
f32 time_difference) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
|
||||
// Promote to pan type if touch moved
|
||||
for (size_t id = 0; id < MAX_POINTS; id++) {
|
||||
if (gesture.points[id] != last_gesture.points[id]) {
|
||||
type = GestureType::Pan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Number of fingers changed cancel the last event and clear data
|
||||
if (gesture.active_points != last_gesture.active_points) {
|
||||
type = GestureType::Cancel;
|
||||
enable_press_and_tap = false;
|
||||
gesture.active_points = 0;
|
||||
gesture.mid_point = {};
|
||||
gesture.points.fill({});
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate extra parameters of panning
|
||||
if (type == GestureType::Pan) {
|
||||
UpdatePanEvent(gesture, last_gesture, type, time_difference);
|
||||
return;
|
||||
}
|
||||
|
||||
// Promote to press type
|
||||
if (last_entry.type == GestureType::Touch) {
|
||||
type = GestureType::Press;
|
||||
}
|
||||
}
|
||||
|
||||
void Gesture::EndGesture(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, GestureAttribute& attributes, f32 time_difference) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
|
||||
if (last_gesture_props.active_points != 0) {
|
||||
switch (last_entry.type) {
|
||||
case GestureType::Touch:
|
||||
if (enable_press_and_tap) {
|
||||
SetTapEvent(gesture, last_gesture_props, type, attributes);
|
||||
return;
|
||||
}
|
||||
type = GestureType::Cancel;
|
||||
force_update = true;
|
||||
break;
|
||||
case GestureType::Press:
|
||||
case GestureType::Tap:
|
||||
case GestureType::Swipe:
|
||||
case GestureType::Pinch:
|
||||
case GestureType::Rotate:
|
||||
type = GestureType::Complete;
|
||||
force_update = true;
|
||||
break;
|
||||
case GestureType::Pan:
|
||||
EndPanEvent(gesture, last_gesture_props, type, time_difference);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (last_entry.type == GestureType::Complete || last_entry.type == GestureType::Cancel) {
|
||||
gesture.detection_count++;
|
||||
}
|
||||
}
|
||||
|
||||
void Gesture::SetTapEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, GestureAttribute& attributes) {
|
||||
type = GestureType::Tap;
|
||||
gesture = last_gesture_props;
|
||||
force_update = true;
|
||||
f32 tap_time_difference =
|
||||
static_cast<f32>(last_update_timestamp - last_tap_timestamp) / (1000 * 1000 * 1000);
|
||||
last_tap_timestamp = last_update_timestamp;
|
||||
if (tap_time_difference < double_tap_delay) {
|
||||
attributes.is_double_tap.Assign(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Gesture::UpdatePanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, f32 time_difference) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
|
||||
next_state.delta = gesture.mid_point - last_entry.pos;
|
||||
next_state.vel_x = static_cast<f32>(next_state.delta.x) / time_difference;
|
||||
next_state.vel_y = static_cast<f32>(next_state.delta.y) / time_difference;
|
||||
last_pan_time_difference = time_difference;
|
||||
|
||||
// Promote to pinch type
|
||||
if (std::abs(gesture.average_distance - last_gesture_props.average_distance) >
|
||||
pinch_threshold) {
|
||||
type = GestureType::Pinch;
|
||||
next_state.scale = gesture.average_distance / last_gesture_props.average_distance;
|
||||
}
|
||||
|
||||
const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture_props.angle) /
|
||||
(1 + (gesture.angle * last_gesture_props.angle)));
|
||||
// Promote to rotate type
|
||||
if (std::abs(angle_between_two_lines) > angle_threshold) {
|
||||
type = GestureType::Rotate;
|
||||
next_state.scale = 0;
|
||||
next_state.rotation_angle = angle_between_two_lines * 180.0f / Common::PI;
|
||||
}
|
||||
}
|
||||
|
||||
void Gesture::EndPanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, f32 time_difference) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
next_state.vel_x =
|
||||
static_cast<f32>(last_entry.delta.x) / (last_pan_time_difference + time_difference);
|
||||
next_state.vel_y =
|
||||
static_cast<f32>(last_entry.delta.y) / (last_pan_time_difference + time_difference);
|
||||
const f32 curr_vel =
|
||||
std::sqrt((next_state.vel_x * next_state.vel_x) + (next_state.vel_y * next_state.vel_y));
|
||||
|
||||
// Set swipe event with parameters
|
||||
if (curr_vel > swipe_threshold) {
|
||||
SetSwipeEvent(gesture, last_gesture_props, type);
|
||||
return;
|
||||
}
|
||||
|
||||
// End panning without swipe
|
||||
type = GestureType::Complete;
|
||||
next_state.vel_x = 0;
|
||||
next_state.vel_y = 0;
|
||||
force_update = true;
|
||||
}
|
||||
|
||||
void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type) {
|
||||
const auto& last_entry = GetLastGestureEntry();
|
||||
|
||||
type = GestureType::Swipe;
|
||||
gesture = last_gesture_props;
|
||||
force_update = true;
|
||||
next_state.delta = last_entry.delta;
|
||||
|
||||
if (std::abs(next_state.delta.x) > std::abs(next_state.delta.y)) {
|
||||
if (next_state.delta.x > 0) {
|
||||
next_state.direction = GestureDirection::Right;
|
||||
return;
|
||||
}
|
||||
next_state.direction = GestureDirection::Left;
|
||||
return;
|
||||
}
|
||||
if (next_state.delta.y > 0) {
|
||||
next_state.direction = GestureDirection::Down;
|
||||
return;
|
||||
}
|
||||
next_state.direction = GestureDirection::Up;
|
||||
}
|
||||
|
||||
const GestureState& Gesture::GetLastGestureEntry() const {
|
||||
return shared_memory->gesture_lifo.ReadCurrentEntry().state;
|
||||
}
|
||||
|
||||
GestureProperties Gesture::GetGestureProperties() {
|
||||
GestureProperties gesture;
|
||||
std::array<Core::HID::TouchFinger, MAX_POINTS> active_fingers;
|
||||
const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(),
|
||||
[](const auto& finger) { return finger.pressed; });
|
||||
gesture.active_points =
|
||||
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
|
||||
|
||||
for (size_t id = 0; id < gesture.active_points; ++id) {
|
||||
const auto& [active_x, active_y] = active_fingers[id].position;
|
||||
gesture.points[id] = {
|
||||
.x = static_cast<s32>(active_x * Layout::ScreenUndocked::Width),
|
||||
.y = static_cast<s32>(active_y * Layout::ScreenUndocked::Height),
|
||||
};
|
||||
|
||||
// Hack: There is no touch in docked but games still allow it
|
||||
if (Settings::IsDockedMode()) {
|
||||
gesture.points[id] = {
|
||||
.x = static_cast<s32>(active_x * Layout::ScreenDocked::Width),
|
||||
.y = static_cast<s32>(active_y * Layout::ScreenDocked::Height),
|
||||
};
|
||||
}
|
||||
|
||||
gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points);
|
||||
gesture.mid_point.y += static_cast<s32>(gesture.points[id].y / gesture.active_points);
|
||||
}
|
||||
|
||||
for (size_t id = 0; id < gesture.active_points; ++id) {
|
||||
const f32 distance = std::sqrt(Square(gesture.mid_point.x - gesture.points[id].x) +
|
||||
Square(gesture.mid_point.y - gesture.points[id].y));
|
||||
gesture.average_distance += distance / static_cast<f32>(gesture.active_points);
|
||||
}
|
||||
|
||||
gesture.angle = std::atan2(static_cast<f32>(gesture.mid_point.y - gesture.points[0].y),
|
||||
static_cast<f32>(gesture.mid_point.x - gesture.points[0].x));
|
||||
|
||||
gesture.detection_count = last_gesture.detection_count;
|
||||
|
||||
return gesture;
|
||||
Result Gesture::IsActive(bool& out_is_active) const {
|
||||
out_is_active = touch_resource->IsGestureActive();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -1,87 +1,32 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "hid_core/resources/controller_base.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedConsole;
|
||||
}
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service::HID {
|
||||
struct GestureSharedMemoryFormat;
|
||||
class TouchResource;
|
||||
|
||||
class Gesture final : public ControllerBase {
|
||||
/// Handles gesture request from HID interfaces
|
||||
class Gesture {
|
||||
public:
|
||||
explicit Gesture(Core::HID::HIDCore& hid_core_);
|
||||
~Gesture() override;
|
||||
Gesture(std::shared_ptr<TouchResource> resource);
|
||||
~Gesture();
|
||||
|
||||
// Called when the controller is initialized
|
||||
void OnInit() override;
|
||||
Result Activate();
|
||||
Result Activate(u64 aruid, u32 basic_gesture_id);
|
||||
|
||||
// When the controller is released
|
||||
void OnRelease() override;
|
||||
Result Deactivate();
|
||||
|
||||
// When the controller is requesting an update for the shared memory
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
Result IsActive(bool& out_is_active) const;
|
||||
|
||||
private:
|
||||
// Reads input from all available input engines
|
||||
void ReadTouchInput();
|
||||
|
||||
// Returns true if gesture state needs to be updated
|
||||
bool ShouldUpdateGesture(const GestureProperties& gesture, f32 time_difference);
|
||||
|
||||
// Updates the shared memory to the next state
|
||||
void UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_difference);
|
||||
|
||||
// Initializes new gesture
|
||||
void NewGesture(GestureProperties& gesture, GestureType& type, GestureAttribute& attributes);
|
||||
|
||||
// Updates existing gesture state
|
||||
void UpdateExistingGesture(GestureProperties& gesture, GestureType& type, f32 time_difference);
|
||||
|
||||
// Terminates exiting gesture
|
||||
void EndGesture(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, GestureAttribute& attributes, f32 time_difference);
|
||||
|
||||
// Set current event to a tap event
|
||||
void SetTapEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, GestureAttribute& attributes);
|
||||
|
||||
// Calculates and set the extra parameters related to a pan event
|
||||
void UpdatePanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, f32 time_difference);
|
||||
|
||||
// Terminates the pan event
|
||||
void EndPanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type, f32 time_difference);
|
||||
|
||||
// Set current event to a swipe event
|
||||
void SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_gesture_props,
|
||||
GestureType& type);
|
||||
|
||||
// Retrieves the last gesture entry, as indicated by shared memory indices.
|
||||
[[nodiscard]] const GestureState& GetLastGestureEntry() const;
|
||||
|
||||
// Returns the average distance, angle and middle point of the active fingers
|
||||
GestureProperties GetGestureProperties();
|
||||
|
||||
GestureState next_state{};
|
||||
GestureSharedMemoryFormat* shared_memory;
|
||||
Core::HID::EmulatedConsole* console = nullptr;
|
||||
|
||||
std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{};
|
||||
GestureProperties last_gesture{};
|
||||
s64 last_update_timestamp{};
|
||||
s64 last_tap_timestamp{};
|
||||
f32 last_pan_time_difference{};
|
||||
bool force_update{false};
|
||||
bool enable_press_and_tap{false};
|
||||
mutable std::mutex mutex;
|
||||
std::shared_ptr<TouchResource> touch_resource;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
||||
|
260
src/hid_core/resources/touch_screen/gesture_handler.cpp
Executable file
260
src/hid_core/resources/touch_screen/gesture_handler.cpp
Executable file
@ -0,0 +1,260 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "common/math_util.h"
|
||||
#include "hid_core/resources/touch_screen/gesture_handler.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
constexpr f32 Square(s32 num) {
|
||||
return static_cast<f32>(num * num);
|
||||
}
|
||||
|
||||
GestureHandler::GestureHandler() {}
|
||||
|
||||
GestureHandler::~GestureHandler() {}
|
||||
|
||||
void GestureHandler::SetTouchState(std::span<TouchState> touch_state, u32 count, s64 timestamp) {
|
||||
gesture = {};
|
||||
gesture.active_points = std::min(MaxPoints, static_cast<std::size_t>(count));
|
||||
|
||||
for (size_t id = 0; id < gesture.active_points; ++id) {
|
||||
const auto& [active_x, active_y] = touch_state[id].position;
|
||||
gesture.points[id] = {
|
||||
.x = static_cast<s32>(active_x),
|
||||
.y = static_cast<s32>(active_y),
|
||||
};
|
||||
|
||||
gesture.mid_point.x += static_cast<s32>(gesture.points[id].x / gesture.active_points);
|
||||
gesture.mid_point.y += static_cast<s32>(gesture.points[id].y / gesture.active_points);
|
||||
}
|
||||
|
||||
for (size_t id = 0; id < gesture.active_points; ++id) {
|
||||
const f32 distance = std::sqrt(Square(gesture.mid_point.x - gesture.points[id].x) +
|
||||
Square(gesture.mid_point.y - gesture.points[id].y));
|
||||
gesture.average_distance += distance / static_cast<f32>(gesture.active_points);
|
||||
}
|
||||
|
||||
gesture.angle = std::atan2(static_cast<f32>(gesture.mid_point.y - gesture.points[0].y),
|
||||
static_cast<f32>(gesture.mid_point.x - gesture.points[0].x));
|
||||
|
||||
gesture.detection_count = last_gesture.detection_count;
|
||||
|
||||
if (last_update_timestamp > timestamp) {
|
||||
timestamp = last_tap_timestamp;
|
||||
}
|
||||
|
||||
time_difference = static_cast<f32>(timestamp - last_update_timestamp) / (1000 * 1000 * 1000);
|
||||
}
|
||||
|
||||
bool GestureHandler::NeedsUpdate() {
|
||||
if (force_update) {
|
||||
force_update = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update if coordinates change
|
||||
for (size_t id = 0; id < MaxPoints; id++) {
|
||||
if (gesture.points[id] != last_gesture.points[id]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Update on press and hold event after 0.5 seconds
|
||||
if (last_gesture_state.type == GestureType::Touch && last_gesture_state.point_count == 1 &&
|
||||
time_difference > PressDelay) {
|
||||
return enable_press_and_tap;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GestureHandler::UpdateGestureState(GestureState& next_state, s64 timestamp) {
|
||||
last_update_timestamp = timestamp;
|
||||
|
||||
GestureType type = GestureType::Idle;
|
||||
GestureAttribute attributes{};
|
||||
|
||||
// Reset next state to default
|
||||
next_state.sampling_number = last_gesture_state.sampling_number + 1;
|
||||
next_state.delta = {};
|
||||
next_state.vel_x = 0;
|
||||
next_state.vel_y = 0;
|
||||
next_state.direction = GestureDirection::None;
|
||||
next_state.rotation_angle = 0;
|
||||
next_state.scale = 0;
|
||||
|
||||
if (gesture.active_points > 0) {
|
||||
if (last_gesture.active_points == 0) {
|
||||
NewGesture(type, attributes);
|
||||
} else {
|
||||
UpdateExistingGesture(next_state, type);
|
||||
}
|
||||
} else {
|
||||
EndGesture(next_state, type, attributes);
|
||||
}
|
||||
|
||||
// Apply attributes
|
||||
next_state.detection_count = gesture.detection_count;
|
||||
next_state.type = type;
|
||||
next_state.attributes = attributes;
|
||||
next_state.pos = gesture.mid_point;
|
||||
next_state.point_count = static_cast<s32>(gesture.active_points);
|
||||
next_state.points = gesture.points;
|
||||
last_gesture = gesture;
|
||||
last_gesture_state = next_state;
|
||||
}
|
||||
|
||||
void GestureHandler::NewGesture(GestureType& type, GestureAttribute& attributes) {
|
||||
gesture.detection_count++;
|
||||
type = GestureType::Touch;
|
||||
|
||||
// New touch after cancel is not considered new
|
||||
if (last_gesture_state.type != GestureType::Cancel) {
|
||||
attributes.is_new_touch.Assign(1);
|
||||
enable_press_and_tap = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GestureHandler::UpdateExistingGesture(GestureState& next_state, GestureType& type) {
|
||||
// Promote to pan type if touch moved
|
||||
for (size_t id = 0; id < MaxPoints; id++) {
|
||||
if (gesture.points[id] != last_gesture.points[id]) {
|
||||
type = GestureType::Pan;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Number of fingers changed cancel the last event and clear data
|
||||
if (gesture.active_points != last_gesture.active_points) {
|
||||
type = GestureType::Cancel;
|
||||
enable_press_and_tap = false;
|
||||
gesture.active_points = 0;
|
||||
gesture.mid_point = {};
|
||||
gesture.points.fill({});
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate extra parameters of panning
|
||||
if (type == GestureType::Pan) {
|
||||
UpdatePanEvent(next_state, type);
|
||||
return;
|
||||
}
|
||||
|
||||
// Promote to press type
|
||||
if (last_gesture_state.type == GestureType::Touch) {
|
||||
type = GestureType::Press;
|
||||
}
|
||||
}
|
||||
|
||||
void GestureHandler::EndGesture(GestureState& next_state, GestureType& type,
|
||||
GestureAttribute& attributes) {
|
||||
if (last_gesture.active_points != 0) {
|
||||
switch (last_gesture_state.type) {
|
||||
case GestureType::Touch:
|
||||
if (enable_press_and_tap) {
|
||||
SetTapEvent(type, attributes);
|
||||
return;
|
||||
}
|
||||
type = GestureType::Cancel;
|
||||
force_update = true;
|
||||
break;
|
||||
case GestureType::Press:
|
||||
case GestureType::Tap:
|
||||
case GestureType::Swipe:
|
||||
case GestureType::Pinch:
|
||||
case GestureType::Rotate:
|
||||
type = GestureType::Complete;
|
||||
force_update = true;
|
||||
break;
|
||||
case GestureType::Pan:
|
||||
EndPanEvent(next_state, type);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (last_gesture_state.type == GestureType::Complete ||
|
||||
last_gesture_state.type == GestureType::Cancel) {
|
||||
gesture.detection_count++;
|
||||
}
|
||||
}
|
||||
|
||||
void GestureHandler::SetTapEvent(GestureType& type, GestureAttribute& attributes) {
|
||||
type = GestureType::Tap;
|
||||
gesture = last_gesture;
|
||||
force_update = true;
|
||||
f32 tap_time_difference =
|
||||
static_cast<f32>(last_update_timestamp - last_tap_timestamp) / (1000 * 1000 * 1000);
|
||||
last_tap_timestamp = last_update_timestamp;
|
||||
if (tap_time_difference < DoubleTapDelay) {
|
||||
attributes.is_double_tap.Assign(1);
|
||||
}
|
||||
}
|
||||
|
||||
void GestureHandler::UpdatePanEvent(GestureState& next_state, GestureType& type) {
|
||||
next_state.delta = gesture.mid_point - last_gesture_state.pos;
|
||||
next_state.vel_x = static_cast<f32>(next_state.delta.x) / time_difference;
|
||||
next_state.vel_y = static_cast<f32>(next_state.delta.y) / time_difference;
|
||||
last_pan_time_difference = time_difference;
|
||||
|
||||
// Promote to pinch type
|
||||
if (std::abs(gesture.average_distance - last_gesture.average_distance) > PinchThreshold) {
|
||||
type = GestureType::Pinch;
|
||||
next_state.scale = gesture.average_distance / last_gesture.average_distance;
|
||||
}
|
||||
|
||||
const f32 angle_between_two_lines = std::atan((gesture.angle - last_gesture.angle) /
|
||||
(1 + (gesture.angle * last_gesture.angle)));
|
||||
// Promote to rotate type
|
||||
if (std::abs(angle_between_two_lines) > AngleThreshold) {
|
||||
type = GestureType::Rotate;
|
||||
next_state.scale = 0;
|
||||
next_state.rotation_angle = angle_between_two_lines * 180.0f / Common::PI;
|
||||
}
|
||||
}
|
||||
|
||||
void GestureHandler::EndPanEvent(GestureState& next_state, GestureType& type) {
|
||||
next_state.vel_x =
|
||||
static_cast<f32>(last_gesture_state.delta.x) / (last_pan_time_difference + time_difference);
|
||||
next_state.vel_y =
|
||||
static_cast<f32>(last_gesture_state.delta.y) / (last_pan_time_difference + time_difference);
|
||||
const f32 curr_vel =
|
||||
std::sqrt((next_state.vel_x * next_state.vel_x) + (next_state.vel_y * next_state.vel_y));
|
||||
|
||||
// Set swipe event with parameters
|
||||
if (curr_vel > SwipeThreshold) {
|
||||
SetSwipeEvent(next_state, type);
|
||||
return;
|
||||
}
|
||||
|
||||
// End panning without swipe
|
||||
type = GestureType::Complete;
|
||||
next_state.vel_x = 0;
|
||||
next_state.vel_y = 0;
|
||||
force_update = true;
|
||||
}
|
||||
|
||||
void GestureHandler::SetSwipeEvent(GestureState& next_state, GestureType& type) {
|
||||
type = GestureType::Swipe;
|
||||
gesture = last_gesture;
|
||||
force_update = true;
|
||||
next_state.delta = last_gesture_state.delta;
|
||||
|
||||
if (std::abs(next_state.delta.x) > std::abs(next_state.delta.y)) {
|
||||
if (next_state.delta.x > 0) {
|
||||
next_state.direction = GestureDirection::Right;
|
||||
return;
|
||||
}
|
||||
next_state.direction = GestureDirection::Left;
|
||||
return;
|
||||
}
|
||||
if (next_state.delta.y > 0) {
|
||||
next_state.direction = GestureDirection::Down;
|
||||
return;
|
||||
}
|
||||
next_state.direction = GestureDirection::Up;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
55
src/hid_core/resources/touch_screen/gesture_handler.h
Executable file
55
src/hid_core/resources/touch_screen/gesture_handler.h
Executable file
@ -0,0 +1,55 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
class GestureHandler {
|
||||
public:
|
||||
GestureHandler();
|
||||
~GestureHandler();
|
||||
|
||||
void SetTouchState(std::span<TouchState> touch_state, u32 count, s64 timestamp);
|
||||
|
||||
bool NeedsUpdate();
|
||||
void UpdateGestureState(GestureState& next_state, s64 timestamp);
|
||||
|
||||
private:
|
||||
// Initializes new gesture
|
||||
void NewGesture(GestureType& type, GestureAttribute& attributes);
|
||||
|
||||
// Updates existing gesture state
|
||||
void UpdateExistingGesture(GestureState& next_state, GestureType& type);
|
||||
|
||||
// Terminates exiting gesture
|
||||
void EndGesture(GestureState& next_state, GestureType& type, GestureAttribute& attributes);
|
||||
|
||||
// Set current event to a tap event
|
||||
void SetTapEvent(GestureType& type, GestureAttribute& attributes);
|
||||
|
||||
// Calculates and set the extra parameters related to a pan event
|
||||
void UpdatePanEvent(GestureState& next_state, GestureType& type);
|
||||
|
||||
// Terminates the pan event
|
||||
void EndPanEvent(GestureState& next_state, GestureType& type);
|
||||
|
||||
// Set current event to a swipe event
|
||||
void SetSwipeEvent(GestureState& next_state, GestureType& type);
|
||||
|
||||
GestureProperties gesture{};
|
||||
GestureProperties last_gesture{};
|
||||
GestureState last_gesture_state{};
|
||||
s64 last_update_timestamp{};
|
||||
s64 last_tap_timestamp{};
|
||||
f32 last_pan_time_difference{};
|
||||
f32 time_difference{};
|
||||
bool force_update{true};
|
||||
bool enable_press_and_tap{false};
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
@ -1,132 +1,119 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include "common/common_types.h"
|
||||
#include "common/settings.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/frontend/emu_window.h"
|
||||
#include "hid_core/frontend/emulated_console.h"
|
||||
#include "hid_core/hid_core.h"
|
||||
#include "hid_core/resources/applet_resource.h"
|
||||
#include "hid_core/resources/shared_memory_format.h"
|
||||
#include "hid_core/hid_types.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_resource.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_)
|
||||
: ControllerBase{hid_core_}, touchscreen_width(Layout::ScreenUndocked::Width),
|
||||
touchscreen_height(Layout::ScreenUndocked::Height) {
|
||||
console = hid_core.GetEmulatedConsole();
|
||||
}
|
||||
TouchScreen::TouchScreen(std::shared_ptr<TouchResource> resource) : touch_resource{resource} {}
|
||||
|
||||
TouchScreen::~TouchScreen() = default;
|
||||
|
||||
void TouchScreen::OnInit() {}
|
||||
Result TouchScreen::Activate() {
|
||||
std::scoped_lock lock{mutex};
|
||||
|
||||
void TouchScreen::OnRelease() {}
|
||||
|
||||
void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
const u64 aruid = applet_resource->GetActiveAruid();
|
||||
auto* data = applet_resource->GetAruidData(aruid);
|
||||
|
||||
if (data == nullptr || !data->flag.is_assigned) {
|
||||
return;
|
||||
// TODO: Result result = CreateThread();
|
||||
Result result = ResultSuccess;
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
TouchScreenSharedMemoryFormat& shared_memory = data->shared_memory_format->touch_screen;
|
||||
shared_memory.touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
|
||||
if (!IsControllerActivated()) {
|
||||
shared_memory.touch_screen_lifo.buffer_count = 0;
|
||||
shared_memory.touch_screen_lifo.buffer_tail = 0;
|
||||
return;
|
||||
result = touch_resource->ActivateTouch();
|
||||
if (result.IsError()) {
|
||||
// TODO: StopThread();
|
||||
}
|
||||
|
||||
const auto touch_status = console->GetTouch();
|
||||
for (std::size_t id = 0; id < MAX_FINGERS; id++) {
|
||||
const auto& current_touch = touch_status[id];
|
||||
auto& finger = fingers[id];
|
||||
finger.id = current_touch.id;
|
||||
|
||||
if (finger.attribute.start_touch) {
|
||||
finger.attribute.raw = 0;
|
||||
continue;
|
||||
return result;
|
||||
}
|
||||
|
||||
if (finger.attribute.end_touch) {
|
||||
finger.attribute.raw = 0;
|
||||
finger.pressed = false;
|
||||
continue;
|
||||
Result TouchScreen::Activate(u64 aruid) {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->ActivateTouch(aruid);
|
||||
}
|
||||
|
||||
if (!finger.pressed && current_touch.pressed) {
|
||||
// Ignore all touch fingers if disabled
|
||||
if (!Settings::values.touchscreen.enabled) {
|
||||
continue;
|
||||
Result TouchScreen::Deactivate() {
|
||||
std::scoped_lock lock{mutex};
|
||||
const auto result = touch_resource->DeactivateTouch();
|
||||
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
finger.attribute.start_touch.Assign(1);
|
||||
finger.pressed = true;
|
||||
finger.position = current_touch.position;
|
||||
continue;
|
||||
// TODO: return StopThread();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
if (finger.pressed && !current_touch.pressed) {
|
||||
finger.attribute.raw = 0;
|
||||
finger.attribute.end_touch.Assign(1);
|
||||
continue;
|
||||
Result TouchScreen::IsActive(bool& out_is_active) const {
|
||||
out_is_active = touch_resource->IsTouchActive();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
// Only update position if touch is not on a special frame
|
||||
finger.position = current_touch.position;
|
||||
Result TouchScreen::SetTouchScreenAutoPilotState(const AutoPilotState& auto_pilot_state) {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->SetTouchScreenAutoPilotState(auto_pilot_state);
|
||||
}
|
||||
|
||||
std::array<Core::HID::TouchFinger, MAX_FINGERS> active_fingers;
|
||||
const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(),
|
||||
[](const auto& finger) { return finger.pressed; });
|
||||
const auto active_fingers_count =
|
||||
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
|
||||
|
||||
const u64 timestamp = static_cast<u64>(core_timing.GetGlobalTimeNs().count());
|
||||
const auto& last_entry = shared_memory.touch_screen_lifo.ReadCurrentEntry().state;
|
||||
|
||||
next_state.sampling_number = last_entry.sampling_number + 1;
|
||||
next_state.entry_count = static_cast<s32>(active_fingers_count);
|
||||
|
||||
for (std::size_t id = 0; id < MAX_FINGERS; ++id) {
|
||||
auto& touch_entry = next_state.states[id];
|
||||
if (id < active_fingers_count) {
|
||||
const auto& [active_x, active_y] = active_fingers[id].position;
|
||||
touch_entry.position = {
|
||||
.x = static_cast<u16>(active_x * static_cast<float>(touchscreen_width)),
|
||||
.y = static_cast<u16>(active_y * static_cast<float>(touchscreen_height)),
|
||||
};
|
||||
touch_entry.diameter_x = Settings::values.touchscreen.diameter_x;
|
||||
touch_entry.diameter_y = Settings::values.touchscreen.diameter_y;
|
||||
touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle;
|
||||
touch_entry.delta_time = timestamp - active_fingers[id].last_touch;
|
||||
fingers[active_fingers[id].id].last_touch = timestamp;
|
||||
touch_entry.finger = active_fingers[id].id;
|
||||
touch_entry.attribute.raw = active_fingers[id].attribute.raw;
|
||||
} else {
|
||||
// Clear touch entry
|
||||
touch_entry.attribute.raw = 0;
|
||||
touch_entry.position = {};
|
||||
touch_entry.diameter_x = 0;
|
||||
touch_entry.diameter_y = 0;
|
||||
touch_entry.rotation_angle = 0;
|
||||
touch_entry.delta_time = 0;
|
||||
touch_entry.finger = 0;
|
||||
}
|
||||
Result TouchScreen::UnsetTouchScreenAutoPilotState() {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->UnsetTouchScreenAutoPilotState();
|
||||
}
|
||||
|
||||
shared_memory.touch_screen_lifo.WriteNextEntry(next_state);
|
||||
Result TouchScreen::RequestNextTouchInput() {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->RequestNextTouchInput();
|
||||
}
|
||||
|
||||
void TouchScreen::SetTouchscreenDimensions(u32 width, u32 height) {
|
||||
touchscreen_width = width;
|
||||
touchscreen_height = height;
|
||||
Result TouchScreen::RequestNextDummyInput() {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->RequestNextDummyInput();
|
||||
}
|
||||
|
||||
Result TouchScreen::ProcessTouchScreenAutoTune() {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->ProcessTouchScreenAutoTune();
|
||||
}
|
||||
|
||||
Result TouchScreen::SetTouchScreenMagnification(f32 point1_x, f32 point1_y, f32 point2_x,
|
||||
f32 point2_y) {
|
||||
std::scoped_lock lock{mutex};
|
||||
touch_resource->SetTouchScreenMagnification(point1_x, point1_y, point2_x, point2_y);
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchScreen::SetTouchScreenResolution(u32 width, u32 height, u64 aruid) {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->SetTouchScreenResolution(width, height, aruid);
|
||||
}
|
||||
|
||||
Result TouchScreen::SetTouchScreenConfiguration(
|
||||
const Core::HID::TouchScreenConfigurationForNx& mode, u64 aruid) {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->SetTouchScreenConfiguration(mode, aruid);
|
||||
}
|
||||
|
||||
Result TouchScreen::GetTouchScreenConfiguration(Core::HID::TouchScreenConfigurationForNx& out_mode,
|
||||
u64 aruid) const {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->GetTouchScreenConfiguration(out_mode, aruid);
|
||||
}
|
||||
|
||||
Result TouchScreen::SetTouchScreenDefaultConfiguration(
|
||||
const Core::HID::TouchScreenConfigurationForNx& mode) {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->SetTouchScreenDefaultConfiguration(mode);
|
||||
}
|
||||
|
||||
Result TouchScreen::GetTouchScreenDefaultConfiguration(
|
||||
Core::HID::TouchScreenConfigurationForNx& out_mode) const {
|
||||
std::scoped_lock lock{mutex};
|
||||
return touch_resource->GetTouchScreenDefaultConfiguration(out_mode);
|
||||
}
|
||||
|
||||
void TouchScreen::OnTouchUpdate(u64 timestamp) {
|
||||
std::scoped_lock lock{mutex};
|
||||
touch_resource->OnTouchUpdate(timestamp);
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -1,43 +1,64 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "hid_core/hid_types.h"
|
||||
#include "hid_core/resources/controller_base.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class EmulatedConsole;
|
||||
} // namespace Core::HID
|
||||
struct TouchScreenConfigurationForNx;
|
||||
}
|
||||
|
||||
namespace Core::Timing {
|
||||
struct EventType;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
struct TouchScreenSharedMemoryFormat;
|
||||
class TouchResource;
|
||||
struct AutoPilotState;
|
||||
|
||||
class TouchScreen final : public ControllerBase {
|
||||
/// Handles touch request from HID interfaces
|
||||
class TouchScreen {
|
||||
public:
|
||||
explicit TouchScreen(Core::HID::HIDCore& hid_core_);
|
||||
~TouchScreen() override;
|
||||
TouchScreen(std::shared_ptr<TouchResource> resource);
|
||||
~TouchScreen();
|
||||
|
||||
// Called when the controller is initialized
|
||||
void OnInit() override;
|
||||
Result Activate();
|
||||
Result Activate(u64 aruid);
|
||||
|
||||
// When the controller is released
|
||||
void OnRelease() override;
|
||||
Result Deactivate();
|
||||
|
||||
// When the controller is requesting an update for the shared memory
|
||||
void OnUpdate(const Core::Timing::CoreTiming& core_timing) override;
|
||||
Result IsActive(bool& out_is_active) const;
|
||||
|
||||
void SetTouchscreenDimensions(u32 width, u32 height);
|
||||
Result SetTouchScreenAutoPilotState(const AutoPilotState& auto_pilot_state);
|
||||
Result UnsetTouchScreenAutoPilotState();
|
||||
|
||||
Result RequestNextTouchInput();
|
||||
Result RequestNextDummyInput();
|
||||
|
||||
Result ProcessTouchScreenAutoTune();
|
||||
|
||||
Result SetTouchScreenMagnification(f32 point1_x, f32 point1_y, f32 point2_x, f32 point2_y);
|
||||
Result SetTouchScreenResolution(u32 width, u32 height, u64 aruid);
|
||||
|
||||
Result SetTouchScreenConfiguration(const Core::HID::TouchScreenConfigurationForNx& mode,
|
||||
u64 aruid);
|
||||
Result GetTouchScreenConfiguration(Core::HID::TouchScreenConfigurationForNx& out_mode,
|
||||
u64 aruid) const;
|
||||
|
||||
Result SetTouchScreenDefaultConfiguration(const Core::HID::TouchScreenConfigurationForNx& mode);
|
||||
Result GetTouchScreenDefaultConfiguration(
|
||||
Core::HID::TouchScreenConfigurationForNx& out_mode) const;
|
||||
|
||||
void OnTouchUpdate(u64 timestamp);
|
||||
|
||||
private:
|
||||
TouchScreenState next_state{};
|
||||
Core::HID::EmulatedConsole* console = nullptr;
|
||||
|
||||
std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers{};
|
||||
u32 touchscreen_width;
|
||||
u32 touchscreen_height;
|
||||
mutable std::mutex mutex;
|
||||
std::shared_ptr<TouchResource> touch_resource;
|
||||
std::shared_ptr<Core::Timing::EventType> touch_update_event;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
||||
|
114
src/hid_core/resources/touch_screen/touch_screen_driver.cpp
Executable file
114
src/hid_core/resources/touch_screen/touch_screen_driver.cpp
Executable file
@ -0,0 +1,114 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <algorithm>
|
||||
#include "common/settings.h"
|
||||
#include "core/frontend/emu_window.h"
|
||||
#include "hid_core/hid_core.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_driver.h"
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
TouchDriver::TouchDriver(Core::HID::HIDCore& hid_core) {
|
||||
console = hid_core.GetEmulatedConsole();
|
||||
}
|
||||
|
||||
TouchDriver::~TouchDriver() = default;
|
||||
|
||||
Result TouchDriver::StartTouchSensor() {
|
||||
is_running = true;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchDriver::StopTouchSensor() {
|
||||
is_running = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
bool TouchDriver::IsRunning() const {
|
||||
return is_running;
|
||||
}
|
||||
|
||||
void TouchDriver::ProcessTouchScreenAutoTune() const {
|
||||
// TODO
|
||||
}
|
||||
|
||||
Result TouchDriver::WaitForDummyInput() {
|
||||
touch_status = {};
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchDriver::WaitForInput() {
|
||||
touch_status = {};
|
||||
const auto touch_input = console->GetTouch();
|
||||
for (std::size_t id = 0; id < touch_status.states.size(); id++) {
|
||||
const auto& current_touch = touch_input[id];
|
||||
auto& finger = fingers[id];
|
||||
finger.id = current_touch.id;
|
||||
|
||||
if (finger.attribute.start_touch) {
|
||||
finger.attribute.raw = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (finger.attribute.end_touch) {
|
||||
finger.attribute.raw = 0;
|
||||
finger.pressed = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!finger.pressed && current_touch.pressed) {
|
||||
finger.attribute.start_touch.Assign(1);
|
||||
finger.pressed = true;
|
||||
finger.position = current_touch.position;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (finger.pressed && !current_touch.pressed) {
|
||||
finger.attribute.raw = 0;
|
||||
finger.attribute.end_touch.Assign(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only update position if touch is not on a special frame
|
||||
finger.position = current_touch.position;
|
||||
}
|
||||
|
||||
std::array<Core::HID::TouchFinger, MaxFingers> active_fingers;
|
||||
const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(),
|
||||
[](const auto& finger) { return finger.pressed; });
|
||||
const auto active_fingers_count =
|
||||
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
|
||||
|
||||
touch_status.entry_count = static_cast<s32>(active_fingers_count);
|
||||
for (std::size_t id = 0; id < MaxFingers; ++id) {
|
||||
auto& touch_entry = touch_status.states[id];
|
||||
if (id < active_fingers_count) {
|
||||
const auto& [active_x, active_y] = active_fingers[id].position;
|
||||
touch_entry.position = {
|
||||
.x = static_cast<u16>(active_x * TouchSensorWidth),
|
||||
.y = static_cast<u16>(active_y * TouchSensorHeight),
|
||||
};
|
||||
touch_entry.diameter_x = Settings::values.touchscreen.diameter_x;
|
||||
touch_entry.diameter_y = Settings::values.touchscreen.diameter_y;
|
||||
touch_entry.rotation_angle = Settings::values.touchscreen.rotation_angle;
|
||||
touch_entry.finger = active_fingers[id].id;
|
||||
touch_entry.attribute.raw = active_fingers[id].attribute.raw;
|
||||
}
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void TouchDriver::GetNextTouchState(TouchScreenState& out_state) const {
|
||||
out_state = touch_status;
|
||||
}
|
||||
|
||||
void TouchDriver::SetTouchMode(Core::HID::TouchScreenModeForNx mode) {
|
||||
touch_mode = mode;
|
||||
}
|
||||
|
||||
Core::HID::TouchScreenModeForNx TouchDriver::GetTouchMode() const {
|
||||
return touch_mode;
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
47
src/hid_core/resources/touch_screen/touch_screen_driver.h
Executable file
47
src/hid_core/resources/touch_screen/touch_screen_driver.h
Executable file
@ -0,0 +1,47 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "hid_core/frontend/emulated_console.h"
|
||||
#include "hid_core/hid_types.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Core::HID {
|
||||
class HIDCore;
|
||||
} // namespace Core::HID
|
||||
|
||||
namespace Service::HID {
|
||||
|
||||
/// This handles all request to Ftm3bd56(TouchPanel) hardware
|
||||
class TouchDriver {
|
||||
public:
|
||||
explicit TouchDriver(Core::HID::HIDCore& hid_core);
|
||||
~TouchDriver();
|
||||
|
||||
Result StartTouchSensor();
|
||||
Result StopTouchSensor();
|
||||
bool IsRunning() const;
|
||||
|
||||
void ProcessTouchScreenAutoTune() const;
|
||||
|
||||
Result WaitForDummyInput();
|
||||
Result WaitForInput();
|
||||
|
||||
void GetNextTouchState(TouchScreenState& out_state) const;
|
||||
|
||||
void SetTouchMode(Core::HID::TouchScreenModeForNx mode);
|
||||
Core::HID::TouchScreenModeForNx GetTouchMode() const;
|
||||
|
||||
private:
|
||||
bool is_running{};
|
||||
TouchScreenState touch_status{};
|
||||
Core::HID::TouchFingerState fingers{};
|
||||
Core::HID::TouchScreenModeForNx touch_mode{};
|
||||
|
||||
Core::HID::EmulatedConsole* console = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
579
src/hid_core/resources/touch_screen/touch_screen_resource.cpp
Executable file
579
src/hid_core/resources/touch_screen/touch_screen_resource.cpp
Executable file
@ -0,0 +1,579 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "common/logging/log.h"
|
||||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/k_event.h"
|
||||
#include "core/hle/kernel/k_shared_memory.h"
|
||||
#include "core/hle/service/set/system_settings_server.h"
|
||||
#include "core/hle/service/sm/sm.h"
|
||||
#include "hid_core/hid_result.h"
|
||||
#include "hid_core/resources/applet_resource.h"
|
||||
#include "hid_core/resources/shared_memory_format.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_driver.h"
|
||||
#include "hid_core/resources/touch_screen/touch_screen_resource.h"
|
||||
|
||||
namespace Service::HID {
|
||||
constexpr auto GestureUpdatePeriod = std::chrono::nanoseconds{4 * 1000 * 1000}; // (4ms, 1000Hz)
|
||||
|
||||
TouchResource::TouchResource(Core::System& system_) : system{system_} {
|
||||
m_set_sys = system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys");
|
||||
}
|
||||
|
||||
TouchResource::~TouchResource() {
|
||||
Finalize();
|
||||
};
|
||||
|
||||
Result TouchResource::ActivateTouch() {
|
||||
if (global_ref_counter == std::numeric_limits<s32>::max() - 1 ||
|
||||
touch_ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultTouchOverflow;
|
||||
}
|
||||
|
||||
if (global_ref_counter == 0) {
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
const auto result = touch_driver->StartTouchSensor();
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
is_initalized = true;
|
||||
system.CoreTiming().ScheduleLoopingEvent(GestureUpdatePeriod, GestureUpdatePeriod,
|
||||
timer_event);
|
||||
current_touch_state = {};
|
||||
ReadTouchInput();
|
||||
gesture_handler.SetTouchState(current_touch_state.states, current_touch_state.entry_count,
|
||||
0);
|
||||
}
|
||||
|
||||
Set::TouchScreenMode touch_mode{Set::TouchScreenMode::Standard};
|
||||
m_set_sys->GetTouchScreenMode(touch_mode);
|
||||
default_touch_screen_mode = static_cast<Core::HID::TouchScreenModeForNx>(touch_mode);
|
||||
|
||||
global_ref_counter++;
|
||||
touch_ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::ActivateTouch(u64 aruid) {
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
|
||||
auto* applet_data = applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
TouchAruidData& touch_data = aruid_data[aruid_index];
|
||||
|
||||
if (!applet_data->flag.is_assigned) {
|
||||
touch_data = {};
|
||||
continue;
|
||||
}
|
||||
|
||||
const u64 aruid_id = applet_data->aruid;
|
||||
if (touch_data.aruid != aruid_id) {
|
||||
touch_data = {};
|
||||
touch_data.aruid = aruid_id;
|
||||
}
|
||||
|
||||
if (aruid != aruid_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& touch_shared = applet_data->shared_memory_format->touch_screen;
|
||||
|
||||
if (touch_shared.touch_screen_lifo.buffer_count == 0) {
|
||||
StorePreviousTouchState(previous_touch_state, touch_data.finger_map,
|
||||
current_touch_state,
|
||||
applet_data->flag.enable_touchscreen.Value() != 0);
|
||||
touch_shared.touch_screen_lifo.WriteNextEntry(previous_touch_state);
|
||||
}
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::ActivateGesture() {
|
||||
if (global_ref_counter == std::numeric_limits<s32>::max() - 1 ||
|
||||
gesture_ref_counter == std::numeric_limits<s32>::max() - 1) {
|
||||
return ResultGestureOverflow;
|
||||
}
|
||||
|
||||
// Initialize first instance
|
||||
if (global_ref_counter == 0) {
|
||||
const auto result = touch_driver->StartTouchSensor();
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
is_initalized = true;
|
||||
system.CoreTiming().ScheduleLoopingEvent(GestureUpdatePeriod, GestureUpdatePeriod,
|
||||
timer_event);
|
||||
current_touch_state = {};
|
||||
ReadTouchInput();
|
||||
gesture_handler.SetTouchState(current_touch_state.states, current_touch_state.entry_count,
|
||||
0);
|
||||
}
|
||||
|
||||
global_ref_counter++;
|
||||
gesture_ref_counter++;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::ActivateGesture(u64 aruid, u32 basic_gesture_id) {
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
|
||||
auto* applet_data = applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
TouchAruidData& touch_data = aruid_data[aruid_index];
|
||||
|
||||
if (!applet_data->flag.is_assigned) {
|
||||
touch_data = {};
|
||||
continue;
|
||||
}
|
||||
|
||||
const u64 aruid_id = applet_data->aruid;
|
||||
if (touch_data.aruid != aruid_id) {
|
||||
touch_data = {};
|
||||
touch_data.aruid = aruid_id;
|
||||
}
|
||||
|
||||
if (aruid != aruid_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& gesture_shared = applet_data->shared_memory_format->gesture;
|
||||
if (touch_data.basic_gesture_id != basic_gesture_id) {
|
||||
gesture_shared.gesture_lifo.buffer_count = 0;
|
||||
}
|
||||
|
||||
if (gesture_shared.gesture_lifo.buffer_count == 0) {
|
||||
touch_data.basic_gesture_id = basic_gesture_id;
|
||||
|
||||
gesture_shared.gesture_lifo.WriteNextEntry(gesture_state);
|
||||
}
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::DeactivateTouch() {
|
||||
if (touch_ref_counter == 0 || global_ref_counter == 0) {
|
||||
return ResultTouchNotInitialized;
|
||||
}
|
||||
|
||||
global_ref_counter--;
|
||||
touch_ref_counter--;
|
||||
|
||||
if (touch_ref_counter + global_ref_counter != 0) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
return Finalize();
|
||||
}
|
||||
|
||||
Result TouchResource::DeactivateGesture() {
|
||||
if (gesture_ref_counter == 0 || global_ref_counter == 0) {
|
||||
return ResultGestureNotInitialized;
|
||||
}
|
||||
|
||||
global_ref_counter--;
|
||||
gesture_ref_counter--;
|
||||
|
||||
if (touch_ref_counter + global_ref_counter != 0) {
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
return Finalize();
|
||||
}
|
||||
|
||||
bool TouchResource::IsTouchActive() const {
|
||||
return touch_ref_counter != 0;
|
||||
}
|
||||
|
||||
bool TouchResource::IsGestureActive() const {
|
||||
return gesture_ref_counter != 0;
|
||||
}
|
||||
|
||||
void TouchResource::SetTouchDriver(std::shared_ptr<TouchDriver> driver) {
|
||||
touch_driver = driver;
|
||||
}
|
||||
|
||||
void TouchResource::SetAppletResource(std::shared_ptr<AppletResource> shared,
|
||||
std::recursive_mutex* mutex) {
|
||||
applet_resource = shared;
|
||||
shared_mutex = mutex;
|
||||
}
|
||||
|
||||
void TouchResource::SetInputEvent(Kernel::KEvent* event, std::mutex* mutex) {
|
||||
input_event = event;
|
||||
input_mutex = mutex;
|
||||
}
|
||||
|
||||
void TouchResource::SetHandheldConfig(std::shared_ptr<HandheldConfig> config) {
|
||||
handheld_config = config;
|
||||
}
|
||||
|
||||
void TouchResource::SetTimerEvent(std::shared_ptr<Core::Timing::EventType> event) {
|
||||
timer_event = event;
|
||||
}
|
||||
|
||||
Result TouchResource::SetTouchScreenAutoPilotState(const AutoPilotState& auto_pilot_state) {
|
||||
if (global_ref_counter == 0) {
|
||||
return ResultTouchNotInitialized;
|
||||
}
|
||||
|
||||
if (!is_auto_pilot_initialized) {
|
||||
is_auto_pilot_initialized = true;
|
||||
auto_pilot = {};
|
||||
}
|
||||
|
||||
TouchScreenState state = {
|
||||
.entry_count = static_cast<s32>(auto_pilot_state.count),
|
||||
.states = auto_pilot_state.state,
|
||||
};
|
||||
|
||||
SanitizeInput(state);
|
||||
|
||||
auto_pilot.count = state.entry_count;
|
||||
auto_pilot.state = state.states;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::UnsetTouchScreenAutoPilotState() {
|
||||
if (global_ref_counter == 0) {
|
||||
return ResultTouchNotInitialized;
|
||||
}
|
||||
|
||||
is_auto_pilot_initialized = false;
|
||||
auto_pilot = {};
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::RequestNextTouchInput() {
|
||||
if (global_ref_counter == 0) {
|
||||
return ResultTouchNotInitialized;
|
||||
}
|
||||
|
||||
if (handheld_config->is_handheld_hid_enabled) {
|
||||
const Result result = touch_driver->WaitForInput();
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
is_initalized = true;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::RequestNextDummyInput() {
|
||||
if (global_ref_counter == 0) {
|
||||
return ResultTouchNotInitialized;
|
||||
}
|
||||
|
||||
if (handheld_config->is_handheld_hid_enabled) {
|
||||
const Result result = touch_driver->WaitForDummyInput();
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
is_initalized = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::ProcessTouchScreenAutoTune() {
|
||||
touch_driver->ProcessTouchScreenAutoTune();
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void TouchResource::SetTouchScreenMagnification(f32 point1_x, f32 point1_y, f32 point2_x,
|
||||
f32 point2_y) {
|
||||
offset = {
|
||||
.x = point1_x,
|
||||
.y = point1_y,
|
||||
};
|
||||
magnification = {
|
||||
.x = point2_x,
|
||||
.y = point2_y,
|
||||
};
|
||||
}
|
||||
|
||||
Result TouchResource::SetTouchScreenResolution(u32 width, u32 height, u64 aruid) {
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
|
||||
const auto* applet_data = applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
TouchAruidData& data = aruid_data[aruid_index];
|
||||
|
||||
if (!applet_data->flag.is_assigned) {
|
||||
continue;
|
||||
}
|
||||
if (aruid != data.aruid) {
|
||||
continue;
|
||||
}
|
||||
data.resolution_width = static_cast<u16>(width);
|
||||
data.resolution_height = static_cast<u16>(height);
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::SetTouchScreenConfiguration(
|
||||
const Core::HID::TouchScreenConfigurationForNx& touch_configuration, u64 aruid) {
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
|
||||
const auto* applet_data = applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
TouchAruidData& data = aruid_data[aruid_index];
|
||||
|
||||
if (!applet_data->flag.is_assigned) {
|
||||
continue;
|
||||
}
|
||||
if (aruid != data.aruid) {
|
||||
continue;
|
||||
}
|
||||
data.finger_map.touch_mode = touch_configuration.mode;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::GetTouchScreenConfiguration(
|
||||
Core::HID::TouchScreenConfigurationForNx& out_touch_configuration, u64 aruid) const {
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
|
||||
const auto* applet_data = applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
const TouchAruidData& data = aruid_data[aruid_index];
|
||||
|
||||
if (!applet_data->flag.is_assigned) {
|
||||
continue;
|
||||
}
|
||||
if (aruid != data.aruid) {
|
||||
continue;
|
||||
}
|
||||
out_touch_configuration.mode = data.finger_map.touch_mode;
|
||||
}
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::SetTouchScreenDefaultConfiguration(
|
||||
const Core::HID::TouchScreenConfigurationForNx& touch_configuration) {
|
||||
default_touch_screen_mode = touch_configuration.mode;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::GetTouchScreenDefaultConfiguration(
|
||||
Core::HID::TouchScreenConfigurationForNx& out_touch_configuration) const {
|
||||
out_touch_configuration.mode = default_touch_screen_mode;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result TouchResource::Finalize() {
|
||||
is_auto_pilot_initialized = false;
|
||||
auto_pilot = {};
|
||||
system.CoreTiming().UnscheduleEvent(timer_event);
|
||||
|
||||
const auto result = touch_driver->StopTouchSensor();
|
||||
if (result.IsError()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
is_initalized = false;
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
void TouchResource::StorePreviousTouchState(TouchScreenState& out_previous_touch,
|
||||
TouchFingerMap& out_finger_map,
|
||||
const TouchScreenState& current_touch,
|
||||
bool is_touch_enabled) const {
|
||||
s32 finger_count{};
|
||||
|
||||
if (is_touch_enabled) {
|
||||
finger_count = current_touch.entry_count;
|
||||
if (finger_count < 1) {
|
||||
out_finger_map.finger_count = 0;
|
||||
out_finger_map.finger_ids = {};
|
||||
out_previous_touch.sampling_number = current_touch.sampling_number;
|
||||
out_previous_touch.entry_count = 0;
|
||||
out_previous_touch.states = {};
|
||||
return;
|
||||
}
|
||||
for (std::size_t i = 0; i < static_cast<u32>(finger_count); i++) {
|
||||
out_finger_map.finger_ids[i] = current_touch.states[i].finger;
|
||||
out_previous_touch.states[i] = current_touch.states[i];
|
||||
}
|
||||
out_finger_map.finger_count = finger_count;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_touch_enabled && out_finger_map.finger_count > 0 && current_touch.entry_count > 0) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Zero out unused entries
|
||||
for (std::size_t i = finger_count; i < MaxFingers; i++) {
|
||||
out_finger_map.finger_ids[i] = 0;
|
||||
out_previous_touch.states[i] = {};
|
||||
}
|
||||
|
||||
out_previous_touch.sampling_number = current_touch.sampling_number;
|
||||
out_previous_touch.entry_count = finger_count;
|
||||
}
|
||||
|
||||
void TouchResource::ReadTouchInput() {
|
||||
previous_touch_state = current_touch_state;
|
||||
|
||||
if (!is_initalized || !handheld_config->is_handheld_hid_enabled || !touch_driver->IsRunning()) {
|
||||
touch_driver->WaitForDummyInput();
|
||||
} else {
|
||||
touch_driver->WaitForInput();
|
||||
}
|
||||
|
||||
touch_driver->GetNextTouchState(current_touch_state);
|
||||
SanitizeInput(current_touch_state);
|
||||
current_touch_state.sampling_number = sample_number;
|
||||
sample_number++;
|
||||
|
||||
if (is_auto_pilot_initialized && current_touch_state.entry_count == 0) {
|
||||
const std::size_t finger_count = static_cast<std::size_t>(auto_pilot.count);
|
||||
current_touch_state.entry_count = static_cast<s32>(finger_count);
|
||||
for (std::size_t i = 0; i < finger_count; i++) {
|
||||
current_touch_state.states[i] = auto_pilot.state[i];
|
||||
}
|
||||
|
||||
std::size_t index = 0;
|
||||
for (std::size_t i = 0; i < finger_count; i++) {
|
||||
if (auto_pilot.state[i].attribute.end_touch) {
|
||||
continue;
|
||||
}
|
||||
auto_pilot.state[i].attribute.raw = 0;
|
||||
auto_pilot.state[index] = auto_pilot.state[i];
|
||||
index++;
|
||||
}
|
||||
|
||||
auto_pilot.count = index;
|
||||
for (std::size_t i = index; i < auto_pilot.state.size(); i++) {
|
||||
auto_pilot.state[i] = {};
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < static_cast<std::size_t>(current_touch_state.entry_count); i++) {
|
||||
auto& state = current_touch_state.states[i];
|
||||
state.position.x = static_cast<u32>((magnification.y * static_cast<f32>(state.position.x)) +
|
||||
(offset.x * static_cast<f32>(TouchSensorWidth)));
|
||||
state.position.y = static_cast<u32>((magnification.y * static_cast<f32>(state.position.y)) +
|
||||
(offset.x * static_cast<f32>(TouchSensorHeight)));
|
||||
state.diameter_x = static_cast<u32>(magnification.x * static_cast<f32>(state.diameter_x));
|
||||
state.diameter_y = static_cast<u32>(magnification.y * static_cast<f32>(state.diameter_y));
|
||||
}
|
||||
|
||||
std::size_t index = 0;
|
||||
for (std::size_t i = 0; i < static_cast<std::size_t>(current_touch_state.entry_count); i++) {
|
||||
const auto& old_state = current_touch_state.states[i];
|
||||
auto& state = current_touch_state.states[index];
|
||||
if ((TouchSensorWidth <= old_state.position.x) ||
|
||||
(TouchSensorHeight <= old_state.position.y)) {
|
||||
continue;
|
||||
}
|
||||
state = old_state;
|
||||
index++;
|
||||
}
|
||||
current_touch_state.entry_count = static_cast<s32>(index);
|
||||
|
||||
SanitizeInput(current_touch_state);
|
||||
|
||||
std::scoped_lock lock{*input_mutex};
|
||||
if (current_touch_state.entry_count == previous_touch_state.entry_count) {
|
||||
if (current_touch_state.entry_count < 1) {
|
||||
return;
|
||||
}
|
||||
bool has_moved = false;
|
||||
for (std::size_t i = 0; i < static_cast<std::size_t>(current_touch_state.entry_count);
|
||||
i++) {
|
||||
s32 delta_x = std::abs(static_cast<s32>(current_touch_state.states[i].position.x) -
|
||||
static_cast<s32>(previous_touch_state.states[i].position.x));
|
||||
s32 delta_y = std::abs(static_cast<s32>(current_touch_state.states[i].position.y) -
|
||||
static_cast<s32>(previous_touch_state.states[i].position.y));
|
||||
if (delta_x > 1 || delta_y > 1) {
|
||||
has_moved = true;
|
||||
}
|
||||
}
|
||||
if (!has_moved) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
input_event->Signal();
|
||||
}
|
||||
|
||||
void TouchResource::OnTouchUpdate(s64 timestamp) {
|
||||
if (global_ref_counter == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
ReadTouchInput();
|
||||
gesture_handler.SetTouchState(current_touch_state.states, current_touch_state.entry_count,
|
||||
timestamp);
|
||||
|
||||
std::scoped_lock lock{*shared_mutex};
|
||||
|
||||
for (std::size_t aruid_index = 0; aruid_index < AruidIndexMax; aruid_index++) {
|
||||
const auto* applet_data = applet_resource->GetAruidDataByIndex(aruid_index);
|
||||
TouchAruidData& data = aruid_data[aruid_index];
|
||||
|
||||
if (applet_data == nullptr || !applet_data->flag.is_assigned) {
|
||||
data = {};
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.aruid != applet_data->aruid) {
|
||||
data = {};
|
||||
data.aruid = applet_data->aruid;
|
||||
}
|
||||
|
||||
if (gesture_ref_counter != 0) {
|
||||
if (!applet_data->flag.enable_touchscreen) {
|
||||
gesture_state = {};
|
||||
}
|
||||
if (gesture_handler.NeedsUpdate()) {
|
||||
gesture_handler.UpdateGestureState(gesture_state, timestamp);
|
||||
auto& gesture_shared = applet_data->shared_memory_format->gesture;
|
||||
gesture_shared.gesture_lifo.WriteNextEntry(gesture_state);
|
||||
}
|
||||
}
|
||||
|
||||
if (touch_ref_counter != 0) {
|
||||
auto touch_mode = data.finger_map.touch_mode;
|
||||
if (touch_mode == Core::HID::TouchScreenModeForNx::UseSystemSetting) {
|
||||
touch_mode = default_touch_screen_mode;
|
||||
}
|
||||
|
||||
if (applet_resource->GetActiveAruid() == applet_data->aruid &&
|
||||
touch_mode != Core::HID::TouchScreenModeForNx::UseSystemSetting && is_initalized &&
|
||||
handheld_config->is_handheld_hid_enabled && touch_driver->IsRunning()) {
|
||||
touch_driver->SetTouchMode(touch_mode);
|
||||
}
|
||||
|
||||
auto& touch_shared = applet_data->shared_memory_format->touch_screen;
|
||||
StorePreviousTouchState(previous_touch_state, data.finger_map, current_touch_state,
|
||||
applet_data->flag.enable_touchscreen.As<bool>());
|
||||
touch_shared.touch_screen_lifo.WriteNextEntry(current_touch_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TouchResource::SanitizeInput(TouchScreenState& state) const {
|
||||
for (std::size_t i = 0; i < static_cast<std::size_t>(state.entry_count); i++) {
|
||||
auto& entry = state.states[i];
|
||||
entry.position.x =
|
||||
std::clamp(entry.position.x, TouchBorders, TouchSensorWidth - TouchBorders - 1);
|
||||
entry.position.y =
|
||||
std::clamp(entry.position.y, TouchBorders, TouchSensorHeight - TouchBorders - 1);
|
||||
entry.diameter_x = std::clamp(entry.diameter_x, 0u, TouchSensorWidth - MaxTouchDiameter);
|
||||
entry.diameter_y = std::clamp(entry.diameter_y, 0u, TouchSensorHeight - MaxTouchDiameter);
|
||||
entry.rotation_angle =
|
||||
std::clamp(entry.rotation_angle, -MaxRotationAngle, MaxRotationAngle);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Service::HID
|
126
src/hid_core/resources/touch_screen/touch_screen_resource.h
Executable file
126
src/hid_core/resources/touch_screen/touch_screen_resource.h
Executable file
@ -0,0 +1,126 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/point.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "hid_core/hid_types.h"
|
||||
#include "hid_core/resources/touch_screen/gesture_handler.h"
|
||||
#include "hid_core/resources/touch_screen/touch_types.h"
|
||||
|
||||
namespace Core {
|
||||
class System;
|
||||
}
|
||||
|
||||
namespace Core::Timing {
|
||||
struct EventType;
|
||||
}
|
||||
|
||||
namespace Kernel {
|
||||
class KEvent;
|
||||
} // namespace Kernel
|
||||
|
||||
namespace Service::Set {
|
||||
class ISystemSettingsServer;
|
||||
}
|
||||
|
||||
namespace Service::HID {
|
||||
class AppletResource;
|
||||
class TouchSharedMemoryManager;
|
||||
class TouchDriver;
|
||||
struct HandheldConfig;
|
||||
|
||||
class TouchResource {
|
||||
public:
|
||||
TouchResource(Core::System& system_);
|
||||
~TouchResource();
|
||||
|
||||
Result ActivateTouch();
|
||||
Result ActivateTouch(u64 aruid);
|
||||
|
||||
Result ActivateGesture();
|
||||
Result ActivateGesture(u64 aruid, u32 basic_gesture_id);
|
||||
|
||||
Result DeactivateTouch();
|
||||
Result DeactivateGesture();
|
||||
|
||||
bool IsTouchActive() const;
|
||||
bool IsGestureActive() const;
|
||||
|
||||
void SetTouchDriver(std::shared_ptr<TouchDriver> driver);
|
||||
void SetAppletResource(std::shared_ptr<AppletResource> shared, std::recursive_mutex* mutex);
|
||||
void SetInputEvent(Kernel::KEvent* event, std::mutex* mutex);
|
||||
void SetHandheldConfig(std::shared_ptr<HandheldConfig> config);
|
||||
void SetTimerEvent(std::shared_ptr<Core::Timing::EventType> event);
|
||||
|
||||
Result SetTouchScreenAutoPilotState(const AutoPilotState& auto_pilot_state);
|
||||
Result UnsetTouchScreenAutoPilotState();
|
||||
|
||||
Result RequestNextTouchInput();
|
||||
Result RequestNextDummyInput();
|
||||
|
||||
Result ProcessTouchScreenAutoTune();
|
||||
void SetTouchScreenMagnification(f32 point1_x, f32 point1_y, f32 point2_x, f32 point2_y);
|
||||
Result SetTouchScreenResolution(u32 width, u32 height, u64 aruid);
|
||||
|
||||
Result SetTouchScreenConfiguration(
|
||||
const Core::HID::TouchScreenConfigurationForNx& touch_configuration, u64 aruid);
|
||||
Result GetTouchScreenConfiguration(
|
||||
Core::HID::TouchScreenConfigurationForNx& out_touch_configuration, u64 aruid) const;
|
||||
|
||||
Result SetTouchScreenDefaultConfiguration(
|
||||
const Core::HID::TouchScreenConfigurationForNx& touch_configuration);
|
||||
Result GetTouchScreenDefaultConfiguration(
|
||||
Core::HID::TouchScreenConfigurationForNx& out_touch_configuration) const;
|
||||
|
||||
void OnTouchUpdate(s64 timestamp);
|
||||
|
||||
private:
|
||||
Result Finalize();
|
||||
|
||||
void StorePreviousTouchState(TouchScreenState& out_previous_touch,
|
||||
TouchFingerMap& out_finger_map,
|
||||
const TouchScreenState& current_touch,
|
||||
bool is_touch_enabled) const;
|
||||
void ReadTouchInput();
|
||||
|
||||
void SanitizeInput(TouchScreenState& state) const;
|
||||
|
||||
s32 global_ref_counter{};
|
||||
s32 gesture_ref_counter{};
|
||||
s32 touch_ref_counter{};
|
||||
bool is_initalized{};
|
||||
u64 sample_number{};
|
||||
|
||||
// External resources
|
||||
std::shared_ptr<Core::Timing::EventType> timer_event{nullptr};
|
||||
std::shared_ptr<TouchDriver> touch_driver{nullptr};
|
||||
std::shared_ptr<AppletResource> applet_resource{nullptr};
|
||||
std::recursive_mutex* shared_mutex{nullptr};
|
||||
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
|
||||
Kernel::KEvent* input_event{nullptr};
|
||||
std::mutex* input_mutex{nullptr};
|
||||
|
||||
// Internal state
|
||||
TouchScreenState current_touch_state{};
|
||||
TouchScreenState previous_touch_state{};
|
||||
GestureState gesture_state{};
|
||||
bool is_auto_pilot_initialized{};
|
||||
AutoPilotState auto_pilot{};
|
||||
GestureHandler gesture_handler{};
|
||||
std::array<TouchAruidData, 0x20> aruid_data{};
|
||||
Common::Point<f32> magnification{1.0f, 1.0f};
|
||||
Common::Point<f32> offset{0.0f, 0.0f};
|
||||
Core::HID::TouchScreenModeForNx default_touch_screen_mode{
|
||||
Core::HID::TouchScreenModeForNx::Finger};
|
||||
|
||||
Core::System& system;
|
||||
std::shared_ptr<Service::Set::ISystemSettingsServer> m_set_sys;
|
||||
};
|
||||
|
||||
} // namespace Service::HID
|
@ -13,8 +13,20 @@
|
||||
#include "hid_core/hid_types.h"
|
||||
|
||||
namespace Service::HID {
|
||||
static constexpr std::size_t MAX_FINGERS = 16;
|
||||
static constexpr size_t MAX_POINTS = 4;
|
||||
constexpr std::size_t MaxFingers = 16;
|
||||
constexpr std::size_t MaxPoints = 4;
|
||||
constexpr u32 TouchSensorWidth = 1280;
|
||||
constexpr u32 TouchSensorHeight = 720;
|
||||
constexpr s32 MaxRotationAngle = 270;
|
||||
constexpr u32 MaxTouchDiameter = 30;
|
||||
constexpr u32 TouchBorders = 15;
|
||||
|
||||
// HW is around 700, value is set to 400 to make it easier to trigger with mouse
|
||||
constexpr f32 SwipeThreshold = 400.0f; // Threshold in pixels/s
|
||||
constexpr f32 AngleThreshold = 0.015f; // Threshold in radians
|
||||
constexpr f32 PinchThreshold = 0.5f; // Threshold in pixels
|
||||
constexpr f32 PressDelay = 0.5f; // Time in seconds
|
||||
constexpr f32 DoubleTapDelay = 0.35f; // Time in seconds
|
||||
|
||||
// This is nn::hid::GestureType
|
||||
enum class GestureType : u32 {
|
||||
@ -28,6 +40,7 @@ enum class GestureType : u32 {
|
||||
Swipe, // Fast press movement and release of a single point
|
||||
Pinch, // All points moving away/closer to the midpoint
|
||||
Rotate, // All points rotating from the midpoint
|
||||
GestureTypeMax = Rotate,
|
||||
};
|
||||
|
||||
// This is nn::hid::GestureDirection
|
||||
@ -69,7 +82,7 @@ struct GestureState {
|
||||
static_assert(sizeof(GestureState) == 0x60, "GestureState is an invalid size");
|
||||
|
||||
struct GestureProperties {
|
||||
std::array<Common::Point<s32>, MAX_POINTS> points{};
|
||||
std::array<Common::Point<s32>, MaxPoints> points{};
|
||||
std::size_t active_points{};
|
||||
Common::Point<s32> mid_point{};
|
||||
s64 detection_count{};
|
||||
@ -78,13 +91,53 @@ struct GestureProperties {
|
||||
f32 angle{};
|
||||
};
|
||||
|
||||
// This is nn::hid::TouchState
|
||||
struct TouchState {
|
||||
u64 delta_time{};
|
||||
Core::HID::TouchAttribute attribute{};
|
||||
u32 finger{};
|
||||
Common::Point<u32> position{};
|
||||
u32 diameter_x{};
|
||||
u32 diameter_y{};
|
||||
s32 rotation_angle{};
|
||||
};
|
||||
static_assert(sizeof(TouchState) == 0x28, "Touchstate is an invalid size");
|
||||
|
||||
// This is nn::hid::TouchScreenState
|
||||
struct TouchScreenState {
|
||||
s64 sampling_number{};
|
||||
s32 entry_count{};
|
||||
INSERT_PADDING_BYTES(4); // Reserved
|
||||
std::array<Core::HID::TouchState, MAX_FINGERS> states{};
|
||||
std::array<TouchState, MaxFingers> states{};
|
||||
};
|
||||
static_assert(sizeof(TouchScreenState) == 0x290, "TouchScreenState is an invalid size");
|
||||
|
||||
struct TouchFingerMap {
|
||||
s32 finger_count{};
|
||||
Core::HID::TouchScreenModeForNx touch_mode;
|
||||
INSERT_PADDING_BYTES(3);
|
||||
std::array<u32, MaxFingers> finger_ids{};
|
||||
};
|
||||
static_assert(sizeof(TouchFingerMap) == 0x48, "TouchFingerMap is an invalid size");
|
||||
|
||||
struct TouchAruidData {
|
||||
u64 aruid;
|
||||
u32 basic_gesture_id;
|
||||
u64 used_1;
|
||||
u64 used_2;
|
||||
u64 used_3;
|
||||
u64 used_4;
|
||||
GestureType gesture_type;
|
||||
u16 resolution_width;
|
||||
u16 resolution_height;
|
||||
TouchFingerMap finger_map;
|
||||
};
|
||||
static_assert(sizeof(TouchAruidData) == 0x80, "TouchAruidData is an invalid size");
|
||||
|
||||
struct AutoPilotState {
|
||||
u64 count;
|
||||
std::array<TouchState, 16> state;
|
||||
};
|
||||
static_assert(sizeof(AutoPilotState) == 0x288, "AutoPilotState is an invalid size");
|
||||
|
||||
} // namespace Service::HID
|
||||
|
@ -28,7 +28,7 @@ void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& header = data->shared_memory_format->capture_button.header;
|
||||
auto& header = data->shared_memory_format->unique_pad.header;
|
||||
header.timestamp = core_timing.GetGlobalTimeNs().count();
|
||||
header.total_entry_count = 17;
|
||||
header.entry_count = 0;
|
||||
|
@ -302,7 +302,7 @@ target_link_options(video_core PRIVATE ${FFmpeg_LDFLAGS})
|
||||
|
||||
add_dependencies(video_core host_shaders)
|
||||
target_include_directories(video_core PRIVATE ${HOST_SHADERS_INCLUDE})
|
||||
target_link_libraries(video_core PRIVATE sirit Vulkan::Headers GPUOpen::VulkanMemoryAllocator)
|
||||
target_link_libraries(video_core PRIVATE sirit Vulkan::Headers Vulkan::UtilityHeaders GPUOpen::VulkanMemoryAllocator)
|
||||
|
||||
if (ENABLE_NSIGHT_AFTERMATH)
|
||||
if (NOT DEFINED ENV{NSIGHT_AFTERMATH_SDK})
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "core/core.h"
|
||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||
#include "video_core/renderer_vulkan/vk_swapchain.h"
|
||||
#include "video_core/vulkan_common/vk_enum_string_helper.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
@ -151,7 +152,7 @@ bool Swapchain::AcquireNextImage() {
|
||||
vk::Check(result);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR(Render_Vulkan, "vkAcquireNextImageKHR returned {}", vk::ToString(result));
|
||||
LOG_ERROR(Render_Vulkan, "vkAcquireNextImageKHR returned {}", string_VkResult(result));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -187,7 +188,7 @@ void Swapchain::Present(VkSemaphore render_semaphore) {
|
||||
vk::Check(result);
|
||||
break;
|
||||
default:
|
||||
LOG_CRITICAL(Render_Vulkan, "Failed to present with error {}", vk::ToString(result));
|
||||
LOG_CRITICAL(Render_Vulkan, "Failed to present with error {}", string_VkResult(result));
|
||||
break;
|
||||
}
|
||||
++frame_index;
|
||||
|
8
src/video_core/vulkan_common/vk_enum_string_helper.h
Executable file
8
src/video_core/vulkan_common/vk_enum_string_helper.h
Executable file
@ -0,0 +1,8 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "video_core/vulkan_common/vulkan.h"
|
||||
|
||||
#include <vulkan/vk_enum_string_helper.h>
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "video_core/vulkan_common/vk_enum_string_helper.h"
|
||||
#include "video_core/vulkan_common/vma.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
|
||||
@ -298,109 +299,7 @@ bool Load(VkInstance instance, InstanceDispatch& dld) noexcept {
|
||||
}
|
||||
|
||||
const char* Exception::what() const noexcept {
|
||||
return ToString(result);
|
||||
}
|
||||
|
||||
const char* ToString(VkResult result) noexcept {
|
||||
switch (result) {
|
||||
case VkResult::VK_SUCCESS:
|
||||
return "VK_SUCCESS";
|
||||
case VkResult::VK_NOT_READY:
|
||||
return "VK_NOT_READY";
|
||||
case VkResult::VK_TIMEOUT:
|
||||
return "VK_TIMEOUT";
|
||||
case VkResult::VK_EVENT_SET:
|
||||
return "VK_EVENT_SET";
|
||||
case VkResult::VK_EVENT_RESET:
|
||||
return "VK_EVENT_RESET";
|
||||
case VkResult::VK_INCOMPLETE:
|
||||
return "VK_INCOMPLETE";
|
||||
case VkResult::VK_ERROR_OUT_OF_HOST_MEMORY:
|
||||
return "VK_ERROR_OUT_OF_HOST_MEMORY";
|
||||
case VkResult::VK_ERROR_OUT_OF_DEVICE_MEMORY:
|
||||
return "VK_ERROR_OUT_OF_DEVICE_MEMORY";
|
||||
case VkResult::VK_ERROR_INITIALIZATION_FAILED:
|
||||
return "VK_ERROR_INITIALIZATION_FAILED";
|
||||
case VkResult::VK_ERROR_DEVICE_LOST:
|
||||
return "VK_ERROR_DEVICE_LOST";
|
||||
case VkResult::VK_ERROR_MEMORY_MAP_FAILED:
|
||||
return "VK_ERROR_MEMORY_MAP_FAILED";
|
||||
case VkResult::VK_ERROR_LAYER_NOT_PRESENT:
|
||||
return "VK_ERROR_LAYER_NOT_PRESENT";
|
||||
case VkResult::VK_ERROR_EXTENSION_NOT_PRESENT:
|
||||
return "VK_ERROR_EXTENSION_NOT_PRESENT";
|
||||
case VkResult::VK_ERROR_FEATURE_NOT_PRESENT:
|
||||
return "VK_ERROR_FEATURE_NOT_PRESENT";
|
||||
case VkResult::VK_ERROR_INCOMPATIBLE_DRIVER:
|
||||
return "VK_ERROR_INCOMPATIBLE_DRIVER";
|
||||
case VkResult::VK_ERROR_TOO_MANY_OBJECTS:
|
||||
return "VK_ERROR_TOO_MANY_OBJECTS";
|
||||
case VkResult::VK_ERROR_FORMAT_NOT_SUPPORTED:
|
||||
return "VK_ERROR_FORMAT_NOT_SUPPORTED";
|
||||
case VkResult::VK_ERROR_FRAGMENTED_POOL:
|
||||
return "VK_ERROR_FRAGMENTED_POOL";
|
||||
case VkResult::VK_ERROR_OUT_OF_POOL_MEMORY:
|
||||
return "VK_ERROR_OUT_OF_POOL_MEMORY";
|
||||
case VkResult::VK_ERROR_INVALID_EXTERNAL_HANDLE:
|
||||
return "VK_ERROR_INVALID_EXTERNAL_HANDLE";
|
||||
case VkResult::VK_ERROR_SURFACE_LOST_KHR:
|
||||
return "VK_ERROR_SURFACE_LOST_KHR";
|
||||
case VkResult::VK_ERROR_NATIVE_WINDOW_IN_USE_KHR:
|
||||
return "VK_ERROR_NATIVE_WINDOW_IN_USE_KHR";
|
||||
case VkResult::VK_SUBOPTIMAL_KHR:
|
||||
return "VK_SUBOPTIMAL_KHR";
|
||||
case VkResult::VK_ERROR_OUT_OF_DATE_KHR:
|
||||
return "VK_ERROR_OUT_OF_DATE_KHR";
|
||||
case VkResult::VK_ERROR_INCOMPATIBLE_DISPLAY_KHR:
|
||||
return "VK_ERROR_INCOMPATIBLE_DISPLAY_KHR";
|
||||
case VkResult::VK_ERROR_VALIDATION_FAILED_EXT:
|
||||
return "VK_ERROR_VALIDATION_FAILED_EXT";
|
||||
case VkResult::VK_ERROR_INVALID_SHADER_NV:
|
||||
return "VK_ERROR_INVALID_SHADER_NV";
|
||||
case VkResult::VK_ERROR_IMAGE_USAGE_NOT_SUPPORTED_KHR:
|
||||
return "VK_ERROR_IMAGE_USAGE_NOT_SUPPORTED_KHR";
|
||||
case VkResult::VK_ERROR_VIDEO_PICTURE_LAYOUT_NOT_SUPPORTED_KHR:
|
||||
return "VK_ERROR_VIDEO_PICTURE_LAYOUT_NOT_SUPPORTED_KHR";
|
||||
case VkResult::VK_ERROR_VIDEO_PROFILE_OPERATION_NOT_SUPPORTED_KHR:
|
||||
return "VK_ERROR_VIDEO_PROFILE_OPERATION_NOT_SUPPORTED_KHR";
|
||||
case VkResult::VK_ERROR_VIDEO_PROFILE_FORMAT_NOT_SUPPORTED_KHR:
|
||||
return "VK_ERROR_VIDEO_PROFILE_FORMAT_NOT_SUPPORTED_KHR";
|
||||
case VkResult::VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR:
|
||||
return "VK_ERROR_VIDEO_PROFILE_CODEC_NOT_SUPPORTED_KHR";
|
||||
case VkResult::VK_ERROR_VIDEO_STD_VERSION_NOT_SUPPORTED_KHR:
|
||||
return "VK_ERROR_VIDEO_STD_VERSION_NOT_SUPPORTED_KHR";
|
||||
case VkResult::VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT:
|
||||
return "VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT";
|
||||
case VkResult::VK_ERROR_FRAGMENTATION_EXT:
|
||||
return "VK_ERROR_FRAGMENTATION_EXT";
|
||||
case VkResult::VK_ERROR_NOT_PERMITTED_EXT:
|
||||
return "VK_ERROR_NOT_PERMITTED_EXT";
|
||||
case VkResult::VK_ERROR_INVALID_DEVICE_ADDRESS_EXT:
|
||||
return "VK_ERROR_INVALID_DEVICE_ADDRESS_EXT";
|
||||
case VkResult::VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT:
|
||||
return "VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT";
|
||||
case VkResult::VK_ERROR_UNKNOWN:
|
||||
return "VK_ERROR_UNKNOWN";
|
||||
case VkResult::VK_THREAD_IDLE_KHR:
|
||||
return "VK_THREAD_IDLE_KHR";
|
||||
case VkResult::VK_THREAD_DONE_KHR:
|
||||
return "VK_THREAD_DONE_KHR";
|
||||
case VkResult::VK_OPERATION_DEFERRED_KHR:
|
||||
return "VK_OPERATION_DEFERRED_KHR";
|
||||
case VkResult::VK_OPERATION_NOT_DEFERRED_KHR:
|
||||
return "VK_OPERATION_NOT_DEFERRED_KHR";
|
||||
case VkResult::VK_ERROR_INVALID_VIDEO_STD_PARAMETERS_KHR:
|
||||
return "VK_ERROR_INVALID_VIDEO_STD_PARAMETERS_KHR";
|
||||
case VkResult::VK_PIPELINE_COMPILE_REQUIRED_EXT:
|
||||
return "VK_PIPELINE_COMPILE_REQUIRED_EXT";
|
||||
case VkResult::VK_RESULT_MAX_ENUM:
|
||||
return "VK_RESULT_MAX_ENUM";
|
||||
case VkResult::VK_ERROR_COMPRESSION_EXHAUSTED_EXT:
|
||||
return "VK_ERROR_COMPRESSION_EXHAUSTED_EXT";
|
||||
case VkResult::VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT:
|
||||
return "VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT";
|
||||
}
|
||||
return "Unknown";
|
||||
return string_VkResult(result);
|
||||
}
|
||||
|
||||
void Destroy(VkInstance instance, const InstanceDispatch& dld) noexcept {
|
||||
@ -1067,7 +966,7 @@ u32 AvailableVersion(const InstanceDispatch& dld) noexcept {
|
||||
u32 version;
|
||||
if (const VkResult result = vkEnumerateInstanceVersion(&version); result != VK_SUCCESS) {
|
||||
LOG_ERROR(Render_Vulkan, "vkEnumerateInstanceVersion returned {}, assuming Vulkan 1.1",
|
||||
ToString(result));
|
||||
string_VkResult(result));
|
||||
return VK_API_VERSION_1_1;
|
||||
}
|
||||
return version;
|
||||
|
@ -125,9 +125,6 @@ private:
|
||||
VkResult result;
|
||||
};
|
||||
|
||||
/// Converts a VkResult enum into a rodata string
|
||||
const char* ToString(VkResult) noexcept;
|
||||
|
||||
/// Throws a Vulkan exception if result is not success.
|
||||
inline void Check(VkResult result) {
|
||||
if (result != VK_SUCCESS) {
|
||||
|
Loading…
Reference in New Issue
Block a user