diff options
Diffstat (limited to 'src/core/hle/service/am')
30 files changed, 302 insertions, 331 deletions
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 9dc710ba9..8c4e14f08 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -8,13 +8,13 @@ namespace Service::AM { -void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) { +void LoopProcess(Core::System& system) { auto server_manager = std::make_unique<ServerManager>(system); - server_manager->RegisterNamedService( - "appletAE", std::make_shared<IAllSystemAppletProxiesService>(system, nvnflinger)); - server_manager->RegisterNamedService( - "appletOE", std::make_shared<IApplicationProxyService>(system, nvnflinger)); + server_manager->RegisterNamedService("appletAE", + std::make_shared<IAllSystemAppletProxiesService>(system)); + server_manager->RegisterNamedService("appletOE", + std::make_shared<IApplicationProxyService>(system)); ServerManager::RunServer(std::move(server_manager)); } diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 4a2d797bd..1afe253ae 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -7,12 +7,8 @@ namespace Core { class System; } -namespace Service::Nvnflinger { -class Nvnflinger; -} - namespace Service::AM { -void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system); +void LoopProcess(Core::System& system); } // namespace Service::AM diff --git a/src/core/hle/service/am/applet.h b/src/core/hle/service/am/applet.h index 4f34d4811..ad602153e 100644 --- a/src/core/hle/service/am/applet.h +++ b/src/core/hle/service/am/applet.h @@ -14,10 +14,9 @@ #include "core/hle/service/am/am_types.h" #include "core/hle/service/am/applet_message_queue.h" +#include "core/hle/service/am/display_layer_manager.h" #include "core/hle/service/am/hid_registration.h" -#include "core/hle/service/am/managed_layer_holder.h" #include "core/hle/service/am/process.h" -#include "core/hle/service/am/system_buffer_manager.h" namespace Service::AM { @@ -54,8 +53,7 @@ struct Applet { HidRegistration hid_registration; // vi state - SystemBufferManager system_buffer_manager{}; - ManagedLayerHolder managed_layer_holder{}; + DisplayLayerManager display_layer_manager{}; // Applet common functions Result terminate_result{}; diff --git a/src/core/hle/service/am/applet_data_broker.cpp b/src/core/hle/service/am/applet_data_broker.cpp index 4d58c4db5..9057244a9 100644 --- a/src/core/hle/service/am/applet_data_broker.cpp +++ b/src/core/hle/service/am/applet_data_broker.cpp @@ -24,11 +24,11 @@ void AppletStorageChannel::Push(std::shared_ptr<IStorage> storage) { Result AppletStorageChannel::Pop(std::shared_ptr<IStorage>* out_storage) { std::scoped_lock lk{m_lock}; - SCOPE_EXIT({ + SCOPE_EXIT { if (m_data.empty()) { m_event.Clear(); } - }); + }; R_UNLESS(!m_data.empty(), AM::ResultNoDataInChannel); diff --git a/src/core/hle/service/am/display_layer_manager.cpp b/src/core/hle/service/am/display_layer_manager.cpp new file mode 100644 index 000000000..85ff6fb88 --- /dev/null +++ b/src/core/hle/service/am/display_layer_manager.cpp @@ -0,0 +1,151 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core.h" +#include "core/hle/service/am/display_layer_manager.h" +#include "core/hle/service/sm/sm.h" +#include "core/hle/service/vi/application_display_service.h" +#include "core/hle/service/vi/container.h" +#include "core/hle/service/vi/manager_display_service.h" +#include "core/hle/service/vi/manager_root_service.h" +#include "core/hle/service/vi/shared_buffer_manager.h" +#include "core/hle/service/vi/vi_results.h" +#include "core/hle/service/vi/vi_types.h" + +namespace Service::AM { + +DisplayLayerManager::DisplayLayerManager() = default; +DisplayLayerManager::~DisplayLayerManager() { + this->Finalize(); +} + +void DisplayLayerManager::Initialize(Core::System& system, Kernel::KProcess* process, + AppletId applet_id, LibraryAppletMode mode) { + R_ASSERT(system.ServiceManager() + .GetService<VI::IManagerRootService>("vi:m", true) + ->GetDisplayService(&m_display_service, VI::Policy::Compositor)); + R_ASSERT(m_display_service->GetManagerDisplayService(&m_manager_display_service)); + + m_process = process; + m_system_shared_buffer_id = 0; + m_system_shared_layer_id = 0; + m_applet_id = applet_id; + m_buffer_sharing_enabled = false; + m_blending_enabled = mode == LibraryAppletMode::PartialForeground || + mode == LibraryAppletMode::PartialForegroundIndirectDisplay; +} + +void DisplayLayerManager::Finalize() { + if (!m_manager_display_service) { + return; + } + + // Clean up managed layers. + for (const auto& layer : m_managed_display_layers) { + m_manager_display_service->DestroyManagedLayer(layer); + } + + for (const auto& layer : m_managed_display_recording_layers) { + m_manager_display_service->DestroyManagedLayer(layer); + } + + // Clean up shared layers. + if (m_buffer_sharing_enabled) { + m_manager_display_service->DestroySharedLayerSession(m_process); + } + + m_manager_display_service = nullptr; + m_display_service = nullptr; +} + +Result DisplayLayerManager::CreateManagedDisplayLayer(u64* out_layer_id) { + R_UNLESS(m_manager_display_service != nullptr, VI::ResultOperationFailed); + + // TODO(Subv): Find out how AM determines the display to use, for now just + // create the layer in the Default display. + u64 display_id; + R_TRY(m_display_service->OpenDisplay(&display_id, VI::DisplayName{"Default"})); + R_TRY(m_manager_display_service->CreateManagedLayer( + out_layer_id, 0, display_id, Service::AppletResourceUserId{m_process->GetProcessId()})); + + m_manager_display_service->SetLayerVisibility(m_visible, *out_layer_id); + m_managed_display_layers.emplace(*out_layer_id); + + R_SUCCEED(); +} + +Result DisplayLayerManager::CreateManagedDisplaySeparableLayer(u64* out_layer_id, + u64* out_recording_layer_id) { + R_UNLESS(m_manager_display_service != nullptr, VI::ResultOperationFailed); + + // TODO(Subv): Find out how AM determines the display to use, for now just + // create the layer in the Default display. + // This calls nn::vi::CreateRecordingLayer() which creates another layer. + // Currently we do not support more than 1 layer per display, output 1 layer id for now. + // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse + // side effects. + *out_recording_layer_id = 0; + R_RETURN(this->CreateManagedDisplayLayer(out_layer_id)); +} + +Result DisplayLayerManager::IsSystemBufferSharingEnabled() { + // Succeed if already enabled. + R_SUCCEED_IF(m_buffer_sharing_enabled); + + // Ensure we can access shared layers. + R_UNLESS(m_manager_display_service != nullptr, VI::ResultOperationFailed); + R_UNLESS(m_applet_id != AppletId::Application, VI::ResultPermissionDenied); + + // Create the shared layer. + u64 display_id; + R_TRY(m_display_service->OpenDisplay(&display_id, VI::DisplayName{"Default"})); + R_TRY(m_manager_display_service->CreateSharedLayerSession(m_process, &m_system_shared_buffer_id, + &m_system_shared_layer_id, display_id, + m_blending_enabled)); + + // We succeeded, so set up remaining state. + m_buffer_sharing_enabled = true; + m_manager_display_service->SetLayerVisibility(m_visible, m_system_shared_layer_id); + R_SUCCEED(); +} + +Result DisplayLayerManager::GetSystemSharedLayerHandle(u64* out_system_shared_buffer_id, + u64* out_system_shared_layer_id) { + R_TRY(this->IsSystemBufferSharingEnabled()); + + *out_system_shared_buffer_id = m_system_shared_buffer_id; + *out_system_shared_layer_id = m_system_shared_layer_id; + + R_SUCCEED(); +} + +void DisplayLayerManager::SetWindowVisibility(bool visible) { + if (m_visible == visible) { + return; + } + + m_visible = visible; + + if (m_manager_display_service) { + if (m_system_shared_layer_id) { + m_manager_display_service->SetLayerVisibility(m_visible, m_system_shared_layer_id); + } + + for (const auto layer_id : m_managed_display_layers) { + m_manager_display_service->SetLayerVisibility(m_visible, layer_id); + } + } +} + +bool DisplayLayerManager::GetWindowVisibility() const { + return m_visible; +} + +Result DisplayLayerManager::WriteAppletCaptureBuffer(bool* out_was_written, + s32* out_fbshare_layer_index) { + R_UNLESS(m_buffer_sharing_enabled, VI::ResultPermissionDenied); + R_RETURN(m_display_service->GetContainer()->GetSharedBufferManager()->WriteAppletCaptureBuffer( + out_was_written, out_fbshare_layer_index)); +} + +} // namespace Service::AM diff --git a/src/core/hle/service/am/display_layer_manager.h b/src/core/hle/service/am/display_layer_manager.h new file mode 100644 index 000000000..a66509c04 --- /dev/null +++ b/src/core/hle/service/am/display_layer_manager.h @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <set> + +#include "common/common_types.h" +#include "core/hle/result.h" +#include "core/hle/service/am/am_types.h" + +namespace Core { +class System; +} + +namespace Kernel { +class KProcess; +} + +namespace Service::VI { +class IApplicationDisplayService; +class IManagerDisplayService; +} // namespace Service::VI + +namespace Service::AM { + +class DisplayLayerManager { +public: + explicit DisplayLayerManager(); + ~DisplayLayerManager(); + + void Initialize(Core::System& system, Kernel::KProcess* process, AppletId applet_id, + LibraryAppletMode mode); + void Finalize(); + + Result CreateManagedDisplayLayer(u64* out_layer_id); + Result CreateManagedDisplaySeparableLayer(u64* out_layer_id, u64* out_recording_layer_id); + + Result IsSystemBufferSharingEnabled(); + Result GetSystemSharedLayerHandle(u64* out_system_shared_buffer_id, + u64* out_system_shared_layer_id); + + void SetWindowVisibility(bool visible); + bool GetWindowVisibility() const; + + Result WriteAppletCaptureBuffer(bool* out_was_written, s32* out_fbshare_layer_index); + +private: + Kernel::KProcess* m_process{}; + std::shared_ptr<VI::IApplicationDisplayService> m_display_service{}; + std::shared_ptr<VI::IManagerDisplayService> m_manager_display_service{}; + std::set<u64> m_managed_display_layers{}; + std::set<u64> m_managed_display_recording_layers{}; + u64 m_system_shared_buffer_id{}; + u64 m_system_shared_layer_id{}; + AppletId m_applet_id{}; + bool m_buffer_sharing_enabled{}; + bool m_blending_enabled{}; + bool m_visible{true}; +}; + +} // namespace Service::AM diff --git a/src/core/hle/service/am/frontend/applet_web_browser.cpp b/src/core/hle/service/am/frontend/applet_web_browser.cpp index bb60260b4..835c20c4e 100644 --- a/src/core/hle/service/am/frontend/applet_web_browser.cpp +++ b/src/core/hle/service/am/frontend/applet_web_browser.cpp @@ -22,7 +22,7 @@ #include "core/hle/service/am/frontend/applet_web_browser.h" #include "core/hle/service/am/service/storage.h" #include "core/hle/service/filesystem/filesystem.h" -#include "core/hle/service/ns/iplatform_service_manager.h" +#include "core/hle/service/ns/platform_service_manager.h" #include "core/loader/loader.h" namespace Service::AM::Frontend { diff --git a/src/core/hle/service/am/library_applet_storage.cpp b/src/core/hle/service/am/library_applet_storage.cpp index 46e6c0111..0412c215d 100644 --- a/src/core/hle/service/am/library_applet_storage.cpp +++ b/src/core/hle/service/am/library_applet_storage.cpp @@ -70,7 +70,7 @@ public: Result Read(s64 offset, void* buffer, size_t size) override { R_TRY(ValidateOffset(offset, size, m_size)); - m_memory.ReadBlock(m_trmem->GetSourceAddress(), buffer, size); + m_memory.ReadBlock(m_trmem->GetSourceAddress() + offset, buffer, size); R_SUCCEED(); } @@ -79,7 +79,7 @@ public: R_UNLESS(m_is_writable, ResultUnknown); R_TRY(ValidateOffset(offset, size, m_size)); - m_memory.WriteBlock(m_trmem->GetSourceAddress(), buffer, size); + m_memory.WriteBlock(m_trmem->GetSourceAddress() + offset, buffer, size); R_SUCCEED(); } diff --git a/src/core/hle/service/am/managed_layer_holder.cpp b/src/core/hle/service/am/managed_layer_holder.cpp deleted file mode 100644 index 61eb8641a..000000000 --- a/src/core/hle/service/am/managed_layer_holder.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "core/hle/service/am/managed_layer_holder.h" -#include "core/hle/service/nvnflinger/nvnflinger.h" - -namespace Service::AM { - -ManagedLayerHolder::ManagedLayerHolder() = default; -ManagedLayerHolder::~ManagedLayerHolder() { - if (!m_nvnflinger) { - return; - } - - for (const auto& layer : m_managed_display_layers) { - m_nvnflinger->DestroyLayer(layer); - } - - for (const auto& layer : m_managed_display_recording_layers) { - m_nvnflinger->DestroyLayer(layer); - } - - m_nvnflinger = nullptr; -} - -void ManagedLayerHolder::Initialize(Nvnflinger::Nvnflinger* nvnflinger) { - m_nvnflinger = nvnflinger; -} - -void ManagedLayerHolder::CreateManagedDisplayLayer(u64* out_layer) { - // TODO(Subv): Find out how AM determines the display to use, for now just - // create the layer in the Default display. - const auto display_id = m_nvnflinger->OpenDisplay("Default"); - const auto layer_id = m_nvnflinger->CreateLayer(*display_id); - - m_managed_display_layers.emplace(*layer_id); - - *out_layer = *layer_id; -} - -void ManagedLayerHolder::CreateManagedDisplaySeparableLayer(u64* out_layer, - u64* out_recording_layer) { - // TODO(Subv): Find out how AM determines the display to use, for now just - // create the layer in the Default display. - // This calls nn::vi::CreateRecordingLayer() which creates another layer. - // Currently we do not support more than 1 layer per display, output 1 layer id for now. - // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse - // side effects. - // TODO: Support multiple layers - const auto display_id = m_nvnflinger->OpenDisplay("Default"); - const auto layer_id = m_nvnflinger->CreateLayer(*display_id); - - m_managed_display_layers.emplace(*layer_id); - - *out_layer = *layer_id; - *out_recording_layer = 0; -} - -} // namespace Service::AM diff --git a/src/core/hle/service/am/managed_layer_holder.h b/src/core/hle/service/am/managed_layer_holder.h deleted file mode 100644 index f7fe03f24..000000000 --- a/src/core/hle/service/am/managed_layer_holder.h +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include <set> - -#include "common/common_funcs.h" -#include "common/common_types.h" - -namespace Service::Nvnflinger { -class Nvnflinger; -} - -namespace Service::AM { - -class ManagedLayerHolder { -public: - ManagedLayerHolder(); - ~ManagedLayerHolder(); - - void Initialize(Nvnflinger::Nvnflinger* nvnflinger); - void CreateManagedDisplayLayer(u64* out_layer); - void CreateManagedDisplaySeparableLayer(u64* out_layer, u64* out_recording_layer); - -private: - Nvnflinger::Nvnflinger* m_nvnflinger{}; - std::set<u64> m_managed_display_layers{}; - std::set<u64> m_managed_display_recording_layers{}; -}; - -} // namespace Service::AM diff --git a/src/core/hle/service/am/process.cpp b/src/core/hle/service/am/process.cpp index 992c50713..388d2045c 100644 --- a/src/core/hle/service/am/process.cpp +++ b/src/core/hle/service/am/process.cpp @@ -68,7 +68,9 @@ bool Process::Initialize(u64 program_id, u8 minimum_key_generation, u8 maximum_k Kernel::KProcess::Register(m_system.Kernel(), process); // On exit, ensure we free the additional reference to the process. - SCOPE_EXIT({ process->Close(); }); + SCOPE_EXIT { + process->Close(); + }; // Insert process modules into memory. const auto [load_result, load_parameters] = app_loader->Load(*process, m_system); diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp index eebd90ba2..21747783a 100644 --- a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp +++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp @@ -10,9 +10,8 @@ namespace Service::AM { -IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_, - Nvnflinger::Nvnflinger& nvnflinger) - : ServiceFramework{system_, "appletAE"}, m_nvnflinger{nvnflinger} { +IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_) + : ServiceFramework{system_, "appletAE"} { // clang-format off static const FunctionInfo functions[] = { {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"}, @@ -37,8 +36,8 @@ Result IAllSystemAppletProxiesService::OpenSystemAppletProxy( LOG_DEBUG(Service_AM, "called"); if (const auto applet = this->GetAppletFromProcessId(pid); applet) { - *out_system_applet_proxy = std::make_shared<ISystemAppletProxy>( - system, applet, process_handle.Get(), m_nvnflinger); + *out_system_applet_proxy = + std::make_shared<ISystemAppletProxy>(system, applet, process_handle.Get()); R_SUCCEED(); } else { UNIMPLEMENTED(); @@ -53,8 +52,8 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxy( LOG_DEBUG(Service_AM, "called"); if (const auto applet = this->GetAppletFromProcessId(pid); applet) { - *out_library_applet_proxy = std::make_shared<ILibraryAppletProxy>( - system, applet, process_handle.Get(), m_nvnflinger); + *out_library_applet_proxy = + std::make_shared<ILibraryAppletProxy>(system, applet, process_handle.Get()); R_SUCCEED(); } else { UNIMPLEMENTED(); diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.h b/src/core/hle/service/am/service/all_system_applet_proxies_service.h index 38b1ca2ea..0e2dcb86d 100644 --- a/src/core/hle/service/am/service/all_system_applet_proxies_service.h +++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.h @@ -8,10 +8,6 @@ namespace Service { -namespace Nvnflinger { -class Nvnflinger; -} - namespace AM { struct Applet; @@ -22,8 +18,7 @@ class ISystemAppletProxy; class IAllSystemAppletProxiesService final : public ServiceFramework<IAllSystemAppletProxiesService> { public: - explicit IAllSystemAppletProxiesService(Core::System& system_, - Nvnflinger::Nvnflinger& nvnflinger); + explicit IAllSystemAppletProxiesService(Core::System& system_); ~IAllSystemAppletProxiesService() override; private: @@ -40,7 +35,6 @@ private: private: std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid); - Nvnflinger::Nvnflinger& m_nvnflinger; }; } // namespace AM diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index 63dd12a47..cb53b07e0 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -16,7 +16,8 @@ #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/save_data_controller.h" #include "core/hle/service/glue/glue_manager.h" -#include "core/hle/service/ns/ns.h" +#include "core/hle/service/ns/application_manager_interface.h" +#include "core/hle/service/ns/service_getter_interface.h" #include "core/hle/service/sm/sm.h" namespace Service::AM { @@ -163,11 +164,13 @@ Result IApplicationFunctions::GetDesiredLanguage(Out<u64> out_language_code) { // Call IApplicationManagerInterface implementation. auto& service_manager = system.ServiceManager(); - auto ns_am2 = service_manager.GetService<NS::NS>("ns:am2"); - auto app_man = ns_am2->GetApplicationManagerInterface(); + auto ns_am2 = service_manager.GetService<NS::IServiceGetterInterface>("ns:am2"); + + std::shared_ptr<NS::IApplicationManagerInterface> app_man; + R_TRY(ns_am2->GetApplicationManagerInterface(&app_man)); // Get desired application language - u8 desired_language{}; + NS::ApplicationLanguage desired_language{}; R_TRY(app_man->GetApplicationDesiredLanguage(&desired_language, supported_languages)); // Convert to settings language code. diff --git a/src/core/hle/service/am/service/application_proxy.cpp b/src/core/hle/service/am/service/application_proxy.cpp index 776f4552b..19d6a3b89 100644 --- a/src/core/hle/service/am/service/application_proxy.cpp +++ b/src/core/hle/service/am/service/application_proxy.cpp @@ -17,9 +17,9 @@ namespace Service::AM { IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger) - : ServiceFramework{system_, "IApplicationProxy"}, - m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "IApplicationProxy"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, @@ -77,8 +77,7 @@ Result IApplicationProxy::GetWindowController( Result IApplicationProxy::GetSelfController( Out<SharedPointer<ISelfController>> out_self_controller) { LOG_DEBUG(Service_AM, "called"); - *out_self_controller = - std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger); + *out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/application_proxy.h b/src/core/hle/service/am/service/application_proxy.h index 1ebc593ba..6da350df7 100644 --- a/src/core/hle/service/am/service/application_proxy.h +++ b/src/core/hle/service/am/service/application_proxy.h @@ -22,7 +22,7 @@ class IWindowController; class IApplicationProxy final : public ServiceFramework<IApplicationProxy> { public: explicit IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); + Kernel::KProcess* process); ~IApplicationProxy(); private: @@ -40,7 +40,6 @@ private: Out<SharedPointer<IApplicationFunctions>> out_application_functions); private: - Nvnflinger::Nvnflinger& m_nvnflinger; Kernel::KProcess* const m_process; const std::shared_ptr<Applet> m_applet; }; diff --git a/src/core/hle/service/am/service/application_proxy_service.cpp b/src/core/hle/service/am/service/application_proxy_service.cpp index 36d4478df..fd66e77b9 100644 --- a/src/core/hle/service/am/service/application_proxy_service.cpp +++ b/src/core/hle/service/am/service/application_proxy_service.cpp @@ -10,9 +10,8 @@ namespace Service::AM { -IApplicationProxyService::IApplicationProxyService(Core::System& system_, - Nvnflinger::Nvnflinger& nvnflinger) - : ServiceFramework{system_, "appletOE"}, m_nvnflinger{nvnflinger} { +IApplicationProxyService::IApplicationProxyService(Core::System& system_) + : ServiceFramework{system_, "appletOE"} { static const FunctionInfo functions[] = { {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"}, }; @@ -28,7 +27,7 @@ Result IApplicationProxyService::OpenApplicationProxy( if (const auto applet = this->GetAppletFromProcessId(pid)) { *out_application_proxy = - std::make_shared<IApplicationProxy>(system, applet, process_handle.Get(), m_nvnflinger); + std::make_shared<IApplicationProxy>(system, applet, process_handle.Get()); R_SUCCEED(); } else { UNIMPLEMENTED(); diff --git a/src/core/hle/service/am/service/application_proxy_service.h b/src/core/hle/service/am/service/application_proxy_service.h index 1c1d32d0b..8efafa31a 100644 --- a/src/core/hle/service/am/service/application_proxy_service.h +++ b/src/core/hle/service/am/service/application_proxy_service.h @@ -8,10 +8,6 @@ namespace Service { -namespace Nvnflinger { -class Nvnflinger; -} - namespace AM { struct Applet; @@ -19,7 +15,7 @@ class IApplicationProxy; class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> { public: - explicit IApplicationProxyService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger); + explicit IApplicationProxyService(Core::System& system_); ~IApplicationProxyService() override; private: @@ -28,7 +24,6 @@ private: private: std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid); - Nvnflinger::Nvnflinger& m_nvnflinger; }; } // namespace AM diff --git a/src/core/hle/service/am/service/display_controller.cpp b/src/core/hle/service/am/service/display_controller.cpp index 249c73dfb..ed71f9093 100644 --- a/src/core/hle/service/am/service/display_controller.cpp +++ b/src/core/hle/service/am/service/display_controller.cpp @@ -69,7 +69,7 @@ Result IDisplayController::ClearCaptureBuffer(bool unknown0, s32 fbshare_layer_i Result IDisplayController::AcquireLastForegroundCaptureSharedBuffer( Out<bool> out_was_written, Out<s32> out_fbshare_layer_index) { LOG_WARNING(Service_AM, "(STUBBED) called"); - R_RETURN(applet->system_buffer_manager.WriteAppletCaptureBuffer(out_was_written, + R_RETURN(applet->display_layer_manager.WriteAppletCaptureBuffer(out_was_written, out_fbshare_layer_index)); } @@ -81,7 +81,7 @@ Result IDisplayController::ReleaseLastForegroundCaptureSharedBuffer() { Result IDisplayController::AcquireCallerAppletCaptureSharedBuffer( Out<bool> out_was_written, Out<s32> out_fbshare_layer_index) { LOG_WARNING(Service_AM, "(STUBBED) called"); - R_RETURN(applet->system_buffer_manager.WriteAppletCaptureBuffer(out_was_written, + R_RETURN(applet->display_layer_manager.WriteAppletCaptureBuffer(out_was_written, out_fbshare_layer_index)); } @@ -93,7 +93,7 @@ Result IDisplayController::ReleaseCallerAppletCaptureSharedBuffer() { Result IDisplayController::AcquireLastApplicationCaptureSharedBuffer( Out<bool> out_was_written, Out<s32> out_fbshare_layer_index) { LOG_WARNING(Service_AM, "(STUBBED) called"); - R_RETURN(applet->system_buffer_manager.WriteAppletCaptureBuffer(out_was_written, + R_RETURN(applet->display_layer_manager.WriteAppletCaptureBuffer(out_was_written, out_fbshare_layer_index)); } diff --git a/src/core/hle/service/am/service/library_applet_creator.cpp b/src/core/hle/service/am/service/library_applet_creator.cpp index 166637d60..c97358d81 100644 --- a/src/core/hle/service/am/service/library_applet_creator.cpp +++ b/src/core/hle/service/am/service/library_applet_creator.cpp @@ -135,7 +135,7 @@ std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system, case LibraryAppletMode::AllForegroundInitiallyHidden: applet->hid_registration.EnableAppletToGetInput(false); applet->focus_state = FocusState::NotInFocus; - applet->system_buffer_manager.SetWindowVisibility(false); + applet->display_layer_manager.SetWindowVisibility(false); applet->message_queue.PushMessage(AppletMessage::ChangeIntoBackground); break; } diff --git a/src/core/hle/service/am/service/library_applet_proxy.cpp b/src/core/hle/service/am/service/library_applet_proxy.cpp index bcb44a71c..58e709347 100644 --- a/src/core/hle/service/am/service/library_applet_proxy.cpp +++ b/src/core/hle/service/am/service/library_applet_proxy.cpp @@ -19,10 +19,9 @@ namespace Service::AM { ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, - Nvnflinger::Nvnflinger& nvnflinger) - : ServiceFramework{system_, "ILibraryAppletProxy"}, - m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "ILibraryAppletProxy"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, @@ -83,8 +82,7 @@ Result ILibraryAppletProxy::GetWindowController( Result ILibraryAppletProxy::GetSelfController( Out<SharedPointer<ISelfController>> out_self_controller) { LOG_DEBUG(Service_AM, "called"); - *out_self_controller = - std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger); + *out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/library_applet_proxy.h b/src/core/hle/service/am/service/library_applet_proxy.h index 23e64e295..7d0714b85 100644 --- a/src/core/hle/service/am/service/library_applet_proxy.h +++ b/src/core/hle/service/am/service/library_applet_proxy.h @@ -25,7 +25,7 @@ class IWindowController; class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> { public: explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); + Kernel::KProcess* process); ~ILibraryAppletProxy(); private: @@ -47,7 +47,6 @@ private: Result GetGlobalStateController( Out<SharedPointer<IGlobalStateController>> out_global_state_controller); - Nvnflinger::Nvnflinger& m_nvnflinger; Kernel::KProcess* const m_process; const std::shared_ptr<Applet> m_applet; }; diff --git a/src/core/hle/service/am/service/library_applet_self_accessor.cpp b/src/core/hle/service/am/service/library_applet_self_accessor.cpp index 94bd4dae6..330eb26f0 100644 --- a/src/core/hle/service/am/service/library_applet_self_accessor.cpp +++ b/src/core/hle/service/am/service/library_applet_self_accessor.cpp @@ -14,7 +14,8 @@ #include "core/hle/service/cmif_serialization.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/glue/glue_manager.h" -#include "core/hle/service/ns/ns.h" +#include "core/hle/service/ns/application_manager_interface.h" +#include "core/hle/service/ns/service_getter_interface.h" #include "core/hle/service/sm/sm.h" namespace Service::AM { @@ -256,11 +257,13 @@ Result ILibraryAppletSelfAccessor::GetMainAppletApplicationDesiredLanguage( // Call IApplicationManagerInterface implementation. auto& service_manager = system.ServiceManager(); - auto ns_am2 = service_manager.GetService<NS::NS>("ns:am2"); - auto app_man = ns_am2->GetApplicationManagerInterface(); + auto ns_am2 = service_manager.GetService<NS::IServiceGetterInterface>("ns:am2"); + + std::shared_ptr<NS::IApplicationManagerInterface> app_man; + R_TRY(ns_am2->GetApplicationManagerInterface(&app_man)); // Get desired application language - u8 desired_language{}; + NS::ApplicationLanguage desired_language{}; R_TRY(app_man->GetApplicationDesiredLanguage(&desired_language, supported_languages)); // Convert to settings language code. diff --git a/src/core/hle/service/am/service/self_controller.cpp b/src/core/hle/service/am/service/self_controller.cpp index 5c4c13de1..06314407c 100644 --- a/src/core/hle/service/am/service/self_controller.cpp +++ b/src/core/hle/service/am/service/self_controller.cpp @@ -15,9 +15,9 @@ namespace Service::AM { ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger) - : ServiceFramework{system_, "ISelfController"}, - m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "ISelfController"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&ISelfController::Exit>, "Exit"}, @@ -72,9 +72,16 @@ ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet> // clang-format on RegisterHandlers(functions); + + std::scoped_lock lk{m_applet->lock}; + m_applet->display_layer_manager.Initialize(system, m_process, m_applet->applet_id, + m_applet->library_applet_mode); } -ISelfController::~ISelfController() = default; +ISelfController::~ISelfController() { + std::scoped_lock lk{m_applet->lock}; + m_applet->display_layer_manager.Finalize(); +} Result ISelfController::Exit() { LOG_DEBUG(Service_AM, "called"); @@ -212,48 +219,42 @@ Result ISelfController::SetAlbumImageOrientation( Result ISelfController::IsSystemBufferSharingEnabled() { LOG_INFO(Service_AM, "called"); - R_SUCCEED_IF(m_applet->system_buffer_manager.Initialize( - &m_nvnflinger, m_process, m_applet->applet_id, m_applet->library_applet_mode)); - R_THROW(VI::ResultOperationFailed); + + std::scoped_lock lk{m_applet->lock}; + R_RETURN(m_applet->display_layer_manager.IsSystemBufferSharingEnabled()); } Result ISelfController::GetSystemSharedBufferHandle(Out<u64> out_buffer_id) { - LOG_WARNING(Service_AM, "(STUBBED) called"); - - R_TRY(this->IsSystemBufferSharingEnabled()); + LOG_INFO(Service_AM, "called"); u64 layer_id; - m_applet->system_buffer_manager.GetSystemSharedLayerHandle(out_buffer_id, &layer_id); - R_SUCCEED(); + + std::scoped_lock lk{m_applet->lock}; + R_RETURN(m_applet->display_layer_manager.GetSystemSharedLayerHandle(out_buffer_id, &layer_id)); } Result ISelfController::GetSystemSharedLayerHandle(Out<u64> out_buffer_id, Out<u64> out_layer_id) { - LOG_INFO(Service_AM, "(STUBBED) called"); - - R_TRY(this->IsSystemBufferSharingEnabled()); + LOG_INFO(Service_AM, "called"); - m_applet->system_buffer_manager.GetSystemSharedLayerHandle(out_buffer_id, out_layer_id); - R_SUCCEED(); + std::scoped_lock lk{m_applet->lock}; + R_RETURN( + m_applet->display_layer_manager.GetSystemSharedLayerHandle(out_buffer_id, out_layer_id)); } Result ISelfController::CreateManagedDisplayLayer(Out<u64> out_layer_id) { LOG_INFO(Service_AM, "called"); - m_applet->managed_layer_holder.Initialize(&m_nvnflinger); - m_applet->managed_layer_holder.CreateManagedDisplayLayer(out_layer_id); - - R_SUCCEED(); + std::scoped_lock lk{m_applet->lock}; + R_RETURN(m_applet->display_layer_manager.CreateManagedDisplayLayer(out_layer_id)); } Result ISelfController::CreateManagedDisplaySeparableLayer(Out<u64> out_layer_id, Out<u64> out_recording_layer_id) { LOG_WARNING(Service_AM, "(STUBBED) called"); - m_applet->managed_layer_holder.Initialize(&m_nvnflinger); - m_applet->managed_layer_holder.CreateManagedDisplaySeparableLayer(out_layer_id, - out_recording_layer_id); - - R_SUCCEED(); + std::scoped_lock lk{m_applet->lock}; + R_RETURN(m_applet->display_layer_manager.CreateManagedDisplaySeparableLayer( + out_layer_id, out_recording_layer_id)); } Result ISelfController::SetHandlesRequestToDisplay(bool enable) { diff --git a/src/core/hle/service/am/service/self_controller.h b/src/core/hle/service/am/service/self_controller.h index 01fa381a3..eca083cfe 100644 --- a/src/core/hle/service/am/service/self_controller.h +++ b/src/core/hle/service/am/service/self_controller.h @@ -23,7 +23,7 @@ struct Applet; class ISelfController final : public ServiceFramework<ISelfController> { public: explicit ISelfController(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); + Kernel::KProcess* process); ~ISelfController() override; private: @@ -64,7 +64,6 @@ private: Result SaveCurrentScreenshot(Capture::AlbumReportOption album_report_option); Result SetRecordVolumeMuted(bool muted); - Nvnflinger::Nvnflinger& m_nvnflinger; Kernel::KProcess* const m_process; const std::shared_ptr<Applet> m_applet; }; diff --git a/src/core/hle/service/am/service/system_applet_proxy.cpp b/src/core/hle/service/am/service/system_applet_proxy.cpp index 5ec509d2e..d1871ef9b 100644 --- a/src/core/hle/service/am/service/system_applet_proxy.cpp +++ b/src/core/hle/service/am/service/system_applet_proxy.cpp @@ -19,10 +19,9 @@ namespace Service::AM { ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, - Nvnflinger::Nvnflinger& nvnflinger) - : ServiceFramework{system_, "ISystemAppletProxy"}, - m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} { + Kernel::KProcess* process) + : ServiceFramework{system_, "ISystemAppletProxy"}, m_process{process}, m_applet{ + std::move(applet)} { // clang-format off static const FunctionInfo functions[] = { {0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, @@ -83,8 +82,7 @@ Result ISystemAppletProxy::GetWindowController( Result ISystemAppletProxy::GetSelfController( Out<SharedPointer<ISelfController>> out_self_controller) { LOG_DEBUG(Service_AM, "called"); - *out_self_controller = - std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger); + *out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process); R_SUCCEED(); } diff --git a/src/core/hle/service/am/service/system_applet_proxy.h b/src/core/hle/service/am/service/system_applet_proxy.h index 3d5040315..67cd50e03 100644 --- a/src/core/hle/service/am/service/system_applet_proxy.h +++ b/src/core/hle/service/am/service/system_applet_proxy.h @@ -25,7 +25,7 @@ class IWindowController; class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> { public: explicit ISystemAppletProxy(Core::System& system, std::shared_ptr<Applet> applet, - Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); + Kernel::KProcess* process); ~ISystemAppletProxy(); private: @@ -46,7 +46,6 @@ private: Result GetGlobalStateController( Out<SharedPointer<IGlobalStateController>> out_global_state_controller); - Nvnflinger::Nvnflinger& m_nvnflinger; Kernel::KProcess* const m_process; const std::shared_ptr<Applet> m_applet; }; diff --git a/src/core/hle/service/am/service/window_controller.cpp b/src/core/hle/service/am/service/window_controller.cpp index b874ecb91..99a4f50a2 100644 --- a/src/core/hle/service/am/service/window_controller.cpp +++ b/src/core/hle/service/am/service/window_controller.cpp @@ -63,7 +63,7 @@ Result IWindowController::RejectToChangeIntoBackground() { } Result IWindowController::SetAppletWindowVisibility(bool visible) { - m_applet->system_buffer_manager.SetWindowVisibility(visible); + m_applet->display_layer_manager.SetWindowVisibility(visible); m_applet->hid_registration.EnableAppletToGetInput(visible); if (visible) { diff --git a/src/core/hle/service/am/system_buffer_manager.cpp b/src/core/hle/service/am/system_buffer_manager.cpp deleted file mode 100644 index 48923fe41..000000000 --- a/src/core/hle/service/am/system_buffer_manager.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "core/hle/service/am/system_buffer_manager.h" -#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" -#include "core/hle/service/nvnflinger/nvnflinger.h" -#include "core/hle/service/vi/vi_results.h" - -namespace Service::AM { - -SystemBufferManager::SystemBufferManager() = default; - -SystemBufferManager::~SystemBufferManager() { - if (!m_nvnflinger) { - return; - } - - // Clean up shared layers. - if (m_buffer_sharing_enabled) { - m_nvnflinger->GetSystemBufferManager().Finalize(m_process); - } -} - -bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process, - AppletId applet_id, LibraryAppletMode mode) { - if (m_nvnflinger) { - return m_buffer_sharing_enabled; - } - - m_process = process; - m_nvnflinger = nvnflinger; - m_buffer_sharing_enabled = false; - m_system_shared_buffer_id = 0; - m_system_shared_layer_id = 0; - - if (applet_id <= AppletId::Application) { - return false; - } - - Nvnflinger::LayerBlending blending = Nvnflinger::LayerBlending::None; - if (mode == LibraryAppletMode::PartialForeground || - mode == LibraryAppletMode::PartialForegroundIndirectDisplay) { - blending = Nvnflinger::LayerBlending::Coverage; - } - - const auto display_id = m_nvnflinger->OpenDisplay("Default").value(); - const auto res = m_nvnflinger->GetSystemBufferManager().Initialize( - m_process, &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id, blending); - - if (res.IsSuccess()) { - m_buffer_sharing_enabled = true; - m_nvnflinger->SetLayerVisibility(m_system_shared_layer_id, m_visible); - } - - return m_buffer_sharing_enabled; -} - -void SystemBufferManager::SetWindowVisibility(bool visible) { - if (m_visible == visible) { - return; - } - - m_visible = visible; - - if (m_nvnflinger) { - m_nvnflinger->SetLayerVisibility(m_system_shared_layer_id, m_visible); - } -} - -Result SystemBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, - s32* out_fbshare_layer_index) { - if (!m_buffer_sharing_enabled) { - return VI::ResultPermissionDenied; - } - - return m_nvnflinger->GetSystemBufferManager().WriteAppletCaptureBuffer(out_was_written, - out_fbshare_layer_index); -} - -} // namespace Service::AM diff --git a/src/core/hle/service/am/system_buffer_manager.h b/src/core/hle/service/am/system_buffer_manager.h deleted file mode 100644 index 0690f68b6..000000000 --- a/src/core/hle/service/am/system_buffer_manager.h +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include <set> - -#include "common/common_funcs.h" -#include "common/common_types.h" - -#include "core/hle/service/am/am_types.h" - -namespace Kernel { -class KProcess; -} - -namespace Service::Nvnflinger { -class Nvnflinger; -} - -union Result; - -namespace Service::AM { - -class SystemBufferManager { -public: - SystemBufferManager(); - ~SystemBufferManager(); - - bool Initialize(Nvnflinger::Nvnflinger* flinger, Kernel::KProcess* process, AppletId applet_id, - LibraryAppletMode mode); - - void GetSystemSharedLayerHandle(u64* out_system_shared_buffer_id, - u64* out_system_shared_layer_id) { - *out_system_shared_buffer_id = m_system_shared_buffer_id; - *out_system_shared_layer_id = m_system_shared_layer_id; - } - - void SetWindowVisibility(bool visible); - - Result WriteAppletCaptureBuffer(bool* out_was_written, s32* out_fbshare_layer_index); - -private: - Kernel::KProcess* m_process{}; - Nvnflinger::Nvnflinger* m_nvnflinger{}; - bool m_buffer_sharing_enabled{}; - bool m_visible{true}; - u64 m_system_shared_buffer_id{}; - u64 m_system_shared_layer_id{}; -}; - -} // namespace Service::AM |