early-access version 4015

This commit is contained in:
pineappleEA 2023-12-11 02:14:53 +01:00
parent 442a7d9120
commit 96d280b4f5
30 changed files with 341 additions and 135 deletions

View file

@ -1,7 +1,7 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 4014. This is the source code for early-access 4015.
## Legal Notice ## Legal Notice

View file

@ -291,9 +291,6 @@ Core::SystemResultStatus EmulationSession::InitializeEmulation(const std::string
// Initialize filesystem. // Initialize filesystem.
ConfigureFilesystemProvider(filepath); ConfigureFilesystemProvider(filepath);
// Initialize account manager
m_profile_manager = std::make_unique<Service::Account::ProfileManager>();
// Load the ROM. // Load the ROM.
m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath); m_load_result = m_system.Load(EmulationSession::GetInstance().Window(), filepath);
if (m_load_result != Core::SystemResultStatus::Success) { if (m_load_result != Core::SystemResultStatus::Success) {
@ -736,8 +733,8 @@ void Java_org_yuzu_yuzu_1emu_NativeLibrary_initializeEmptyUserDirectory(JNIEnv*
auto vfs_nand_dir = EmulationSession::GetInstance().System().GetFilesystem()->OpenDirectory( auto vfs_nand_dir = EmulationSession::GetInstance().System().GetFilesystem()->OpenDirectory(
Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read); Common::FS::PathToUTF8String(nand_dir), FileSys::Mode::Read);
Service::Account::ProfileManager manager; const auto user_id = EmulationSession::GetInstance().System().GetProfileManager().GetUser(
const auto user_id = manager.GetUser(static_cast<std::size_t>(0)); static_cast<std::size_t>(0));
ASSERT(user_id); ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(

View file

@ -73,7 +73,6 @@ private:
std::atomic<bool> m_is_running = false; std::atomic<bool> m_is_running = false;
std::atomic<bool> m_is_paused = false; std::atomic<bool> m_is_paused = false;
SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{}; SoftwareKeyboard::AndroidKeyboard* m_software_keyboard{};
std::unique_ptr<Service::Account::ProfileManager> m_profile_manager;
std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider; std::unique_ptr<FileSys::ManualContentProvider> m_manual_provider;
// GPU driver parameters // GPU driver parameters

View file

@ -36,6 +36,7 @@
#include "core/hle/kernel/k_scheduler.h" #include "core/hle/kernel/k_scheduler.h"
#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/physical_core.h" #include "core/hle/kernel/physical_core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/am/applets/applets.h" #include "core/hle/service/am/applets/applets.h"
#include "core/hle/service/apm/apm_controller.h" #include "core/hle/service/apm/apm_controller.h"
#include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/filesystem.h"
@ -130,8 +131,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
struct System::Impl { struct System::Impl {
explicit Impl(System& system) explicit Impl(System& system)
: kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{}, : kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{},
cpu_manager{system}, reporter{system}, applet_manager{system}, time_manager{system}, cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{},
gpu_dirty_memory_write_manager{} { time_manager{system}, gpu_dirty_memory_write_manager{} {
memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager); memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager);
} }
@ -532,6 +533,7 @@ struct System::Impl {
/// Service State /// Service State
Service::Glue::ARPManager arp_manager; Service::Glue::ARPManager arp_manager;
Service::Account::ProfileManager profile_manager;
Service::Time::TimeManager time_manager; Service::Time::TimeManager time_manager;
/// Service manager /// Service manager
@ -921,6 +923,14 @@ const Service::APM::Controller& System::GetAPMController() const {
return impl->apm_controller; return impl->apm_controller;
} }
Service::Account::ProfileManager& System::GetProfileManager() {
return impl->profile_manager;
}
const Service::Account::ProfileManager& System::GetProfileManager() const {
return impl->profile_manager;
}
Service::Time::TimeManager& System::GetTimeManager() { Service::Time::TimeManager& System::GetTimeManager() {
return impl->time_manager; return impl->time_manager;
} }

View file

@ -45,6 +45,10 @@ class Memory;
namespace Service { namespace Service {
namespace Account {
class ProfileManager;
} // namespace Account
namespace AM::Applets { namespace AM::Applets {
struct AppletFrontendSet; struct AppletFrontendSet;
class AppletManager; class AppletManager;
@ -383,6 +387,9 @@ public:
[[nodiscard]] Service::APM::Controller& GetAPMController(); [[nodiscard]] Service::APM::Controller& GetAPMController();
[[nodiscard]] const Service::APM::Controller& GetAPMController() const; [[nodiscard]] const Service::APM::Controller& GetAPMController() const;
[[nodiscard]] Service::Account::ProfileManager& GetProfileManager();
[[nodiscard]] const Service::Account::ProfileManager& GetProfileManager() const;
[[nodiscard]] Service::Time::TimeManager& GetTimeManager(); [[nodiscard]] Service::Time::TimeManager& GetTimeManager();
[[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const; [[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const;

View file

@ -112,6 +112,19 @@ void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
} }
} }
void AppletResource::FreeAppletResourceId(u64 aruid) {
u64 index = GetIndexFromAruid(aruid);
if (index >= AruidIndexMax) {
return;
}
auto& aruid_data = data[index];
if (aruid_data.flag.is_assigned) {
aruid_data.shared_memory_handle = nullptr;
aruid_data.flag.is_assigned.Assign(false);
}
}
u64 AppletResource::GetActiveAruid() { u64 AppletResource::GetActiveAruid() {
return active_aruid; return active_aruid;
} }
@ -196,4 +209,80 @@ void AppletResource::EnablePalmaBoostMode(u64 aruid, bool is_enabled) {
data[index].flag.enable_palma_boost_mode.Assign(is_enabled); data[index].flag.enable_palma_boost_mode.Assign(is_enabled);
} }
Result AppletResource::RegisterCoreAppletResource() {
if (ref_counter == std::numeric_limits<s32>::max() - 1) {
return ResultAppletResourceOverflow;
}
if (ref_counter == 0) {
const u64 index = GetIndexFromAruid(0);
if (index < AruidIndexMax) {
return ResultAruidAlreadyRegistered;
}
std::size_t data_index = AruidIndexMax;
for (std::size_t i = 0; i < AruidIndexMax; i++) {
if (!data[i].flag.is_initialized) {
data_index = i;
break;
}
}
if (data_index == AruidIndexMax) {
return ResultAruidNoAvailableEntries;
}
AruidData& aruid_data = data[data_index];
aruid_data.aruid = 0;
aruid_data.flag.is_initialized.Assign(true);
aruid_data.flag.enable_pad_input.Assign(true);
aruid_data.flag.enable_six_axis_sensor.Assign(true);
aruid_data.flag.bit_18.Assign(true);
aruid_data.flag.enable_touchscreen.Assign(true);
data_index = AruidIndexMax;
for (std::size_t i = 0; i < AruidIndexMax; i++) {
if (registration_list.flag[i] == RegistrationStatus::Initialized) {
if (registration_list.aruid[i] != 0) {
continue;
}
data_index = i;
break;
}
if (registration_list.flag[i] == RegistrationStatus::None) {
data_index = i;
break;
}
}
Result result = ResultSuccess;
if (data_index == AruidIndexMax) {
result = CreateAppletResource(0);
} else {
registration_list.flag[data_index] = RegistrationStatus::Initialized;
registration_list.aruid[data_index] = 0;
}
if (result.IsError()) {
UnregisterAppletResourceUserId(0);
return result;
}
}
ref_counter++;
return ResultSuccess;
}
Result AppletResource::UnregisterCoreAppletResource() {
if (ref_counter == 0) {
return ResultAppletResourceNotInitialized;
}
if (--ref_counter == 0) {
UnregisterAppletResourceUserId(0);
}
return ResultSuccess;
}
} // namespace Service::HID } // namespace Service::HID

View file

@ -28,6 +28,8 @@ public:
Result RegisterAppletResourceUserId(u64 aruid, bool enable_input); Result RegisterAppletResourceUserId(u64 aruid, bool enable_input);
void UnregisterAppletResourceUserId(u64 aruid); void UnregisterAppletResourceUserId(u64 aruid);
void FreeAppletResourceId(u64 aruid);
u64 GetActiveAruid(); u64 GetActiveAruid();
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
@ -42,6 +44,9 @@ public:
void SetIsPalmaConnectable(u64 aruid, bool is_connectable); void SetIsPalmaConnectable(u64 aruid, bool is_connectable);
void EnablePalmaBoostMode(u64 aruid, bool is_enabled); void EnablePalmaBoostMode(u64 aruid, bool is_enabled);
Result RegisterCoreAppletResource();
Result UnregisterCoreAppletResource();
private: private:
static constexpr std::size_t AruidIndexMax = 0x20; static constexpr std::size_t AruidIndexMax = 0x20;
@ -81,6 +86,7 @@ private:
u64 active_aruid{}; u64 active_aruid{};
AruidRegisterList registration_list{}; AruidRegisterList registration_list{};
std::array<AruidData, AruidIndexMax> data{}; std::array<AruidData, AruidIndexMax> data{};
s32 ref_counter{};
Core::System& system; Core::System& system;
}; };

View file

@ -20,6 +20,9 @@ constexpr Result InvalidNpadId{ErrorModule::HID, 709};
constexpr Result NpadNotConnected{ErrorModule::HID, 710}; constexpr Result NpadNotConnected{ErrorModule::HID, 710};
constexpr Result InvalidArraySize{ErrorModule::HID, 715}; constexpr Result InvalidArraySize{ErrorModule::HID, 715};
constexpr Result ResultAppletResourceOverflow{ErrorModule::HID, 1041};
constexpr Result ResultAppletResourceNotInitialized{ErrorModule::HID, 1042};
constexpr Result ResultSharedMemoryNotInitialized{ErrorModule::HID, 1043};
constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044}; constexpr Result ResultAruidNoAvailableEntries{ErrorModule::HID, 1044};
constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046}; constexpr Result ResultAruidAlreadyRegistered{ErrorModule::HID, 1046};
constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047}; constexpr Result ResultAruidNotRegistered{ErrorModule::HID, 1047};

View file

@ -222,16 +222,14 @@ void IHidServer::CreateAppletResource(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
const auto applet_resource_user_id{rp.Pop<u64>()}; const auto applet_resource_user_id{rp.Pop<u64>()};
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id); Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id);
if (result.IsSuccess()) {
result = GetResourceManager()->GetNpad()->Activate(applet_resource_user_id); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}",
} applet_resource_user_id, result.raw);
IPC::ResponseBuilder rb{ctx, 2, 0, 1}; IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(result); rb.Push(result);
rb.PushIpcInterface<IAppletResource>(system, resource_manager); rb.PushIpcInterface<IAppletResource>(system, resource_manager, applet_resource_user_id);
} }
void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { void IHidServer::ActivateDebugPad(HLERequestContext& ctx) {

View file

@ -146,10 +146,36 @@ std::shared_ptr<UniquePad> ResourceManager::GetUniquePad() const {
} }
Result ResourceManager::CreateAppletResource(u64 aruid) { Result ResourceManager::CreateAppletResource(u64 aruid) {
if (aruid == 0) {
const auto result = RegisterCoreAppletResource();
if (result.IsError()) {
return result;
}
return GetNpad()->Activate();
}
const auto result = CreateAppletResourceImpl(aruid);
if (result.IsError()) {
return result;
}
return GetNpad()->Activate(aruid);
}
Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
std::scoped_lock lock{shared_mutex}; std::scoped_lock lock{shared_mutex};
return applet_resource->CreateAppletResource(aruid); return applet_resource->CreateAppletResource(aruid);
} }
Result ResourceManager::RegisterCoreAppletResource() {
std::scoped_lock lock{shared_mutex};
return applet_resource->RegisterCoreAppletResource();
}
Result ResourceManager::UnregisterCoreAppletResource() {
std::scoped_lock lock{shared_mutex};
return applet_resource->UnregisterCoreAppletResource();
}
Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) { Result ResourceManager::RegisterAppletResourceUserId(u64 aruid, bool bool_value) {
std::scoped_lock lock{shared_mutex}; std::scoped_lock lock{shared_mutex};
return applet_resource->RegisterAppletResourceUserId(aruid, bool_value); return applet_resource->RegisterAppletResourceUserId(aruid, bool_value);
@ -165,6 +191,11 @@ Result ResourceManager::GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle
return applet_resource->GetSharedMemoryHandle(out_handle, aruid); return applet_resource->GetSharedMemoryHandle(out_handle, aruid);
} }
void ResourceManager::FreeAppletResourceId(u64 aruid) {
std::scoped_lock lock{shared_mutex};
applet_resource->FreeAppletResourceId(aruid);
}
void ResourceManager::EnableInput(u64 aruid, bool is_enabled) { void ResourceManager::EnableInput(u64 aruid, bool is_enabled) {
std::scoped_lock lock{shared_mutex}; std::scoped_lock lock{shared_mutex};
applet_resource->EnableInput(aruid, is_enabled); applet_resource->EnableInput(aruid, is_enabled);
@ -219,8 +250,10 @@ void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanose
console_six_axis->OnUpdate(core_timing); console_six_axis->OnUpdate(core_timing);
} }
IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource) IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
: ServiceFramework{system_, "IAppletResource"}, resource_manager{resource} { u64 applet_resource_user_id)
: ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id},
resource_manager{resource} {
static const FunctionInfo functions[] = { static const FunctionInfo functions[] = {
{0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"}, {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"},
}; };
@ -274,14 +307,14 @@ IAppletResource::~IAppletResource() {
system.CoreTiming().UnscheduleEvent(default_update_event, 0); system.CoreTiming().UnscheduleEvent(default_update_event, 0);
system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event, 0); system.CoreTiming().UnscheduleEvent(mouse_keyboard_update_event, 0);
system.CoreTiming().UnscheduleEvent(motion_update_event, 0); system.CoreTiming().UnscheduleEvent(motion_update_event, 0);
resource_manager->FreeAppletResourceId(aruid);
} }
void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) {
LOG_DEBUG(Service_HID, "called");
Kernel::KSharedMemory* handle; Kernel::KSharedMemory* handle;
const u64 applet_resource_user_id = resource_manager->GetAppletResource()->GetActiveAruid(); const auto result = resource_manager->GetSharedMemoryHandle(&handle, aruid);
const auto result = resource_manager->GetSharedMemoryHandle(&handle, applet_resource_user_id);
LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw);
IPC::ResponseBuilder rb{ctx, 2, 1}; IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(result); rb.Push(result);

View file

@ -66,10 +66,13 @@ public:
Result CreateAppletResource(u64 aruid); Result CreateAppletResource(u64 aruid);
Result RegisterCoreAppletResource();
Result UnregisterCoreAppletResource();
Result RegisterAppletResourceUserId(u64 aruid, bool bool_value); Result RegisterAppletResourceUserId(u64 aruid, bool bool_value);
void UnregisterAppletResourceUserId(u64 aruid); void UnregisterAppletResourceUserId(u64 aruid);
Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid); Result GetSharedMemoryHandle(Kernel::KSharedMemory** out_handle, u64 aruid);
void FreeAppletResourceId(u64 aruid);
void EnableInput(u64 aruid, bool is_enabled); void EnableInput(u64 aruid, bool is_enabled);
void EnableSixAxisSensor(u64 aruid, bool is_enabled); void EnableSixAxisSensor(u64 aruid, bool is_enabled);
@ -82,6 +85,8 @@ public:
void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late);
private: private:
Result CreateAppletResourceImpl(u64 aruid);
bool is_initialized{false}; bool is_initialized{false};
mutable std::mutex shared_mutex; mutable std::mutex shared_mutex;
@ -121,7 +126,8 @@ private:
class IAppletResource final : public ServiceFramework<IAppletResource> { class IAppletResource final : public ServiceFramework<IAppletResource> {
public: public:
explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource); explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
u64 applet_resource_user_id);
~IAppletResource() override; ~IAppletResource() override;
private: private:
@ -132,6 +138,7 @@ private:
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_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> motion_update_event;
u64 aruid;
std::shared_ptr<ResourceManager> resource_manager; std::shared_ptr<ResourceManager> resource_manager;
}; };

View file

@ -90,7 +90,7 @@ Status BufferQueueConsumer::AcquireBuffer(BufferItem* out_buffer,
LOG_DEBUG(Service_Nvnflinger, "acquiring slot={}", slot); LOG_DEBUG(Service_Nvnflinger, "acquiring slot={}", slot);
if (core->StillTracking(*out_buffer)) { if (core->StillTracking(*front)) {
slots[slot].acquire_called = true; slots[slot].acquire_called = true;
slots[slot].buffer_state = BufferState::Acquired; slots[slot].buffer_state = BufferState::Acquired;
slots[slot].fence = Fence::NoFence(); slots[slot].fence = Fence::NoFence();

View file

@ -176,17 +176,37 @@ void Nvnflinger::CreateLayerAtId(VI::Display& display, u64 layer_id) {
display.CreateLayer(layer_id, buffer_id, nvdrv->container); display.CreateLayer(layer_id, buffer_id, nvdrv->container);
} }
void Nvnflinger::OpenLayer(u64 layer_id) {
const auto lock_guard = Lock();
for (auto& display : displays) {
if (auto* layer = display.FindLayer(layer_id); layer) {
layer->Open();
}
}
}
void Nvnflinger::CloseLayer(u64 layer_id) { void Nvnflinger::CloseLayer(u64 layer_id) {
const auto lock_guard = Lock(); const auto lock_guard = Lock();
for (auto& display : displays) { for (auto& display : displays) {
display.CloseLayer(layer_id); if (auto* layer = display.FindLayer(layer_id); layer) {
layer->Close();
}
}
}
void Nvnflinger::DestroyLayer(u64 layer_id) {
const auto lock_guard = Lock();
for (auto& display : displays) {
display.DestroyLayer(layer_id);
} }
} }
std::optional<u32> Nvnflinger::FindBufferQueueId(u64 display_id, u64 layer_id) { std::optional<u32> Nvnflinger::FindBufferQueueId(u64 display_id, u64 layer_id) {
const auto lock_guard = Lock(); const auto lock_guard = Lock();
const auto* const layer = FindOrCreateLayer(display_id, layer_id); const auto* const layer = FindLayer(display_id, layer_id);
if (layer == nullptr) { if (layer == nullptr) {
return std::nullopt; return std::nullopt;
@ -240,24 +260,6 @@ VI::Layer* Nvnflinger::FindLayer(u64 display_id, u64 layer_id) {
return display->FindLayer(layer_id); return display->FindLayer(layer_id);
} }
VI::Layer* Nvnflinger::FindOrCreateLayer(u64 display_id, u64 layer_id) {
auto* const display = FindDisplay(display_id);
if (display == nullptr) {
return nullptr;
}
auto* layer = display->FindLayer(layer_id);
if (layer == nullptr) {
LOG_DEBUG(Service_Nvnflinger, "Layer at id {} not found. Trying to create it.", layer_id);
CreateLayerAtId(*display, layer_id);
return display->FindLayer(layer_id);
}
return layer;
}
void Nvnflinger::Compose() { void Nvnflinger::Compose() {
for (auto& display : displays) { for (auto& display : displays) {
// Trigger vsync for this display at the end of drawing // Trigger vsync for this display at the end of drawing

View file

@ -73,9 +73,15 @@ public:
/// If an invalid display ID is specified, then an empty optional is returned. /// If an invalid display ID is specified, then an empty optional is returned.
[[nodiscard]] std::optional<u64> CreateLayer(u64 display_id); [[nodiscard]] std::optional<u64> CreateLayer(u64 display_id);
/// Opens a layer on all displays for the given layer ID.
void OpenLayer(u64 layer_id);
/// Closes a layer on all displays for the given layer ID. /// Closes a layer on all displays for the given layer ID.
void CloseLayer(u64 layer_id); void CloseLayer(u64 layer_id);
/// Destroys the given layer ID.
void DestroyLayer(u64 layer_id);
/// Finds the buffer queue ID of the specified layer in the specified display. /// Finds the buffer queue ID of the specified layer in the specified display.
/// ///
/// If an invalid display ID or layer ID is provided, then an empty optional is returned. /// If an invalid display ID or layer ID is provided, then an empty optional is returned.
@ -117,11 +123,6 @@ private:
/// Finds the layer identified by the specified ID in the desired display. /// Finds the layer identified by the specified ID in the desired display.
[[nodiscard]] VI::Layer* FindLayer(u64 display_id, u64 layer_id); [[nodiscard]] VI::Layer* FindLayer(u64 display_id, u64 layer_id);
/// Finds the layer identified by the specified ID in the desired display,
/// or creates the layer if it is not found.
/// To be used when the system expects the specified ID to already exist.
[[nodiscard]] VI::Layer* FindOrCreateLayer(u64 display_id, u64 layer_id);
/// Creates a layer with the specified layer ID in the desired display. /// Creates a layer with the specified layer ID in the desired display.
void CreateLayerAtId(VI::Display& display, u64 layer_id); void CreateLayerAtId(VI::Display& display, u64 layer_id);

View file

@ -121,7 +121,7 @@ void SM::Initialize(HLERequestContext& ctx) {
rb.Push(ResultSuccess); rb.Push(ResultSuccess);
} }
void SM::GetService(HLERequestContext& ctx) { void SM::GetServiceCmif(HLERequestContext& ctx) {
Kernel::KClientSession* client_session{}; Kernel::KClientSession* client_session{};
auto result = GetServiceImpl(&client_session, ctx); auto result = GetServiceImpl(&client_session, ctx);
if (ctx.GetIsDeferred()) { if (ctx.GetIsDeferred()) {
@ -196,13 +196,28 @@ Result SM::GetServiceImpl(Kernel::KClientSession** out_client_session, HLEReques
return ResultSuccess; return ResultSuccess;
} }
void SM::RegisterService(HLERequestContext& ctx) { void SM::RegisterServiceCmif(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx}; IPC::RequestParser rp{ctx};
std::string name(PopServiceName(rp)); std::string name(PopServiceName(rp));
const auto is_light = static_cast<bool>(rp.PopRaw<u32>()); const auto is_light = static_cast<bool>(rp.PopRaw<u32>());
const auto max_session_count = rp.PopRaw<u32>(); const auto max_session_count = rp.PopRaw<u32>();
this->RegisterServiceImpl(ctx, name, max_session_count, is_light);
}
void SM::RegisterServiceTipc(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
std::string name(PopServiceName(rp));
const auto max_session_count = rp.PopRaw<u32>();
const auto is_light = static_cast<bool>(rp.PopRaw<u32>());
this->RegisterServiceImpl(ctx, name, max_session_count, is_light);
}
void SM::RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_session_count,
bool is_light) {
LOG_DEBUG(Service_SM, "called with name={}, max_session_count={}, is_light={}", name, LOG_DEBUG(Service_SM, "called with name={}, max_session_count={}, is_light={}", name,
max_session_count, is_light); max_session_count, is_light);
@ -238,15 +253,15 @@ SM::SM(ServiceManager& service_manager_, Core::System& system_)
service_manager{service_manager_}, kernel{system_.Kernel()} { service_manager{service_manager_}, kernel{system_.Kernel()} {
RegisterHandlers({ RegisterHandlers({
{0, &SM::Initialize, "Initialize"}, {0, &SM::Initialize, "Initialize"},
{1, &SM::GetService, "GetService"}, {1, &SM::GetServiceCmif, "GetService"},
{2, &SM::RegisterService, "RegisterService"}, {2, &SM::RegisterServiceCmif, "RegisterService"},
{3, &SM::UnregisterService, "UnregisterService"}, {3, &SM::UnregisterService, "UnregisterService"},
{4, nullptr, "DetachClient"}, {4, nullptr, "DetachClient"},
}); });
RegisterHandlersTipc({ RegisterHandlersTipc({
{0, &SM::Initialize, "Initialize"}, {0, &SM::Initialize, "Initialize"},
{1, &SM::GetServiceTipc, "GetService"}, {1, &SM::GetServiceTipc, "GetService"},
{2, &SM::RegisterService, "RegisterService"}, {2, &SM::RegisterServiceTipc, "RegisterService"},
{3, &SM::UnregisterService, "UnregisterService"}, {3, &SM::UnregisterService, "UnregisterService"},
{4, nullptr, "DetachClient"}, {4, nullptr, "DetachClient"},
}); });

View file

@ -37,12 +37,15 @@ public:
private: private:
void Initialize(HLERequestContext& ctx); void Initialize(HLERequestContext& ctx);
void GetService(HLERequestContext& ctx); void GetServiceCmif(HLERequestContext& ctx);
void GetServiceTipc(HLERequestContext& ctx); void GetServiceTipc(HLERequestContext& ctx);
void RegisterService(HLERequestContext& ctx); void RegisterServiceCmif(HLERequestContext& ctx);
void RegisterServiceTipc(HLERequestContext& ctx);
void UnregisterService(HLERequestContext& ctx); void UnregisterService(HLERequestContext& ctx);
Result GetServiceImpl(Kernel::KClientSession** out_client_session, HLERequestContext& ctx); Result GetServiceImpl(Kernel::KClientSession** out_client_session, HLERequestContext& ctx);
void RegisterServiceImpl(HLERequestContext& ctx, std::string name, u32 max_session_count,
bool is_light);
ServiceManager& service_manager; ServiceManager& service_manager;
Kernel::KernelCore& kernel; Kernel::KernelCore& kernel;

View file

@ -51,11 +51,24 @@ Display::~Display() {
} }
Layer& Display::GetLayer(std::size_t index) { Layer& Display::GetLayer(std::size_t index) {
return *layers.at(index); size_t i = 0;
for (auto& layer : layers) {
if (!layer->IsOpen()) {
continue;
}
if (i == index) {
return *layer;
}
i++;
}
UNREACHABLE();
} }
const Layer& Display::GetLayer(std::size_t index) const { size_t Display::GetNumLayers() const {
return *layers.at(index); return std::ranges::count_if(layers, [](auto& l) { return l->IsOpen(); });
} }
Result Display::GetVSyncEvent(Kernel::KReadableEvent** out_vsync_event) { Result Display::GetVSyncEvent(Kernel::KReadableEvent** out_vsync_event) {
@ -92,7 +105,11 @@ void Display::CreateLayer(u64 layer_id, u32 binder_id,
hos_binder_driver_server.RegisterProducer(std::move(producer)); hos_binder_driver_server.RegisterProducer(std::move(producer));
} }
void Display::CloseLayer(u64 layer_id) { void Display::DestroyLayer(u64 layer_id) {
if (auto* layer = this->FindLayer(layer_id); layer != nullptr) {
layer->GetConsumer().Abandon();
}
std::erase_if(layers, std::erase_if(layers,
[layer_id](const auto& layer) { return layer->GetLayerId() == layer_id; }); [layer_id](const auto& layer) { return layer->GetLayerId() == layer_id; });
} }

View file

@ -72,12 +72,7 @@ public:
/// Gets a layer for this display based off an index. /// Gets a layer for this display based off an index.
Layer& GetLayer(std::size_t index); Layer& GetLayer(std::size_t index);
/// Gets a layer for this display based off an index. std::size_t GetNumLayers() const;
const Layer& GetLayer(std::size_t index) const;
std::size_t GetNumLayers() const {
return layers.size();
}
/** /**
* Gets the internal vsync event. * Gets the internal vsync event.
@ -100,11 +95,11 @@ public:
/// ///
void CreateLayer(u64 layer_id, u32 binder_id, Service::Nvidia::NvCore::Container& core); void CreateLayer(u64 layer_id, u32 binder_id, Service::Nvidia::NvCore::Container& core);
/// Closes and removes a layer from this display with the given ID. /// Removes a layer from this display with the given ID.
/// ///
/// @param layer_id The ID assigned to the layer to close. /// @param layer_id The ID assigned to the layer to destroy.
/// ///
void CloseLayer(u64 layer_id); void DestroyLayer(u64 layer_id);
/// Resets the display for a new connection. /// Resets the display for a new connection.
void Reset() { void Reset() {

View file

@ -8,8 +8,8 @@ namespace Service::VI {
Layer::Layer(u64 layer_id_, u32 binder_id_, android::BufferQueueCore& core_, Layer::Layer(u64 layer_id_, u32 binder_id_, android::BufferQueueCore& core_,
android::BufferQueueProducer& binder_, android::BufferQueueProducer& binder_,
std::shared_ptr<android::BufferItemConsumer>&& consumer_) std::shared_ptr<android::BufferItemConsumer>&& consumer_)
: layer_id{layer_id_}, binder_id{binder_id_}, core{core_}, binder{binder_}, consumer{std::move( : layer_id{layer_id_}, binder_id{binder_id_}, core{core_}, binder{binder_},
consumer_)} {} consumer{std::move(consumer_)}, open{false} {}
Layer::~Layer() = default; Layer::~Layer() = default;

View file

@ -71,12 +71,25 @@ public:
return core; return core;
} }
bool IsOpen() const {
return open;
}
void Close() {
open = false;
}
void Open() {
open = true;
}
private: private:
const u64 layer_id; const u64 layer_id;
const u32 binder_id; const u32 binder_id;
android::BufferQueueCore& core; android::BufferQueueCore& core;
android::BufferQueueProducer& binder; android::BufferQueueProducer& binder;
std::shared_ptr<android::BufferItemConsumer> consumer; std::shared_ptr<android::BufferItemConsumer> consumer;
bool open;
}; };
} // namespace Service::VI } // namespace Service::VI

View file

@ -719,6 +719,8 @@ private:
return; return;
} }
nv_flinger.OpenLayer(layer_id);
android::OutputParcel parcel; android::OutputParcel parcel;
parcel.WriteInterface(NativeWindow{*buffer_queue_id}); parcel.WriteInterface(NativeWindow{*buffer_queue_id});
@ -783,6 +785,7 @@ private:
const u64 layer_id = rp.Pop<u64>(); const u64 layer_id = rp.Pop<u64>();
LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}", layer_id); LOG_WARNING(Service_VI, "(STUBBED) called. layer_id=0x{:016X}", layer_id);
nv_flinger.DestroyLayer(layer_id);
IPC::ResponseBuilder rb{ctx, 2}; IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess); rb.Push(ResultSuccess);

View file

@ -14,6 +14,8 @@
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "core/constants.h" #include "core/constants.h"
#include "core/core.h"
#include "core/hle/service/acc/profile_manager.h"
#include "yuzu/applets/qt_profile_select.h" #include "yuzu/applets/qt_profile_select.h"
#include "yuzu/main.h" #include "yuzu/main.h"
#include "yuzu/util/controller_navigation.h" #include "yuzu/util/controller_navigation.h"
@ -47,9 +49,9 @@ QPixmap GetIcon(Common::UUID uuid) {
} // Anonymous namespace } // Anonymous namespace
QtProfileSelectionDialog::QtProfileSelectionDialog( QtProfileSelectionDialog::QtProfileSelectionDialog(
Core::HID::HIDCore& hid_core, QWidget* parent, Core::System& system, QWidget* parent,
const Core::Frontend::ProfileSelectParameters& parameters) const Core::Frontend::ProfileSelectParameters& parameters)
: QDialog(parent), profile_manager(std::make_unique<Service::Account::ProfileManager>()) { : QDialog(parent), profile_manager{system.GetProfileManager()} {
outer_layout = new QVBoxLayout; outer_layout = new QVBoxLayout;
instruction_label = new QLabel(); instruction_label = new QLabel();
@ -68,7 +70,7 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(
tree_view = new QTreeView; tree_view = new QTreeView;
item_model = new QStandardItemModel(tree_view); item_model = new QStandardItemModel(tree_view);
tree_view->setModel(item_model); tree_view->setModel(item_model);
controller_navigation = new ControllerNavigation(hid_core, this); controller_navigation = new ControllerNavigation(system.HIDCore(), this);
tree_view->setAlternatingRowColors(true); tree_view->setAlternatingRowColors(true);
tree_view->setSelectionMode(QHeaderView::SingleSelection); tree_view->setSelectionMode(QHeaderView::SingleSelection);
@ -106,10 +108,10 @@ QtProfileSelectionDialog::QtProfileSelectionDialog(
SelectUser(tree_view->currentIndex()); SelectUser(tree_view->currentIndex());
}); });
const auto& profiles = profile_manager->GetAllUsers(); const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) { for (const auto& user : profiles) {
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!profile_manager->GetProfileBase(user, profile)) if (!profile_manager.GetProfileBase(user, profile))
continue; continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer( const auto username = Common::StringFromFixedZeroTerminatedBuffer(
@ -134,7 +136,7 @@ QtProfileSelectionDialog::~QtProfileSelectionDialog() {
int QtProfileSelectionDialog::exec() { int QtProfileSelectionDialog::exec() {
// Skip profile selection when there's only one. // Skip profile selection when there's only one.
if (profile_manager->GetUserCount() == 1) { if (profile_manager.GetUserCount() == 1) {
user_index = 0; user_index = 0;
return QDialog::Accepted; return QDialog::Accepted;
} }

View file

@ -7,7 +7,6 @@
#include <QDialog> #include <QDialog>
#include <QList> #include <QList>
#include "core/frontend/applets/profile_select.h" #include "core/frontend/applets/profile_select.h"
#include "core/hle/service/acc/profile_manager.h"
class ControllerNavigation; class ControllerNavigation;
class GMainWindow; class GMainWindow;
@ -20,15 +19,19 @@ class QStandardItemModel;
class QTreeView; class QTreeView;
class QVBoxLayout; class QVBoxLayout;
namespace Core::HID { namespace Core {
class HIDCore; class System;
} // namespace Core::HID }
namespace Service::Account {
class ProfileManager;
}
class QtProfileSelectionDialog final : public QDialog { class QtProfileSelectionDialog final : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit QtProfileSelectionDialog(Core::HID::HIDCore& hid_core, QWidget* parent, explicit QtProfileSelectionDialog(Core::System& system, QWidget* parent,
const Core::Frontend::ProfileSelectParameters& parameters); const Core::Frontend::ProfileSelectParameters& parameters);
~QtProfileSelectionDialog() override; ~QtProfileSelectionDialog() override;
@ -58,7 +61,7 @@ private:
QScrollArea* scroll_area; QScrollArea* scroll_area;
QDialogButtonBox* buttons; QDialogButtonBox* buttons;
std::unique_ptr<Service::Account::ProfileManager> profile_manager; Service::Account::ProfileManager& profile_manager;
ControllerNavigation* controller_navigation = nullptr; ControllerNavigation* controller_navigation = nullptr;
}; };

View file

@ -76,9 +76,9 @@ QString GetProfileUsernameFromUser(QWidget* parent, const QString& description_t
} }
} // Anonymous namespace } // Anonymous namespace
ConfigureProfileManager::ConfigureProfileManager(const Core::System& system_, QWidget* parent) ConfigureProfileManager::ConfigureProfileManager(Core::System& system_, QWidget* parent)
: QWidget(parent), ui{std::make_unique<Ui::ConfigureProfileManager>()}, : QWidget(parent), ui{std::make_unique<Ui::ConfigureProfileManager>()},
profile_manager(std::make_unique<Service::Account::ProfileManager>()), system{system_} { profile_manager{system_.GetProfileManager()}, system{system_} {
ui->setupUi(this); ui->setupUi(this);
tree_view = new QTreeView; tree_view = new QTreeView;
@ -149,10 +149,10 @@ void ConfigureProfileManager::SetConfiguration() {
} }
void ConfigureProfileManager::PopulateUserList() { void ConfigureProfileManager::PopulateUserList() {
const auto& profiles = profile_manager->GetAllUsers(); const auto& profiles = profile_manager.GetAllUsers();
for (const auto& user : profiles) { for (const auto& user : profiles) {
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!profile_manager->GetProfileBase(user, profile)) if (!profile_manager.GetProfileBase(user, profile))
continue; continue;
const auto username = Common::StringFromFixedZeroTerminatedBuffer( const auto username = Common::StringFromFixedZeroTerminatedBuffer(
@ -167,11 +167,11 @@ void ConfigureProfileManager::PopulateUserList() {
} }
void ConfigureProfileManager::UpdateCurrentUser() { void ConfigureProfileManager::UpdateCurrentUser() {
ui->pm_add->setEnabled(profile_manager->GetUserCount() < Service::Account::MAX_USERS); ui->pm_add->setEnabled(profile_manager.GetUserCount() < Service::Account::MAX_USERS);
const auto& current_user = profile_manager->GetUser(Settings::values.current_user.GetValue()); const auto& current_user = profile_manager.GetUser(Settings::values.current_user.GetValue());
ASSERT(current_user); ASSERT(current_user);
const auto username = GetAccountUsername(*profile_manager, *current_user); const auto username = GetAccountUsername(profile_manager, *current_user);
scene->clear(); scene->clear();
scene->addPixmap( scene->addPixmap(
@ -187,11 +187,11 @@ void ConfigureProfileManager::ApplyConfiguration() {
void ConfigureProfileManager::SelectUser(const QModelIndex& index) { void ConfigureProfileManager::SelectUser(const QModelIndex& index) {
Settings::values.current_user = Settings::values.current_user =
std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager->GetUserCount() - 1)); std::clamp<s32>(index.row(), 0, static_cast<s32>(profile_manager.GetUserCount() - 1));
UpdateCurrentUser(); UpdateCurrentUser();
ui->pm_remove->setEnabled(profile_manager->GetUserCount() >= 2); ui->pm_remove->setEnabled(profile_manager.GetUserCount() >= 2);
ui->pm_rename->setEnabled(true); ui->pm_rename->setEnabled(true);
ui->pm_set_image->setEnabled(true); ui->pm_set_image->setEnabled(true);
} }
@ -204,18 +204,18 @@ void ConfigureProfileManager::AddUser() {
} }
const auto uuid = Common::UUID::MakeRandom(); const auto uuid = Common::UUID::MakeRandom();
profile_manager->CreateNewUser(uuid, username.toStdString()); profile_manager.CreateNewUser(uuid, username.toStdString());
item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)});
} }
void ConfigureProfileManager::RenameUser() { void ConfigureProfileManager::RenameUser() {
const auto user = tree_view->currentIndex().row(); const auto user = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(user); const auto uuid = profile_manager.GetUser(user);
ASSERT(uuid); ASSERT(uuid);
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!profile_manager->GetProfileBase(*uuid, profile)) if (!profile_manager.GetProfileBase(*uuid, profile))
return; return;
const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:")); const auto new_username = GetProfileUsernameFromUser(this, tr("Enter a new username:"));
@ -227,7 +227,7 @@ void ConfigureProfileManager::RenameUser() {
std::fill(profile.username.begin(), profile.username.end(), '\0'); std::fill(profile.username.begin(), profile.username.end(), '\0');
std::copy(username_std.begin(), username_std.end(), profile.username.begin()); std::copy(username_std.begin(), username_std.end(), profile.username.begin());
profile_manager->SetProfileBase(*uuid, profile); profile_manager.SetProfileBase(*uuid, profile);
item_model->setItem( item_model->setItem(
user, 0, user, 0,
@ -238,9 +238,9 @@ void ConfigureProfileManager::RenameUser() {
void ConfigureProfileManager::ConfirmDeleteUser() { void ConfigureProfileManager::ConfirmDeleteUser() {
const auto index = tree_view->currentIndex().row(); const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(index); const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid); ASSERT(uuid);
const auto username = GetAccountUsername(*profile_manager, *uuid); const auto username = GetAccountUsername(profile_manager, *uuid);
confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); }); confirm_dialog->SetInfo(username, *uuid, [this, uuid]() { DeleteUser(*uuid); });
confirm_dialog->show(); confirm_dialog->show();
@ -252,7 +252,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
} }
UpdateCurrentUser(); UpdateCurrentUser();
if (!profile_manager->RemoveUser(uuid)) { if (!profile_manager.RemoveUser(uuid)) {
return; return;
} }
@ -265,7 +265,7 @@ void ConfigureProfileManager::DeleteUser(const Common::UUID& uuid) {
void ConfigureProfileManager::SetUserImage() { void ConfigureProfileManager::SetUserImage() {
const auto index = tree_view->currentIndex().row(); const auto index = tree_view->currentIndex().row();
const auto uuid = profile_manager->GetUser(index); const auto uuid = profile_manager.GetUser(index);
ASSERT(uuid); ASSERT(uuid);
const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(), const auto file = QFileDialog::getOpenFileName(this, tr("Select User Image"), QString(),
@ -317,7 +317,7 @@ void ConfigureProfileManager::SetUserImage() {
} }
} }
const auto username = GetAccountUsername(*profile_manager, *uuid); const auto username = GetAccountUsername(profile_manager, *uuid);
item_model->setItem(index, 0, item_model->setItem(index, 0,
new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)}); new QStandardItem{GetIcon(*uuid), FormatUserEntryText(username, *uuid)});
UpdateCurrentUser(); UpdateCurrentUser();

View file

@ -52,7 +52,7 @@ class ConfigureProfileManager : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit ConfigureProfileManager(const Core::System& system_, QWidget* parent = nullptr); explicit ConfigureProfileManager(Core::System& system_, QWidget* parent = nullptr);
~ConfigureProfileManager() override; ~ConfigureProfileManager() override;
void ApplyConfiguration(); void ApplyConfiguration();
@ -85,7 +85,6 @@ private:
std::unique_ptr<Ui::ConfigureProfileManager> ui; std::unique_ptr<Ui::ConfigureProfileManager> ui;
bool enabled = false; bool enabled = false;
std::unique_ptr<Service::Account::ProfileManager> profile_manager; Service::Account::ProfileManager& profile_manager;
const Core::System& system; const Core::System& system;
}; };

View file

@ -346,7 +346,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue());
discord_rpc->Update(); discord_rpc->Update();
play_time_manager = std::make_unique<PlayTime::PlayTimeManager>(); play_time_manager = std::make_unique<PlayTime::PlayTimeManager>(system->GetProfileManager());
system->GetRoomNetwork().Init(); system->GetRoomNetwork().Init();
@ -526,8 +526,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk
continue; continue;
} }
const Service::Account::ProfileManager manager; if (!system->GetProfileManager().UserExistsIndex(selected_user)) {
if (!manager.UserExistsIndex(selected_user)) {
LOG_ERROR(Frontend, "Selected user doesn't exist"); LOG_ERROR(Frontend, "Selected user doesn't exist");
continue; continue;
} }
@ -691,7 +690,7 @@ void GMainWindow::ControllerSelectorRequestExit() {
void GMainWindow::ProfileSelectorSelectProfile( void GMainWindow::ProfileSelectorSelectProfile(
const Core::Frontend::ProfileSelectParameters& parameters) { const Core::Frontend::ProfileSelectParameters& parameters) {
profile_select_applet = new QtProfileSelectionDialog(system->HIDCore(), this, parameters); profile_select_applet = new QtProfileSelectionDialog(*system, this, parameters);
SCOPE_EXIT({ SCOPE_EXIT({
profile_select_applet->deleteLater(); profile_select_applet->deleteLater();
profile_select_applet = nullptr; profile_select_applet = nullptr;
@ -706,8 +705,8 @@ void GMainWindow::ProfileSelectorSelectProfile(
return; return;
} }
const Service::Account::ProfileManager manager; const auto uuid = system->GetProfileManager().GetUser(
const auto uuid = manager.GetUser(static_cast<std::size_t>(profile_select_applet->GetIndex())); static_cast<std::size_t>(profile_select_applet->GetIndex()));
if (!uuid.has_value()) { if (!uuid.has_value()) {
emit ProfileSelectorFinishedSelection(std::nullopt); emit ProfileSelectorFinishedSelection(std::nullopt);
return; return;
@ -1856,7 +1855,7 @@ bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t p
bool GMainWindow::SelectAndSetCurrentUser( bool GMainWindow::SelectAndSetCurrentUser(
const Core::Frontend::ProfileSelectParameters& parameters) { const Core::Frontend::ProfileSelectParameters& parameters) {
QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters); QtProfileSelectionDialog dialog(*system, this, parameters);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
@ -2271,7 +2270,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
.display_options = {}, .display_options = {},
.purpose = Service::AM::Applets::UserSelectionPurpose::General, .purpose = Service::AM::Applets::UserSelectionPurpose::General,
}; };
QtProfileSelectionDialog dialog(system->HIDCore(), this, parameters); QtProfileSelectionDialog dialog(*system, this, parameters);
dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint |
Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
@ -2288,8 +2287,8 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
return; return;
} }
Service::Account::ProfileManager manager; const auto user_id =
const auto user_id = manager.GetUser(static_cast<std::size_t>(index)); system->GetProfileManager().GetUser(static_cast<std::size_t>(index));
ASSERT(user_id); ASSERT(user_id);
const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath(

View file

@ -27,9 +27,9 @@
Lobby::Lobby(QWidget* parent, QStandardItemModel* list, Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session, Core::System& system_) std::shared_ptr<Core::AnnounceMultiplayerSession> session, Core::System& system_)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(std::make_unique<Ui::Lobby>()), announce_multiplayer_session(session), ui(std::make_unique<Ui::Lobby>()),
profile_manager(std::make_unique<Service::Account::ProfileManager>()), system{system_}, announce_multiplayer_session(session), system{system_}, room_network{
room_network{system.GetRoomNetwork()} { system.GetRoomNetwork()} {
ui->setupUi(this); ui->setupUi(this);
// setup the watcher for background connections // setup the watcher for background connections
@ -299,14 +299,15 @@ void Lobby::OnRefreshLobby() {
} }
std::string Lobby::GetProfileUsername() { std::string Lobby::GetProfileUsername() {
const auto& current_user = profile_manager->GetUser(Settings::values.current_user.GetValue()); const auto& current_user =
system.GetProfileManager().GetUser(Settings::values.current_user.GetValue());
Service::Account::ProfileBase profile{}; Service::Account::ProfileBase profile{};
if (!current_user.has_value()) { if (!current_user.has_value()) {
return ""; return "";
} }
if (!profile_manager->GetProfileBase(*current_user, profile)) { if (!system.GetProfileManager().GetProfileBase(*current_user, profile)) {
return ""; return "";
} }

View file

@ -24,10 +24,6 @@ namespace Core {
class System; class System;
} }
namespace Service::Account {
class ProfileManager;
}
/** /**
* Listing of all public games pulled from services. The lobby should be simple enough for users to * Listing of all public games pulled from services. The lobby should be simple enough for users to
* find the game they want to play, and join it. * find the game they want to play, and join it.
@ -103,7 +99,6 @@ private:
QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher; QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
std::unique_ptr<Service::Account::ProfileManager> profile_manager;
QFutureWatcher<void>* watcher; QFutureWatcher<void>* watcher;
Validation validation; Validation validation;
Core::System& system; Core::System& system;

View file

@ -20,8 +20,8 @@ struct PlayTimeElement {
PlayTime play_time; PlayTime play_time;
}; };
std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() { std::optional<std::filesystem::path> GetCurrentUserPlayTimePath(
const Service::Account::ProfileManager manager; const Service::Account::ProfileManager& manager) {
const auto uuid = manager.GetUser(static_cast<s32>(Settings::values.current_user)); const auto uuid = manager.GetUser(static_cast<s32>(Settings::values.current_user));
if (!uuid.has_value()) { if (!uuid.has_value()) {
return std::nullopt; return std::nullopt;
@ -30,8 +30,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
uuid->RawString().append(".bin"); uuid->RawString().append(".bin");
} }
[[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db) { [[nodiscard]] bool ReadPlayTimeFile(PlayTimeDatabase& out_play_time_db,
const auto filename = GetCurrentUserPlayTimePath(); const Service::Account::ProfileManager& manager) {
const auto filename = GetCurrentUserPlayTimePath(manager);
if (!filename.has_value()) { if (!filename.has_value()) {
LOG_ERROR(Frontend, "Failed to get current user path"); LOG_ERROR(Frontend, "Failed to get current user path");
@ -66,8 +67,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
return true; return true;
} }
[[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db) { [[nodiscard]] bool WritePlayTimeFile(const PlayTimeDatabase& play_time_db,
const auto filename = GetCurrentUserPlayTimePath(); const Service::Account::ProfileManager& manager) {
const auto filename = GetCurrentUserPlayTimePath(manager);
if (!filename.has_value()) { if (!filename.has_value()) {
LOG_ERROR(Frontend, "Failed to get current user path"); LOG_ERROR(Frontend, "Failed to get current user path");
@ -96,8 +98,9 @@ std::optional<std::filesystem::path> GetCurrentUserPlayTimePath() {
} // namespace } // namespace
PlayTimeManager::PlayTimeManager() { PlayTimeManager::PlayTimeManager(Service::Account::ProfileManager& profile_manager)
if (!ReadPlayTimeFile(database)) { : manager{profile_manager} {
if (!ReadPlayTimeFile(database, manager)) {
LOG_ERROR(Frontend, "Failed to read play time database! Resetting to default."); LOG_ERROR(Frontend, "Failed to read play time database! Resetting to default.");
} }
} }
@ -142,7 +145,7 @@ void PlayTimeManager::AutoTimestamp(std::stop_token stop_token) {
} }
void PlayTimeManager::Save() { void PlayTimeManager::Save() {
if (!WritePlayTimeFile(database)) { if (!WritePlayTimeFile(database, manager)) {
LOG_ERROR(Frontend, "Failed to update play time database!"); LOG_ERROR(Frontend, "Failed to update play time database!");
} }
} }

View file

@ -11,6 +11,10 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/polyfill_thread.h" #include "common/polyfill_thread.h"
namespace Service::Account {
class ProfileManager;
}
namespace PlayTime { namespace PlayTime {
using ProgramId = u64; using ProgramId = u64;
@ -19,7 +23,7 @@ using PlayTimeDatabase = std::map<ProgramId, PlayTime>;
class PlayTimeManager { class PlayTimeManager {
public: public:
explicit PlayTimeManager(); explicit PlayTimeManager(Service::Account::ProfileManager& profile_manager);
~PlayTimeManager(); ~PlayTimeManager();
YUZU_NON_COPYABLE(PlayTimeManager); YUZU_NON_COPYABLE(PlayTimeManager);
@ -32,11 +36,13 @@ public:
void Stop(); void Stop();
private: private:
void AutoTimestamp(std::stop_token stop_token);
void Save();
PlayTimeDatabase database; PlayTimeDatabase database;
u64 running_program_id; u64 running_program_id;
std::jthread play_time_thread; std::jthread play_time_thread;
void AutoTimestamp(std::stop_token stop_token); Service::Account::ProfileManager& manager;
void Save();
}; };
QString ReadablePlayTime(qulonglong time_seconds); QString ReadablePlayTime(qulonglong time_seconds);