summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/CMakeLists.txt4
-rw-r--r--src/core/core.cpp4
-rw-r--r--src/core/hle/service/am/am.cpp10
-rw-r--r--src/core/hle/service/am/am.h6
-rw-r--r--src/core/hle/service/am/display_layer_manager.cpp51
-rw-r--r--src/core/hle/service/am/display_layer_manager.h10
-rw-r--r--src/core/hle/service/am/service/all_system_applet_proxies_service.cpp13
-rw-r--r--src/core/hle/service/am/service/all_system_applet_proxies_service.h8
-rw-r--r--src/core/hle/service/am/service/application_proxy.cpp9
-rw-r--r--src/core/hle/service/am/service/application_proxy.h3
-rw-r--r--src/core/hle/service/am/service/application_proxy_service.cpp7
-rw-r--r--src/core/hle/service/am/service/application_proxy_service.h7
-rw-r--r--src/core/hle/service/am/service/library_applet_proxy.cpp10
-rw-r--r--src/core/hle/service/am/service/library_applet_proxy.h3
-rw-r--r--src/core/hle/service/am/service/self_controller.cpp8
-rw-r--r--src/core/hle/service/am/service/self_controller.h3
-rw-r--r--src/core/hle/service/am/service/system_applet_proxy.cpp10
-rw-r--r--src/core/hle/service/am/service/system_applet_proxy.h3
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.cpp3
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.h2
-rw-r--r--src/core/hle/service/nvdrv/nvdrv_interface.cpp6
-rw-r--r--src/core/hle/service/nvdrv/nvdrv_interface.h4
-rw-r--r--src/core/hle/service/nvnflinger/hos_binder_driver.cpp (renamed from src/core/hle/service/vi/hos_binder_driver.cpp)17
-rw-r--r--src/core/hle/service/nvnflinger/hos_binder_driver.h (renamed from src/core/hle/service/vi/hos_binder_driver.h)17
-rw-r--r--src/core/hle/service/nvnflinger/nvnflinger.cpp53
-rw-r--r--src/core/hle/service/nvnflinger/nvnflinger.h6
-rw-r--r--src/core/hle/service/service.cpp20
-rw-r--r--src/core/hle/service/service.h11
-rw-r--r--src/core/hle/service/vi/application_display_service.cpp47
-rw-r--r--src/core/hle/service/vi/application_display_service.h18
-rw-r--r--src/core/hle/service/vi/application_root_service.cpp10
-rw-r--r--src/core/hle/service/vi/application_root_service.h10
-rw-r--r--src/core/hle/service/vi/manager_display_service.cpp9
-rw-r--r--src/core/hle/service/vi/manager_display_service.h5
-rw-r--r--src/core/hle/service/vi/manager_root_service.cpp10
-rw-r--r--src/core/hle/service/vi/manager_root_service.h10
-rw-r--r--src/core/hle/service/vi/service_creator.cpp7
-rw-r--r--src/core/hle/service/vi/service_creator.h8
-rw-r--r--src/core/hle/service/vi/system_display_service.cpp17
-rw-r--r--src/core/hle/service/vi/system_display_service.h8
-rw-r--r--src/core/hle/service/vi/system_root_service.cpp11
-rw-r--r--src/core/hle/service/vi/system_root_service.h10
-rw-r--r--src/core/hle/service/vi/vi.cpp18
-rw-r--r--src/core/hle/service/vi/vi.h8
44 files changed, 241 insertions, 273 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 6456ae634..f598bd634 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -804,6 +804,8 @@ add_library(core STATIC
804 hle/service/nvnflinger/graphic_buffer_producer.h 804 hle/service/nvnflinger/graphic_buffer_producer.h
805 hle/service/nvnflinger/hos_binder_driver_server.cpp 805 hle/service/nvnflinger/hos_binder_driver_server.cpp
806 hle/service/nvnflinger/hos_binder_driver_server.h 806 hle/service/nvnflinger/hos_binder_driver_server.h
807 hle/service/nvnflinger/hos_binder_driver.cpp
808 hle/service/nvnflinger/hos_binder_driver.h
807 hle/service/nvnflinger/hardware_composer.cpp 809 hle/service/nvnflinger/hardware_composer.cpp
808 hle/service/nvnflinger/hardware_composer.h 810 hle/service/nvnflinger/hardware_composer.h
809 hle/service/nvnflinger/hwc_layer.h 811 hle/service/nvnflinger/hwc_layer.h
@@ -961,8 +963,6 @@ add_library(core STATIC
961 hle/service/vi/application_display_service.h 963 hle/service/vi/application_display_service.h
962 hle/service/vi/application_root_service.cpp 964 hle/service/vi/application_root_service.cpp
963 hle/service/vi/application_root_service.h 965 hle/service/vi/application_root_service.h
964 hle/service/vi/hos_binder_driver.cpp
965 hle/service/vi/hos_binder_driver.h
966 hle/service/vi/manager_display_service.cpp 966 hle/service/vi/manager_display_service.cpp
967 hle/service/vi/manager_display_service.h 967 hle/service/vi/manager_display_service.h
968 hle/service/vi/manager_root_service.cpp 968 hle/service/vi/manager_root_service.cpp
diff --git a/src/core/core.cpp b/src/core/core.cpp
index bd5f11d53..60e2efddc 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -458,11 +458,9 @@ struct System::Impl {
458 gpu_core->NotifyShutdown(); 458 gpu_core->NotifyShutdown();
459 } 459 }
460 460
461 core_timing.SyncPause(false);
461 Network::CancelPendingSocketOperations(); 462 Network::CancelPendingSocketOperations();
462 kernel.SuspendEmulation(true); 463 kernel.SuspendEmulation(true);
463 if (services) {
464 services->KillNVNFlinger();
465 }
466 kernel.CloseServices(); 464 kernel.CloseServices();
467 kernel.ShutdownCores(); 465 kernel.ShutdownCores();
468 applet_manager.Reset(); 466 applet_manager.Reset();
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 @@
8 8
9namespace Service::AM { 9namespace Service::AM {
10 10
11void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) { 11void LoopProcess(Core::System& system) {
12 auto server_manager = std::make_unique<ServerManager>(system); 12 auto server_manager = std::make_unique<ServerManager>(system);
13 13
14 server_manager->RegisterNamedService( 14 server_manager->RegisterNamedService("appletAE",
15 "appletAE", std::make_shared<IAllSystemAppletProxiesService>(system, nvnflinger)); 15 std::make_shared<IAllSystemAppletProxiesService>(system));
16 server_manager->RegisterNamedService( 16 server_manager->RegisterNamedService("appletOE",
17 "appletOE", std::make_shared<IApplicationProxyService>(system, nvnflinger)); 17 std::make_shared<IApplicationProxyService>(system));
18 ServerManager::RunServer(std::move(server_manager)); 18 ServerManager::RunServer(std::move(server_manager));
19} 19}
20 20
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 {
7class System; 7class System;
8} 8}
9 9
10namespace Service::Nvnflinger {
11class Nvnflinger;
12}
13
14namespace Service::AM { 10namespace Service::AM {
15 11
16void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system); 12void LoopProcess(Core::System& system);
17 13
18} // namespace Service::AM 14} // namespace Service::AM
diff --git a/src/core/hle/service/am/display_layer_manager.cpp b/src/core/hle/service/am/display_layer_manager.cpp
index 50674c325..6cf3c369c 100644
--- a/src/core/hle/service/am/display_layer_manager.cpp
+++ b/src/core/hle/service/am/display_layer_manager.cpp
@@ -1,9 +1,12 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/core.h"
4#include "core/hle/service/am/display_layer_manager.h" 5#include "core/hle/service/am/display_layer_manager.h"
5#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" 6#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
7#include "core/hle/service/nvnflinger/hos_binder_driver.h"
6#include "core/hle/service/nvnflinger/nvnflinger.h" 8#include "core/hle/service/nvnflinger/nvnflinger.h"
9#include "core/hle/service/sm/sm.h"
7#include "core/hle/service/vi/vi_results.h" 10#include "core/hle/service/vi/vi_results.h"
8 11
9namespace Service::AM { 12namespace Service::AM {
@@ -13,10 +16,12 @@ DisplayLayerManager::~DisplayLayerManager() {
13 this->Finalize(); 16 this->Finalize();
14} 17}
15 18
16void DisplayLayerManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process, 19void DisplayLayerManager::Initialize(Core::System& system, Kernel::KProcess* process,
17 AppletId applet_id, LibraryAppletMode mode) { 20 AppletId applet_id, LibraryAppletMode mode) {
18 m_process = process; 21 m_process = process;
19 m_nvnflinger = nvnflinger; 22 m_surface_flinger = system.ServiceManager()
23 .GetService<Nvnflinger::IHOSBinderDriver>("dispdrv", true)
24 ->GetSurfaceFlinger();
20 m_system_shared_buffer_id = 0; 25 m_system_shared_buffer_id = 0;
21 m_system_shared_layer_id = 0; 26 m_system_shared_layer_id = 0;
22 m_applet_id = applet_id; 27 m_applet_id = applet_id;
@@ -26,36 +31,36 @@ void DisplayLayerManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel:
26} 31}
27 32
28void DisplayLayerManager::Finalize() { 33void DisplayLayerManager::Finalize() {
29 if (!m_nvnflinger) { 34 if (!m_surface_flinger) {
30 return; 35 return;
31 } 36 }
32 37
33 // Clean up managed layers. 38 // Clean up managed layers.
34 for (const auto& layer : m_managed_display_layers) { 39 for (const auto& layer : m_managed_display_layers) {
35 m_nvnflinger->DestroyLayer(layer); 40 m_surface_flinger->DestroyLayer(layer);
36 } 41 }
37 42
38 for (const auto& layer : m_managed_display_recording_layers) { 43 for (const auto& layer : m_managed_display_recording_layers) {
39 m_nvnflinger->DestroyLayer(layer); 44 m_surface_flinger->DestroyLayer(layer);
40 } 45 }
41 46
42 // Clean up shared layers. 47 // Clean up shared layers.
43 if (m_buffer_sharing_enabled) { 48 if (m_buffer_sharing_enabled) {
44 m_nvnflinger->GetSystemBufferManager().Finalize(m_process); 49 m_surface_flinger->GetSystemBufferManager().Finalize(m_process);
45 } 50 }
46 51
47 m_nvnflinger = nullptr; 52 m_surface_flinger = nullptr;
48} 53}
49 54
50Result DisplayLayerManager::CreateManagedDisplayLayer(u64* out_layer) { 55Result DisplayLayerManager::CreateManagedDisplayLayer(u64* out_layer) {
51 R_UNLESS(m_nvnflinger != nullptr, VI::ResultOperationFailed); 56 R_UNLESS(m_surface_flinger != nullptr, VI::ResultOperationFailed);
52 57
53 // TODO(Subv): Find out how AM determines the display to use, for now just 58 // TODO(Subv): Find out how AM determines the display to use, for now just
54 // create the layer in the Default display. 59 // create the layer in the Default display.
55 const auto display_id = m_nvnflinger->OpenDisplay("Default"); 60 const auto display_id = m_surface_flinger->OpenDisplay("Default");
56 const auto layer_id = m_nvnflinger->CreateLayer(*display_id); 61 const auto layer_id = m_surface_flinger->CreateLayer(*display_id);
57 62
58 m_nvnflinger->SetLayerVisibility(*layer_id, m_visible); 63 m_surface_flinger->SetLayerVisibility(*layer_id, m_visible);
59 m_managed_display_layers.emplace(*layer_id); 64 m_managed_display_layers.emplace(*layer_id);
60 65
61 *out_layer = *layer_id; 66 *out_layer = *layer_id;
@@ -65,7 +70,7 @@ Result DisplayLayerManager::CreateManagedDisplayLayer(u64* out_layer) {
65 70
66Result DisplayLayerManager::CreateManagedDisplaySeparableLayer(u64* out_layer, 71Result DisplayLayerManager::CreateManagedDisplaySeparableLayer(u64* out_layer,
67 u64* out_recording_layer) { 72 u64* out_recording_layer) {
68 R_UNLESS(m_nvnflinger != nullptr, VI::ResultOperationFailed); 73 R_UNLESS(m_surface_flinger != nullptr, VI::ResultOperationFailed);
69 74
70 // TODO(Subv): Find out how AM determines the display to use, for now just 75 // TODO(Subv): Find out how AM determines the display to use, for now just
71 // create the layer in the Default display. 76 // create the layer in the Default display.
@@ -74,10 +79,10 @@ Result DisplayLayerManager::CreateManagedDisplaySeparableLayer(u64* out_layer,
74 // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse 79 // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse
75 // side effects. 80 // side effects.
76 // TODO: Support multiple layers 81 // TODO: Support multiple layers
77 const auto display_id = m_nvnflinger->OpenDisplay("Default"); 82 const auto display_id = m_surface_flinger->OpenDisplay("Default");
78 const auto layer_id = m_nvnflinger->CreateLayer(*display_id); 83 const auto layer_id = m_surface_flinger->CreateLayer(*display_id);
79 84
80 m_nvnflinger->SetLayerVisibility(*layer_id, m_visible); 85 m_surface_flinger->SetLayerVisibility(*layer_id, m_visible);
81 m_managed_display_layers.emplace(*layer_id); 86 m_managed_display_layers.emplace(*layer_id);
82 87
83 *out_layer = *layer_id; 88 *out_layer = *layer_id;
@@ -91,19 +96,19 @@ Result DisplayLayerManager::IsSystemBufferSharingEnabled() {
91 R_SUCCEED_IF(m_buffer_sharing_enabled); 96 R_SUCCEED_IF(m_buffer_sharing_enabled);
92 97
93 // Ensure we can access shared layers. 98 // Ensure we can access shared layers.
94 R_UNLESS(m_nvnflinger != nullptr, VI::ResultOperationFailed); 99 R_UNLESS(m_surface_flinger != nullptr, VI::ResultOperationFailed);
95 R_UNLESS(m_applet_id != AppletId::Application, VI::ResultPermissionDenied); 100 R_UNLESS(m_applet_id != AppletId::Application, VI::ResultPermissionDenied);
96 101
97 // Create the shared layer. 102 // Create the shared layer.
98 const auto blend = 103 const auto blend =
99 m_blending_enabled ? Nvnflinger::LayerBlending::Coverage : Nvnflinger::LayerBlending::None; 104 m_blending_enabled ? Nvnflinger::LayerBlending::Coverage : Nvnflinger::LayerBlending::None;
100 const auto display_id = m_nvnflinger->OpenDisplay("Default").value(); 105 const auto display_id = m_surface_flinger->OpenDisplay("Default").value();
101 R_TRY(m_nvnflinger->GetSystemBufferManager().Initialize( 106 R_TRY(m_surface_flinger->GetSystemBufferManager().Initialize(
102 m_process, &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id, blend)); 107 m_process, &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id, blend));
103 108
104 // We succeeded, so set up remaining state. 109 // We succeeded, so set up remaining state.
105 m_buffer_sharing_enabled = true; 110 m_buffer_sharing_enabled = true;
106 m_nvnflinger->SetLayerVisibility(m_system_shared_layer_id, m_visible); 111 m_surface_flinger->SetLayerVisibility(m_system_shared_layer_id, m_visible);
107 R_SUCCEED(); 112 R_SUCCEED();
108} 113}
109 114
@@ -124,13 +129,13 @@ void DisplayLayerManager::SetWindowVisibility(bool visible) {
124 129
125 m_visible = visible; 130 m_visible = visible;
126 131
127 if (m_nvnflinger) { 132 if (m_surface_flinger) {
128 if (m_system_shared_layer_id) { 133 if (m_system_shared_layer_id) {
129 m_nvnflinger->SetLayerVisibility(m_system_shared_layer_id, m_visible); 134 m_surface_flinger->SetLayerVisibility(m_system_shared_layer_id, m_visible);
130 } 135 }
131 136
132 for (const auto layer_id : m_managed_display_layers) { 137 for (const auto layer_id : m_managed_display_layers) {
133 m_nvnflinger->SetLayerVisibility(layer_id, m_visible); 138 m_surface_flinger->SetLayerVisibility(layer_id, m_visible);
134 } 139 }
135 } 140 }
136} 141}
@@ -142,7 +147,7 @@ bool DisplayLayerManager::GetWindowVisibility() const {
142Result DisplayLayerManager::WriteAppletCaptureBuffer(bool* out_was_written, 147Result DisplayLayerManager::WriteAppletCaptureBuffer(bool* out_was_written,
143 s32* out_fbshare_layer_index) { 148 s32* out_fbshare_layer_index) {
144 R_UNLESS(m_buffer_sharing_enabled, VI::ResultPermissionDenied); 149 R_UNLESS(m_buffer_sharing_enabled, VI::ResultPermissionDenied);
145 R_RETURN(m_nvnflinger->GetSystemBufferManager().WriteAppletCaptureBuffer( 150 R_RETURN(m_surface_flinger->GetSystemBufferManager().WriteAppletCaptureBuffer(
146 out_was_written, out_fbshare_layer_index)); 151 out_was_written, out_fbshare_layer_index));
147} 152}
148 153
diff --git a/src/core/hle/service/am/display_layer_manager.h b/src/core/hle/service/am/display_layer_manager.h
index 45023a88c..92ab9399f 100644
--- a/src/core/hle/service/am/display_layer_manager.h
+++ b/src/core/hle/service/am/display_layer_manager.h
@@ -9,6 +9,10 @@
9#include "core/hle/result.h" 9#include "core/hle/result.h"
10#include "core/hle/service/am/am_types.h" 10#include "core/hle/service/am/am_types.h"
11 11
12namespace Core {
13class System;
14}
15
12namespace Kernel { 16namespace Kernel {
13class KProcess; 17class KProcess;
14} 18}
@@ -24,8 +28,8 @@ public:
24 explicit DisplayLayerManager(); 28 explicit DisplayLayerManager();
25 ~DisplayLayerManager(); 29 ~DisplayLayerManager();
26 30
27 void Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process, 31 void Initialize(Core::System& system, Kernel::KProcess* process, AppletId applet_id,
28 AppletId applet_id, LibraryAppletMode mode); 32 LibraryAppletMode mode);
29 void Finalize(); 33 void Finalize();
30 34
31 Result CreateManagedDisplayLayer(u64* out_layer); 35 Result CreateManagedDisplayLayer(u64* out_layer);
@@ -42,7 +46,7 @@ public:
42 46
43private: 47private:
44 Kernel::KProcess* m_process{}; 48 Kernel::KProcess* m_process{};
45 Nvnflinger::Nvnflinger* m_nvnflinger{}; 49 std::shared_ptr<Nvnflinger::Nvnflinger> m_surface_flinger{};
46 std::set<u64> m_managed_display_layers{}; 50 std::set<u64> m_managed_display_layers{};
47 std::set<u64> m_managed_display_recording_layers{}; 51 std::set<u64> m_managed_display_recording_layers{};
48 u64 m_system_shared_buffer_id{}; 52 u64 m_system_shared_buffer_id{};
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 @@
10 10
11namespace Service::AM { 11namespace Service::AM {
12 12
13IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_, 13IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_)
14 Nvnflinger::Nvnflinger& nvnflinger) 14 : ServiceFramework{system_, "appletAE"} {
15 : ServiceFramework{system_, "appletAE"}, m_nvnflinger{nvnflinger} {
16 // clang-format off 15 // clang-format off
17 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
18 {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"}, 17 {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"},
@@ -37,8 +36,8 @@ Result IAllSystemAppletProxiesService::OpenSystemAppletProxy(
37 LOG_DEBUG(Service_AM, "called"); 36 LOG_DEBUG(Service_AM, "called");
38 37
39 if (const auto applet = this->GetAppletFromProcessId(pid); applet) { 38 if (const auto applet = this->GetAppletFromProcessId(pid); applet) {
40 *out_system_applet_proxy = std::make_shared<ISystemAppletProxy>( 39 *out_system_applet_proxy =
41 system, applet, process_handle.Get(), m_nvnflinger); 40 std::make_shared<ISystemAppletProxy>(system, applet, process_handle.Get());
42 R_SUCCEED(); 41 R_SUCCEED();
43 } else { 42 } else {
44 UNIMPLEMENTED(); 43 UNIMPLEMENTED();
@@ -53,8 +52,8 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxy(
53 LOG_DEBUG(Service_AM, "called"); 52 LOG_DEBUG(Service_AM, "called");
54 53
55 if (const auto applet = this->GetAppletFromProcessId(pid); applet) { 54 if (const auto applet = this->GetAppletFromProcessId(pid); applet) {
56 *out_library_applet_proxy = std::make_shared<ILibraryAppletProxy>( 55 *out_library_applet_proxy =
57 system, applet, process_handle.Get(), m_nvnflinger); 56 std::make_shared<ILibraryAppletProxy>(system, applet, process_handle.Get());
58 R_SUCCEED(); 57 R_SUCCEED();
59 } else { 58 } else {
60 UNIMPLEMENTED(); 59 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 @@
8 8
9namespace Service { 9namespace Service {
10 10
11namespace Nvnflinger {
12class Nvnflinger;
13}
14
15namespace AM { 11namespace AM {
16 12
17struct Applet; 13struct Applet;
@@ -22,8 +18,7 @@ class ISystemAppletProxy;
22class IAllSystemAppletProxiesService final 18class IAllSystemAppletProxiesService final
23 : public ServiceFramework<IAllSystemAppletProxiesService> { 19 : public ServiceFramework<IAllSystemAppletProxiesService> {
24public: 20public:
25 explicit IAllSystemAppletProxiesService(Core::System& system_, 21 explicit IAllSystemAppletProxiesService(Core::System& system_);
26 Nvnflinger::Nvnflinger& nvnflinger);
27 ~IAllSystemAppletProxiesService() override; 22 ~IAllSystemAppletProxiesService() override;
28 23
29private: 24private:
@@ -40,7 +35,6 @@ private:
40 35
41private: 36private:
42 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid); 37 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);
43 Nvnflinger::Nvnflinger& m_nvnflinger;
44}; 38};
45 39
46} // namespace AM 40} // namespace AM
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 @@
17namespace Service::AM { 17namespace Service::AM {
18 18
19IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet, 19IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet,
20 Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger) 20 Kernel::KProcess* process)
21 : ServiceFramework{system_, "IApplicationProxy"}, 21 : ServiceFramework{system_, "IApplicationProxy"}, m_process{process}, m_applet{
22 m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} { 22 std::move(applet)} {
23 // clang-format off 23 // clang-format off
24 static const FunctionInfo functions[] = { 24 static const FunctionInfo functions[] = {
25 {0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, 25 {0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -77,8 +77,7 @@ Result IApplicationProxy::GetWindowController(
77Result IApplicationProxy::GetSelfController( 77Result IApplicationProxy::GetSelfController(
78 Out<SharedPointer<ISelfController>> out_self_controller) { 78 Out<SharedPointer<ISelfController>> out_self_controller) {
79 LOG_DEBUG(Service_AM, "called"); 79 LOG_DEBUG(Service_AM, "called");
80 *out_self_controller = 80 *out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process);
81 std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger);
82 R_SUCCEED(); 81 R_SUCCEED();
83} 82}
84 83
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;
22class IApplicationProxy final : public ServiceFramework<IApplicationProxy> { 22class IApplicationProxy final : public ServiceFramework<IApplicationProxy> {
23public: 23public:
24 explicit IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet, 24 explicit IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet,
25 Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); 25 Kernel::KProcess* process);
26 ~IApplicationProxy(); 26 ~IApplicationProxy();
27 27
28private: 28private:
@@ -40,7 +40,6 @@ private:
40 Out<SharedPointer<IApplicationFunctions>> out_application_functions); 40 Out<SharedPointer<IApplicationFunctions>> out_application_functions);
41 41
42private: 42private:
43 Nvnflinger::Nvnflinger& m_nvnflinger;
44 Kernel::KProcess* const m_process; 43 Kernel::KProcess* const m_process;
45 const std::shared_ptr<Applet> m_applet; 44 const std::shared_ptr<Applet> m_applet;
46}; 45};
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 @@
10 10
11namespace Service::AM { 11namespace Service::AM {
12 12
13IApplicationProxyService::IApplicationProxyService(Core::System& system_, 13IApplicationProxyService::IApplicationProxyService(Core::System& system_)
14 Nvnflinger::Nvnflinger& nvnflinger) 14 : ServiceFramework{system_, "appletOE"} {
15 : ServiceFramework{system_, "appletOE"}, m_nvnflinger{nvnflinger} {
16 static const FunctionInfo functions[] = { 15 static const FunctionInfo functions[] = {
17 {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"}, 16 {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"},
18 }; 17 };
@@ -28,7 +27,7 @@ Result IApplicationProxyService::OpenApplicationProxy(
28 27
29 if (const auto applet = this->GetAppletFromProcessId(pid)) { 28 if (const auto applet = this->GetAppletFromProcessId(pid)) {
30 *out_application_proxy = 29 *out_application_proxy =
31 std::make_shared<IApplicationProxy>(system, applet, process_handle.Get(), m_nvnflinger); 30 std::make_shared<IApplicationProxy>(system, applet, process_handle.Get());
32 R_SUCCEED(); 31 R_SUCCEED();
33 } else { 32 } else {
34 UNIMPLEMENTED(); 33 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 @@
8 8
9namespace Service { 9namespace Service {
10 10
11namespace Nvnflinger {
12class Nvnflinger;
13}
14
15namespace AM { 11namespace AM {
16 12
17struct Applet; 13struct Applet;
@@ -19,7 +15,7 @@ class IApplicationProxy;
19 15
20class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> { 16class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> {
21public: 17public:
22 explicit IApplicationProxyService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger); 18 explicit IApplicationProxyService(Core::System& system_);
23 ~IApplicationProxyService() override; 19 ~IApplicationProxyService() override;
24 20
25private: 21private:
@@ -28,7 +24,6 @@ private:
28 24
29private: 25private:
30 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid); 26 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);
31 Nvnflinger::Nvnflinger& m_nvnflinger;
32}; 27};
33 28
34} // namespace AM 29} // namespace AM
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 @@
19namespace Service::AM { 19namespace Service::AM {
20 20
21ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, 21ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
22 Kernel::KProcess* process, 22 Kernel::KProcess* process)
23 Nvnflinger::Nvnflinger& nvnflinger) 23 : ServiceFramework{system_, "ILibraryAppletProxy"}, m_process{process}, m_applet{
24 : ServiceFramework{system_, "ILibraryAppletProxy"}, 24 std::move(applet)} {
25 m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} {
26 // clang-format off 25 // clang-format off
27 static const FunctionInfo functions[] = { 26 static const FunctionInfo functions[] = {
28 {0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, 27 {0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -83,8 +82,7 @@ Result ILibraryAppletProxy::GetWindowController(
83Result ILibraryAppletProxy::GetSelfController( 82Result ILibraryAppletProxy::GetSelfController(
84 Out<SharedPointer<ISelfController>> out_self_controller) { 83 Out<SharedPointer<ISelfController>> out_self_controller) {
85 LOG_DEBUG(Service_AM, "called"); 84 LOG_DEBUG(Service_AM, "called");
86 *out_self_controller = 85 *out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process);
87 std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger);
88 R_SUCCEED(); 86 R_SUCCEED();
89} 87}
90 88
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;
25class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> { 25class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> {
26public: 26public:
27 explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, 27 explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
28 Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); 28 Kernel::KProcess* process);
29 ~ILibraryAppletProxy(); 29 ~ILibraryAppletProxy();
30 30
31private: 31private:
@@ -47,7 +47,6 @@ private:
47 Result GetGlobalStateController( 47 Result GetGlobalStateController(
48 Out<SharedPointer<IGlobalStateController>> out_global_state_controller); 48 Out<SharedPointer<IGlobalStateController>> out_global_state_controller);
49 49
50 Nvnflinger::Nvnflinger& m_nvnflinger;
51 Kernel::KProcess* const m_process; 50 Kernel::KProcess* const m_process;
52 const std::shared_ptr<Applet> m_applet; 51 const std::shared_ptr<Applet> m_applet;
53}; 52};
diff --git a/src/core/hle/service/am/service/self_controller.cpp b/src/core/hle/service/am/service/self_controller.cpp
index 6b77e423a..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 @@
15namespace Service::AM { 15namespace Service::AM {
16 16
17ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet> applet, 17ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet> applet,
18 Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger) 18 Kernel::KProcess* process)
19 : ServiceFramework{system_, "ISelfController"}, m_nvnflinger{nvnflinger}, m_process{process}, 19 : ServiceFramework{system_, "ISelfController"}, m_process{process}, m_applet{
20 m_applet{std::move(applet)} { 20 std::move(applet)} {
21 // clang-format off 21 // clang-format off
22 static const FunctionInfo functions[] = { 22 static const FunctionInfo functions[] = {
23 {0, D<&ISelfController::Exit>, "Exit"}, 23 {0, D<&ISelfController::Exit>, "Exit"},
@@ -74,7 +74,7 @@ ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet>
74 RegisterHandlers(functions); 74 RegisterHandlers(functions);
75 75
76 std::scoped_lock lk{m_applet->lock}; 76 std::scoped_lock lk{m_applet->lock};
77 m_applet->display_layer_manager.Initialize(&m_nvnflinger, m_process, m_applet->applet_id, 77 m_applet->display_layer_manager.Initialize(system, m_process, m_applet->applet_id,
78 m_applet->library_applet_mode); 78 m_applet->library_applet_mode);
79} 79}
80 80
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;
23class ISelfController final : public ServiceFramework<ISelfController> { 23class ISelfController final : public ServiceFramework<ISelfController> {
24public: 24public:
25 explicit ISelfController(Core::System& system_, std::shared_ptr<Applet> applet, 25 explicit ISelfController(Core::System& system_, std::shared_ptr<Applet> applet,
26 Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); 26 Kernel::KProcess* process);
27 ~ISelfController() override; 27 ~ISelfController() override;
28 28
29private: 29private:
@@ -64,7 +64,6 @@ private:
64 Result SaveCurrentScreenshot(Capture::AlbumReportOption album_report_option); 64 Result SaveCurrentScreenshot(Capture::AlbumReportOption album_report_option);
65 Result SetRecordVolumeMuted(bool muted); 65 Result SetRecordVolumeMuted(bool muted);
66 66
67 Nvnflinger::Nvnflinger& m_nvnflinger;
68 Kernel::KProcess* const m_process; 67 Kernel::KProcess* const m_process;
69 const std::shared_ptr<Applet> m_applet; 68 const std::shared_ptr<Applet> m_applet;
70}; 69};
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 @@
19namespace Service::AM { 19namespace Service::AM {
20 20
21ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, 21ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
22 Kernel::KProcess* process, 22 Kernel::KProcess* process)
23 Nvnflinger::Nvnflinger& nvnflinger) 23 : ServiceFramework{system_, "ISystemAppletProxy"}, m_process{process}, m_applet{
24 : ServiceFramework{system_, "ISystemAppletProxy"}, 24 std::move(applet)} {
25 m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} {
26 // clang-format off 25 // clang-format off
27 static const FunctionInfo functions[] = { 26 static const FunctionInfo functions[] = {
28 {0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, 27 {0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -83,8 +82,7 @@ Result ISystemAppletProxy::GetWindowController(
83Result ISystemAppletProxy::GetSelfController( 82Result ISystemAppletProxy::GetSelfController(
84 Out<SharedPointer<ISelfController>> out_self_controller) { 83 Out<SharedPointer<ISelfController>> out_self_controller) {
85 LOG_DEBUG(Service_AM, "called"); 84 LOG_DEBUG(Service_AM, "called");
86 *out_self_controller = 85 *out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process);
87 std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger);
88 R_SUCCEED(); 86 R_SUCCEED();
89} 87}
90 88
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;
25class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> { 25class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> {
26public: 26public:
27 explicit ISystemAppletProxy(Core::System& system, std::shared_ptr<Applet> applet, 27 explicit ISystemAppletProxy(Core::System& system, std::shared_ptr<Applet> applet,
28 Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger); 28 Kernel::KProcess* process);
29 ~ISystemAppletProxy(); 29 ~ISystemAppletProxy();
30 30
31private: 31private:
@@ -46,7 +46,6 @@ private:
46 Result GetGlobalStateController( 46 Result GetGlobalStateController(
47 Out<SharedPointer<IGlobalStateController>> out_global_state_controller); 47 Out<SharedPointer<IGlobalStateController>> out_global_state_controller);
48 48
49 Nvnflinger::Nvnflinger& m_nvnflinger;
50 Kernel::KProcess* const m_process; 49 Kernel::KProcess* const m_process;
51 const std::shared_ptr<Applet> m_applet; 50 const std::shared_ptr<Applet> m_applet;
52}; 51};
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp
index cb256e5b4..03eb507b9 100644
--- a/src/core/hle/service/nvdrv/nvdrv.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv.cpp
@@ -42,7 +42,7 @@ void EventInterface::FreeEvent(Kernel::KEvent* event) {
42 module.service_context.CloseEvent(event); 42 module.service_context.CloseEvent(event);
43} 43}
44 44
45void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) { 45void LoopProcess(Core::System& system) {
46 auto server_manager = std::make_unique<ServerManager>(system); 46 auto server_manager = std::make_unique<ServerManager>(system);
47 auto module = std::make_shared<Module>(system); 47 auto module = std::make_shared<Module>(system);
48 const auto NvdrvInterfaceFactoryForApplication = [&, module] { 48 const auto NvdrvInterfaceFactoryForApplication = [&, module] {
@@ -62,7 +62,6 @@ void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) {
62 server_manager->RegisterNamedService("nvdrv:s", NvdrvInterfaceFactoryForSysmodules); 62 server_manager->RegisterNamedService("nvdrv:s", NvdrvInterfaceFactoryForSysmodules);
63 server_manager->RegisterNamedService("nvdrv:t", NvdrvInterfaceFactoryForTesting); 63 server_manager->RegisterNamedService("nvdrv:t", NvdrvInterfaceFactoryForTesting);
64 server_manager->RegisterNamedService("nvmemp", std::make_shared<NVMEMP>(system)); 64 server_manager->RegisterNamedService("nvmemp", std::make_shared<NVMEMP>(system));
65 nvnflinger.SetNVDrvInstance(module);
66 ServerManager::RunServer(std::move(server_manager)); 65 ServerManager::RunServer(std::move(server_manager));
67} 66}
68 67
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h
index c594f0e5e..154c38951 100644
--- a/src/core/hle/service/nvdrv/nvdrv.h
+++ b/src/core/hle/service/nvdrv/nvdrv.h
@@ -118,6 +118,6 @@ private:
118 std::unordered_map<std::string, std::function<FilesContainerType::iterator(DeviceFD)>> builders; 118 std::unordered_map<std::string, std::function<FilesContainerType::iterator(DeviceFD)>> builders;
119}; 119};
120 120
121void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system); 121void LoopProcess(Core::System& system);
122 122
123} // namespace Service::Nvidia 123} // namespace Service::Nvidia
diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.cpp b/src/core/hle/service/nvdrv/nvdrv_interface.cpp
index ffe72f281..241006cc8 100644
--- a/src/core/hle/service/nvdrv/nvdrv_interface.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv_interface.cpp
@@ -263,8 +263,10 @@ NVDRV::NVDRV(Core::System& system_, std::shared_ptr<Module> nvdrv_, const char*
263} 263}
264 264
265NVDRV::~NVDRV() { 265NVDRV::~NVDRV() {
266 auto& container = nvdrv->GetContainer(); 266 if (is_initialized) {
267 container.CloseSession(session_id); 267 auto& container = nvdrv->GetContainer();
268 container.CloseSession(session_id);
269 }
268} 270}
269 271
270} // namespace Service::Nvidia 272} // namespace Service::Nvidia
diff --git a/src/core/hle/service/nvdrv/nvdrv_interface.h b/src/core/hle/service/nvdrv/nvdrv_interface.h
index f2195ae1e..c72f92597 100644
--- a/src/core/hle/service/nvdrv/nvdrv_interface.h
+++ b/src/core/hle/service/nvdrv/nvdrv_interface.h
@@ -16,6 +16,10 @@ public:
16 explicit NVDRV(Core::System& system_, std::shared_ptr<Module> nvdrv_, const char* name); 16 explicit NVDRV(Core::System& system_, std::shared_ptr<Module> nvdrv_, const char* name);
17 ~NVDRV() override; 17 ~NVDRV() override;
18 18
19 std::shared_ptr<Module> GetModule() const {
20 return nvdrv;
21 }
22
19private: 23private:
20 void Open(HLERequestContext& ctx); 24 void Open(HLERequestContext& ctx);
21 void Ioctl1(HLERequestContext& ctx); 25 void Ioctl1(HLERequestContext& ctx);
diff --git a/src/core/hle/service/vi/hos_binder_driver.cpp b/src/core/hle/service/nvnflinger/hos_binder_driver.cpp
index ba0317245..e09d72047 100644
--- a/src/core/hle/service/vi/hos_binder_driver.cpp
+++ b/src/core/hle/service/nvnflinger/hos_binder_driver.cpp
@@ -3,13 +3,16 @@
3 3
4#include "core/hle/service/cmif_serialization.h" 4#include "core/hle/service/cmif_serialization.h"
5#include "core/hle/service/nvnflinger/binder.h" 5#include "core/hle/service/nvnflinger/binder.h"
6#include "core/hle/service/nvnflinger/hos_binder_driver.h"
6#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" 7#include "core/hle/service/nvnflinger/hos_binder_driver_server.h"
7#include "core/hle/service/vi/hos_binder_driver.h"
8 8
9namespace Service::VI { 9namespace Service::Nvnflinger {
10 10
11IHOSBinderDriver::IHOSBinderDriver(Core::System& system_, Nvnflinger::HosBinderDriverServer& server) 11IHOSBinderDriver::IHOSBinderDriver(Core::System& system_,
12 : ServiceFramework{system_, "IHOSBinderDriver"}, m_server(server) { 12 std::shared_ptr<HosBinderDriverServer> server,
13 std::shared_ptr<Nvnflinger> surface_flinger)
14 : ServiceFramework{system_, "IHOSBinderDriver"}, m_server(server),
15 m_surface_flinger(surface_flinger) {
13 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
14 {0, C<&IHOSBinderDriver::TransactParcel>, "TransactParcel"}, 17 {0, C<&IHOSBinderDriver::TransactParcel>, "TransactParcel"},
15 {1, C<&IHOSBinderDriver::AdjustRefcount>, "AdjustRefcount"}, 18 {1, C<&IHOSBinderDriver::AdjustRefcount>, "AdjustRefcount"},
@@ -27,7 +30,7 @@ Result IHOSBinderDriver::TransactParcel(s32 binder_id, android::TransactionId tr
27 u32 flags) { 30 u32 flags) {
28 LOG_DEBUG(Service_VI, "called. id={} transaction={}, flags={}", binder_id, transaction_id, 31 LOG_DEBUG(Service_VI, "called. id={} transaction={}, flags={}", binder_id, transaction_id,
29 flags); 32 flags);
30 m_server.TryGetProducer(binder_id)->Transact(transaction_id, flags, parcel_data, parcel_reply); 33 m_server->TryGetProducer(binder_id)->Transact(transaction_id, flags, parcel_data, parcel_reply);
31 R_SUCCEED(); 34 R_SUCCEED();
32} 35}
33 36
@@ -39,7 +42,7 @@ Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) {
39Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id, 42Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id,
40 OutCopyHandle<Kernel::KReadableEvent> out_handle) { 43 OutCopyHandle<Kernel::KReadableEvent> out_handle) {
41 LOG_WARNING(Service_VI, "(STUBBED) called id={}, type_id={}", binder_id, type_id); 44 LOG_WARNING(Service_VI, "(STUBBED) called id={}, type_id={}", binder_id, type_id);
42 *out_handle = &m_server.TryGetProducer(binder_id)->GetNativeHandle(); 45 *out_handle = &m_server->TryGetProducer(binder_id)->GetNativeHandle();
43 R_SUCCEED(); 46 R_SUCCEED();
44} 47}
45 48
@@ -50,4 +53,4 @@ Result IHOSBinderDriver::TransactParcelAuto(s32 binder_id, android::TransactionI
50 R_RETURN(this->TransactParcel(binder_id, transaction_id, parcel_data, parcel_reply, flags)); 53 R_RETURN(this->TransactParcel(binder_id, transaction_id, parcel_data, parcel_reply, flags));
51} 54}
52 55
53} // namespace Service::VI 56} // namespace Service::Nvnflinger
diff --git a/src/core/hle/service/vi/hos_binder_driver.h b/src/core/hle/service/nvnflinger/hos_binder_driver.h
index ed6e8cdbe..aa9e3121a 100644
--- a/src/core/hle/service/vi/hos_binder_driver.h
+++ b/src/core/hle/service/nvnflinger/hos_binder_driver.h
@@ -5,13 +5,21 @@
5#include "core/hle/service/nvnflinger/binder.h" 5#include "core/hle/service/nvnflinger/binder.h"
6#include "core/hle/service/service.h" 6#include "core/hle/service/service.h"
7 7
8namespace Service::VI { 8namespace Service::Nvnflinger {
9
10class HosBinderDriverServer;
11class Nvnflinger;
9 12
10class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> { 13class IHOSBinderDriver final : public ServiceFramework<IHOSBinderDriver> {
11public: 14public:
12 explicit IHOSBinderDriver(Core::System& system_, Nvnflinger::HosBinderDriverServer& server); 15 explicit IHOSBinderDriver(Core::System& system_, std::shared_ptr<HosBinderDriverServer> server,
16 std::shared_ptr<Nvnflinger> surface_flinger);
13 ~IHOSBinderDriver() override; 17 ~IHOSBinderDriver() override;
14 18
19 std::shared_ptr<Nvnflinger> GetSurfaceFlinger() {
20 return m_surface_flinger;
21 }
22
15private: 23private:
16 Result TransactParcel(s32 binder_id, android::TransactionId transaction_id, 24 Result TransactParcel(s32 binder_id, android::TransactionId transaction_id,
17 InBuffer<BufferAttr_HipcMapAlias> parcel_data, 25 InBuffer<BufferAttr_HipcMapAlias> parcel_data,
@@ -24,7 +32,8 @@ private:
24 OutBuffer<BufferAttr_HipcAutoSelect> parcel_reply, u32 flags); 32 OutBuffer<BufferAttr_HipcAutoSelect> parcel_reply, u32 flags);
25 33
26private: 34private:
27 Nvnflinger::HosBinderDriverServer& m_server; 35 const std::shared_ptr<HosBinderDriverServer> m_server;
36 const std::shared_ptr<Nvnflinger> m_surface_flinger;
28}; 37};
29 38
30} // namespace Service::VI 39} // namespace Service::Nvnflinger
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.cpp b/src/core/hle/service/nvnflinger/nvnflinger.cpp
index 687ccc9f9..cd8062a2b 100644
--- a/src/core/hle/service/nvnflinger/nvnflinger.cpp
+++ b/src/core/hle/service/nvnflinger/nvnflinger.cpp
@@ -1,33 +1,24 @@
1// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later 2// SPDX-License-Identifier: GPL-3.0-or-later
3 3
4#include <algorithm>
5#include <optional>
6
7#include "common/assert.h"
8#include "common/logging/log.h"
9#include "common/microprofile.h" 4#include "common/microprofile.h"
10#include "common/scope_exit.h" 5#include "common/scope_exit.h"
11#include "common/settings.h" 6#include "common/settings.h"
12#include "common/thread.h"
13#include "core/core.h" 7#include "core/core.h"
14#include "core/core_timing.h" 8#include "core/core_timing.h"
15#include "core/hle/kernel/k_readable_event.h"
16#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" 9#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
17#include "core/hle/service/nvdrv/nvdrv.h" 10#include "core/hle/service/nvdrv/nvdrv.h"
18#include "core/hle/service/nvnflinger/buffer_item_consumer.h" 11#include "core/hle/service/nvdrv/nvdrv_interface.h"
19#include "core/hle/service/nvnflinger/buffer_queue_core.h"
20#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" 12#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
21#include "core/hle/service/nvnflinger/hardware_composer.h" 13#include "core/hle/service/nvnflinger/hardware_composer.h"
14#include "core/hle/service/nvnflinger/hos_binder_driver.h"
22#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" 15#include "core/hle/service/nvnflinger/hos_binder_driver_server.h"
23#include "core/hle/service/nvnflinger/nvnflinger.h" 16#include "core/hle/service/nvnflinger/nvnflinger.h"
24#include "core/hle/service/nvnflinger/ui/graphic_buffer.h" 17#include "core/hle/service/server_manager.h"
18#include "core/hle/service/sm/sm.h"
25#include "core/hle/service/vi/display/vi_display.h" 19#include "core/hle/service/vi/display/vi_display.h"
26#include "core/hle/service/vi/layer/vi_layer.h" 20#include "core/hle/service/vi/layer/vi_layer.h"
27#include "core/hle/service/vi/vi_results.h" 21#include "core/hle/service/vi/vi_results.h"
28#include "video_core/gpu.h"
29#include "video_core/host1x/host1x.h"
30#include "video_core/host1x/syncpoint_manager.h"
31 22
32namespace Service::Nvnflinger { 23namespace Service::Nvnflinger {
33 24
@@ -47,6 +38,11 @@ void Nvnflinger::SplitVSync(std::stop_token stop_token) {
47 while (!stop_token.stop_requested()) { 38 while (!stop_token.stop_requested()) {
48 vsync_signal.Wait(); 39 vsync_signal.Wait();
49 40
41 if (system.IsShuttingDown()) {
42 ShutdownLayers();
43 return;
44 }
45
50 const auto lock_guard = Lock(); 46 const auto lock_guard = Lock();
51 47
52 if (!is_abandoned) { 48 if (!is_abandoned) {
@@ -65,6 +61,9 @@ Nvnflinger::Nvnflinger(Core::System& system_, HosBinderDriverServer& hos_binder_
65 displays.emplace_back(4, "Null", hos_binder_driver_server, service_context, system); 61 displays.emplace_back(4, "Null", hos_binder_driver_server, service_context, system);
66 guard = std::make_shared<std::mutex>(); 62 guard = std::make_shared<std::mutex>();
67 63
64 nvdrv = system.ServiceManager().GetService<Nvidia::NVDRV>("nvdrv:s", true)->GetModule();
65 disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {});
66
68 // Schedule the screen composition events 67 // Schedule the screen composition events
69 multi_composition_event = Core::Timing::CreateEvent( 68 multi_composition_event = Core::Timing::CreateEvent(
70 "ScreenComposition", 69 "ScreenComposition",
@@ -110,22 +109,12 @@ Nvnflinger::~Nvnflinger() {
110 109
111void Nvnflinger::ShutdownLayers() { 110void Nvnflinger::ShutdownLayers() {
112 // Abandon consumers. 111 // Abandon consumers.
113 { 112 const auto lock_guard = Lock();
114 const auto lock_guard = Lock(); 113 for (auto& display : displays) {
115 for (auto& display : displays) { 114 display.Abandon();
116 display.Abandon();
117 }
118
119 is_abandoned = true;
120 } 115 }
121 116
122 // Join the vsync thread, if it exists. 117 is_abandoned = true;
123 vsync_thread = {};
124}
125
126void Nvnflinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) {
127 nvdrv = std::move(instance);
128 disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {});
129} 118}
130 119
131std::optional<u64> Nvnflinger::OpenDisplay(std::string_view name) { 120std::optional<u64> Nvnflinger::OpenDisplay(std::string_view name) {
@@ -332,4 +321,14 @@ FbShareBufferManager& Nvnflinger::GetSystemBufferManager() {
332 return *system_buffer_manager; 321 return *system_buffer_manager;
333} 322}
334 323
324void LoopProcess(Core::System& system) {
325 const auto binder_server = std::make_shared<HosBinderDriverServer>(system);
326 const auto surface_flinger = std::make_shared<Nvnflinger>(system, *binder_server);
327
328 auto server_manager = std::make_unique<ServerManager>(system);
329 server_manager->RegisterNamedService(
330 "dispdrv", std::make_shared<IHOSBinderDriver>(system, binder_server, surface_flinger));
331 ServerManager::RunServer(std::move(server_manager));
332}
333
335} // namespace Service::Nvnflinger 334} // namespace Service::Nvnflinger
diff --git a/src/core/hle/service/nvnflinger/nvnflinger.h b/src/core/hle/service/nvnflinger/nvnflinger.h
index 4cf4f069d..5ed7dc317 100644
--- a/src/core/hle/service/nvnflinger/nvnflinger.h
+++ b/src/core/hle/service/nvnflinger/nvnflinger.h
@@ -8,7 +8,6 @@
8#include <mutex> 8#include <mutex>
9#include <optional> 9#include <optional>
10#include <thread> 10#include <thread>
11#include <vector>
12 11
13#include "common/common_types.h" 12#include "common/common_types.h"
14#include "common/polyfill_thread.h" 13#include "common/polyfill_thread.h"
@@ -57,9 +56,6 @@ public:
57 56
58 void ShutdownLayers(); 57 void ShutdownLayers();
59 58
60 /// Sets the NVDrv module instance to use to send buffers to the GPU.
61 void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance);
62
63 /// Opens the specified display and returns the ID. 59 /// Opens the specified display and returns the ID.
64 /// 60 ///
65 /// If an invalid display name is provided, then an empty optional is returned. 61 /// If an invalid display name is provided, then an empty optional is returned.
@@ -169,4 +165,6 @@ private:
169 HosBinderDriverServer& hos_binder_driver_server; 165 HosBinderDriverServer& hos_binder_driver_server;
170}; 166};
171 167
168void LoopProcess(Core::System& system);
169
172} // namespace Service::Nvnflinger 170} // namespace Service::Nvnflinger
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index fbdf217ba..0718df981 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -49,7 +49,6 @@
49#include "core/hle/service/npns/npns.h" 49#include "core/hle/service/npns/npns.h"
50#include "core/hle/service/ns/ns.h" 50#include "core/hle/service/ns/ns.h"
51#include "core/hle/service/nvdrv/nvdrv.h" 51#include "core/hle/service/nvdrv/nvdrv.h"
52#include "core/hle/service/nvnflinger/hos_binder_driver_server.h"
53#include "core/hle/service/nvnflinger/nvnflinger.h" 52#include "core/hle/service/nvnflinger/nvnflinger.h"
54#include "core/hle/service/olsc/olsc.h" 53#include "core/hle/service/olsc/olsc.h"
55#include "core/hle/service/omm/omm.h" 54#include "core/hle/service/omm/omm.h"
@@ -210,14 +209,9 @@ Result ServiceFrameworkBase::HandleSyncRequest(Kernel::KServerSession& session,
210} 209}
211 210
212/// Initialize Services 211/// Initialize Services
213Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system) 212Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system) {
214 : hos_binder_driver_server{std::make_unique<Nvnflinger::HosBinderDriverServer>(system)},
215 nv_flinger{std::make_unique<Nvnflinger::Nvnflinger>(system, *hos_binder_driver_server)} {
216
217 auto& kernel = system.Kernel(); 213 auto& kernel = system.Kernel();
218 214
219 // Nvnflinger needs to be accessed by several services like Vi and AppletOE so we instantiate it
220 // here and pass it into the respective InstallInterfaces functions.
221 system.GetFileSystemController().CreateFactories(*system.GetFilesystem(), false); 215 system.GetFileSystemController().CreateFactories(*system.GetFilesystem(), false);
222 216
223 // clang-format off 217 // clang-format off
@@ -226,13 +220,14 @@ Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system
226 kernel.RunOnHostCoreProcess("jit", [&] { JIT::LoopProcess(system); }).detach(); 220 kernel.RunOnHostCoreProcess("jit", [&] { JIT::LoopProcess(system); }).detach();
227 kernel.RunOnHostCoreProcess("ldn", [&] { LDN::LoopProcess(system); }).detach(); 221 kernel.RunOnHostCoreProcess("ldn", [&] { LDN::LoopProcess(system); }).detach();
228 kernel.RunOnHostCoreProcess("Loader", [&] { LDR::LoopProcess(system); }).detach(); 222 kernel.RunOnHostCoreProcess("Loader", [&] { LDR::LoopProcess(system); }).detach();
229 kernel.RunOnHostCoreProcess("nvservices", [&] { Nvidia::LoopProcess(*nv_flinger, system); }).detach(); 223 kernel.RunOnHostCoreProcess("nvservices", [&] { Nvidia::LoopProcess(system); }).detach();
230 kernel.RunOnHostCoreProcess("bsdsocket", [&] { Sockets::LoopProcess(system); }).detach(); 224 kernel.RunOnHostCoreProcess("bsdsocket", [&] { Sockets::LoopProcess(system); }).detach();
231 kernel.RunOnHostCoreProcess("vi", [&] { VI::LoopProcess(system, *nv_flinger, *hos_binder_driver_server); }).detach(); 225 kernel.RunOnHostCoreProcess("vi", [&] { VI::LoopProcess(system); }).detach();
226 kernel.RunOnHostCoreProcess("nvnflinger", [&] { Nvnflinger::LoopProcess(system); }).detach();
232 227
233 kernel.RunOnGuestCoreProcess("sm", [&] { SM::LoopProcess(system); }); 228 kernel.RunOnGuestCoreProcess("sm", [&] { SM::LoopProcess(system); });
234 kernel.RunOnGuestCoreProcess("account", [&] { Account::LoopProcess(system); }); 229 kernel.RunOnGuestCoreProcess("account", [&] { Account::LoopProcess(system); });
235 kernel.RunOnGuestCoreProcess("am", [&] { AM::LoopProcess(*nv_flinger, system); }); 230 kernel.RunOnGuestCoreProcess("am", [&] { AM::LoopProcess(system); });
236 kernel.RunOnGuestCoreProcess("aoc", [&] { AOC::LoopProcess(system); }); 231 kernel.RunOnGuestCoreProcess("aoc", [&] { AOC::LoopProcess(system); });
237 kernel.RunOnGuestCoreProcess("apm", [&] { APM::LoopProcess(system); }); 232 kernel.RunOnGuestCoreProcess("apm", [&] { APM::LoopProcess(system); });
238 kernel.RunOnGuestCoreProcess("bcat", [&] { BCAT::LoopProcess(system); }); 233 kernel.RunOnGuestCoreProcess("bcat", [&] { BCAT::LoopProcess(system); });
@@ -246,7 +241,6 @@ Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system
246 kernel.RunOnGuestCoreProcess("fatal", [&] { Fatal::LoopProcess(system); }); 241 kernel.RunOnGuestCoreProcess("fatal", [&] { Fatal::LoopProcess(system); });
247 kernel.RunOnGuestCoreProcess("fgm", [&] { FGM::LoopProcess(system); }); 242 kernel.RunOnGuestCoreProcess("fgm", [&] { FGM::LoopProcess(system); });
248 kernel.RunOnGuestCoreProcess("friends", [&] { Friend::LoopProcess(system); }); 243 kernel.RunOnGuestCoreProcess("friends", [&] { Friend::LoopProcess(system); });
249 // glue depends on settings and psc, so they must come first
250 kernel.RunOnGuestCoreProcess("settings", [&] { Set::LoopProcess(system); }); 244 kernel.RunOnGuestCoreProcess("settings", [&] { Set::LoopProcess(system); });
251 kernel.RunOnGuestCoreProcess("psc", [&] { PSC::LoopProcess(system); }); 245 kernel.RunOnGuestCoreProcess("psc", [&] { PSC::LoopProcess(system); });
252 kernel.RunOnGuestCoreProcess("glue", [&] { Glue::LoopProcess(system); }); 246 kernel.RunOnGuestCoreProcess("glue", [&] { Glue::LoopProcess(system); });
@@ -283,8 +277,4 @@ Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system
283 277
284Services::~Services() = default; 278Services::~Services() = default;
285 279
286void Services::KillNVNFlinger() {
287 nv_flinger->ShutdownLayers();
288}
289
290} // namespace Service 280} // namespace Service
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index 22d1343d5..cf4a3e8be 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -28,11 +28,6 @@ namespace FileSystem {
28class FileSystemController; 28class FileSystemController;
29} 29}
30 30
31namespace Nvnflinger {
32class HosBinderDriverServer;
33class Nvnflinger;
34} // namespace Nvnflinger
35
36namespace SM { 31namespace SM {
37class ServiceManager; 32class ServiceManager;
38} 33}
@@ -244,12 +239,6 @@ class Services final {
244public: 239public:
245 explicit Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system); 240 explicit Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system);
246 ~Services(); 241 ~Services();
247
248 void KillNVNFlinger();
249
250private:
251 std::unique_ptr<Nvnflinger::HosBinderDriverServer> hos_binder_driver_server;
252 std::unique_ptr<Nvnflinger::Nvnflinger> nv_flinger;
253}; 242};
254 243
255} // namespace Service 244} // namespace Service
diff --git a/src/core/hle/service/vi/application_display_service.cpp b/src/core/hle/service/vi/application_display_service.cpp
index 78229e30f..a6e04bf60 100644
--- a/src/core/hle/service/vi/application_display_service.cpp
+++ b/src/core/hle/service/vi/application_display_service.cpp
@@ -2,10 +2,10 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/hle/service/cmif_serialization.h" 4#include "core/hle/service/cmif_serialization.h"
5#include "core/hle/service/nvnflinger/hos_binder_driver.h"
5#include "core/hle/service/nvnflinger/nvnflinger.h" 6#include "core/hle/service/nvnflinger/nvnflinger.h"
6#include "core/hle/service/nvnflinger/parcel.h" 7#include "core/hle/service/nvnflinger/parcel.h"
7#include "core/hle/service/vi/application_display_service.h" 8#include "core/hle/service/vi/application_display_service.h"
8#include "core/hle/service/vi/hos_binder_driver.h"
9#include "core/hle/service/vi/manager_display_service.h" 9#include "core/hle/service/vi/manager_display_service.h"
10#include "core/hle/service/vi/system_display_service.h" 10#include "core/hle/service/vi/system_display_service.h"
11#include "core/hle/service/vi/vi_results.h" 11#include "core/hle/service/vi/vi_results.h"
@@ -13,10 +13,10 @@
13namespace Service::VI { 13namespace Service::VI {
14 14
15IApplicationDisplayService::IApplicationDisplayService( 15IApplicationDisplayService::IApplicationDisplayService(
16 Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 16 Core::System& system_, std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service)
17 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) 17 : ServiceFramework{system_, "IApplicationDisplayService"},
18 : ServiceFramework{system_, "IApplicationDisplayService"}, m_nvnflinger{nvnflinger}, 18 m_binder_service{std::move(binder_service)},
19 m_hos_binder_driver_server{hos_binder_driver_server} { 19 m_surface_flinger{m_binder_service->GetSurfaceFlinger()} {
20 20
21 // clang-format off 21 // clang-format off
22 static const FunctionInfo functions[] = { 22 static const FunctionInfo functions[] = {
@@ -49,36 +49,37 @@ IApplicationDisplayService::IApplicationDisplayService(
49 49
50IApplicationDisplayService::~IApplicationDisplayService() { 50IApplicationDisplayService::~IApplicationDisplayService() {
51 for (const auto layer_id : m_stray_layer_ids) { 51 for (const auto layer_id : m_stray_layer_ids) {
52 m_nvnflinger.DestroyLayer(layer_id); 52 m_surface_flinger->DestroyLayer(layer_id);
53 } 53 }
54} 54}
55 55
56Result IApplicationDisplayService::GetRelayService( 56Result IApplicationDisplayService::GetRelayService(
57 Out<SharedPointer<IHOSBinderDriver>> out_relay_service) { 57 Out<SharedPointer<Nvnflinger::IHOSBinderDriver>> out_relay_service) {
58 LOG_WARNING(Service_VI, "(STUBBED) called"); 58 LOG_WARNING(Service_VI, "(STUBBED) called");
59 *out_relay_service = std::make_shared<IHOSBinderDriver>(system, m_hos_binder_driver_server); 59 *out_relay_service = m_binder_service;
60 R_SUCCEED(); 60 R_SUCCEED();
61} 61}
62 62
63Result IApplicationDisplayService::GetSystemDisplayService( 63Result IApplicationDisplayService::GetSystemDisplayService(
64 Out<SharedPointer<ISystemDisplayService>> out_system_display_service) { 64 Out<SharedPointer<ISystemDisplayService>> out_system_display_service) {
65 LOG_WARNING(Service_VI, "(STUBBED) called"); 65 LOG_WARNING(Service_VI, "(STUBBED) called");
66 *out_system_display_service = std::make_shared<ISystemDisplayService>(system, m_nvnflinger); 66 *out_system_display_service =
67 std::make_shared<ISystemDisplayService>(system, m_surface_flinger);
67 R_SUCCEED(); 68 R_SUCCEED();
68} 69}
69 70
70Result IApplicationDisplayService::GetManagerDisplayService( 71Result IApplicationDisplayService::GetManagerDisplayService(
71 Out<SharedPointer<IManagerDisplayService>> out_manager_display_service) { 72 Out<SharedPointer<IManagerDisplayService>> out_manager_display_service) {
72 LOG_WARNING(Service_VI, "(STUBBED) called"); 73 LOG_WARNING(Service_VI, "(STUBBED) called");
73 *out_manager_display_service = std::make_shared<IManagerDisplayService>(system, m_nvnflinger); 74 *out_manager_display_service =
75 std::make_shared<IManagerDisplayService>(system, m_surface_flinger);
74 R_SUCCEED(); 76 R_SUCCEED();
75} 77}
76 78
77Result IApplicationDisplayService::GetIndirectDisplayTransactionService( 79Result IApplicationDisplayService::GetIndirectDisplayTransactionService(
78 Out<SharedPointer<IHOSBinderDriver>> out_indirect_display_transaction_service) { 80 Out<SharedPointer<Nvnflinger::IHOSBinderDriver>> out_indirect_display_transaction_service) {
79 LOG_WARNING(Service_VI, "(STUBBED) called"); 81 LOG_WARNING(Service_VI, "(STUBBED) called");
80 *out_indirect_display_transaction_service = 82 *out_indirect_display_transaction_service = m_binder_service;
81 std::make_shared<IHOSBinderDriver>(system, m_hos_binder_driver_server);
82 R_SUCCEED(); 83 R_SUCCEED();
83} 84}
84 85
@@ -89,7 +90,7 @@ Result IApplicationDisplayService::OpenDisplay(Out<u64> out_display_id, DisplayN
89 ASSERT_MSG(strcmp(display_name.data(), "Default") == 0, 90 ASSERT_MSG(strcmp(display_name.data(), "Default") == 0,
90 "Non-default displays aren't supported yet"); 91 "Non-default displays aren't supported yet");
91 92
92 const auto display_id = m_nvnflinger.OpenDisplay(display_name.data()); 93 const auto display_id = m_surface_flinger->OpenDisplay(display_name.data());
93 if (!display_id) { 94 if (!display_id) {
94 LOG_ERROR(Service_VI, "Display not found! display_name={}", display_name.data()); 95 LOG_ERROR(Service_VI, "Display not found! display_name={}", display_name.data());
95 R_THROW(VI::ResultNotFound); 96 R_THROW(VI::ResultNotFound);
@@ -106,7 +107,7 @@ Result IApplicationDisplayService::OpenDefaultDisplay(Out<u64> out_display_id) {
106 107
107Result IApplicationDisplayService::CloseDisplay(u64 display_id) { 108Result IApplicationDisplayService::CloseDisplay(u64 display_id) {
108 LOG_DEBUG(Service_VI, "called"); 109 LOG_DEBUG(Service_VI, "called");
109 R_SUCCEED_IF(m_nvnflinger.CloseDisplay(display_id)); 110 R_SUCCEED_IF(m_surface_flinger->CloseDisplay(display_id));
110 R_THROW(ResultUnknown); 111 R_THROW(ResultUnknown);
111} 112}
112 113
@@ -168,19 +169,19 @@ Result IApplicationDisplayService::OpenLayer(Out<u64> out_size,
168 169
169 LOG_DEBUG(Service_VI, "called. layer_id={}, aruid={:#x}", layer_id, aruid.pid); 170 LOG_DEBUG(Service_VI, "called. layer_id={}, aruid={:#x}", layer_id, aruid.pid);
170 171
171 const auto display_id = m_nvnflinger.OpenDisplay(display_name.data()); 172 const auto display_id = m_surface_flinger->OpenDisplay(display_name.data());
172 if (!display_id) { 173 if (!display_id) {
173 LOG_ERROR(Service_VI, "Layer not found! layer_id={}", layer_id); 174 LOG_ERROR(Service_VI, "Layer not found! layer_id={}", layer_id);
174 R_THROW(VI::ResultNotFound); 175 R_THROW(VI::ResultNotFound);
175 } 176 }
176 177
177 const auto buffer_queue_id = m_nvnflinger.FindBufferQueueId(*display_id, layer_id); 178 const auto buffer_queue_id = m_surface_flinger->FindBufferQueueId(*display_id, layer_id);
178 if (!buffer_queue_id) { 179 if (!buffer_queue_id) {
179 LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", *display_id); 180 LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", *display_id);
180 R_THROW(VI::ResultNotFound); 181 R_THROW(VI::ResultNotFound);
181 } 182 }
182 183
183 if (!m_nvnflinger.OpenLayer(layer_id)) { 184 if (!m_surface_flinger->OpenLayer(layer_id)) {
184 LOG_WARNING(Service_VI, "Tried to open layer which was already open"); 185 LOG_WARNING(Service_VI, "Tried to open layer which was already open");
185 R_THROW(VI::ResultOperationFailed); 186 R_THROW(VI::ResultOperationFailed);
186 } 187 }
@@ -199,7 +200,7 @@ Result IApplicationDisplayService::OpenLayer(Out<u64> out_size,
199Result IApplicationDisplayService::CloseLayer(u64 layer_id) { 200Result IApplicationDisplayService::CloseLayer(u64 layer_id) {
200 LOG_DEBUG(Service_VI, "called. layer_id={}", layer_id); 201 LOG_DEBUG(Service_VI, "called. layer_id={}", layer_id);
201 202
202 if (!m_nvnflinger.CloseLayer(layer_id)) { 203 if (!m_surface_flinger->CloseLayer(layer_id)) {
203 LOG_WARNING(Service_VI, "Tried to close layer which was not open"); 204 LOG_WARNING(Service_VI, "Tried to close layer which was not open");
204 R_THROW(VI::ResultOperationFailed); 205 R_THROW(VI::ResultOperationFailed);
205 } 206 }
@@ -212,14 +213,14 @@ Result IApplicationDisplayService::CreateStrayLayer(
212 u32 flags, u64 display_id) { 213 u32 flags, u64 display_id) {
213 LOG_DEBUG(Service_VI, "called. flags={}, display_id={}", flags, display_id); 214 LOG_DEBUG(Service_VI, "called. flags={}, display_id={}", flags, display_id);
214 215
215 const auto layer_id = m_nvnflinger.CreateLayer(display_id); 216 const auto layer_id = m_surface_flinger->CreateLayer(display_id);
216 if (!layer_id) { 217 if (!layer_id) {
217 LOG_ERROR(Service_VI, "Layer not found! display_id={}", display_id); 218 LOG_ERROR(Service_VI, "Layer not found! display_id={}", display_id);
218 R_THROW(VI::ResultNotFound); 219 R_THROW(VI::ResultNotFound);
219 } 220 }
220 221
221 m_stray_layer_ids.push_back(*layer_id); 222 m_stray_layer_ids.push_back(*layer_id);
222 const auto buffer_queue_id = m_nvnflinger.FindBufferQueueId(display_id, *layer_id); 223 const auto buffer_queue_id = m_surface_flinger->FindBufferQueueId(display_id, *layer_id);
223 if (!buffer_queue_id) { 224 if (!buffer_queue_id) {
224 LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", display_id); 225 LOG_ERROR(Service_VI, "Buffer queue id not found! display_id={}", display_id);
225 R_THROW(VI::ResultNotFound); 226 R_THROW(VI::ResultNotFound);
@@ -240,7 +241,7 @@ Result IApplicationDisplayService::CreateStrayLayer(
240 241
241Result IApplicationDisplayService::DestroyStrayLayer(u64 layer_id) { 242Result IApplicationDisplayService::DestroyStrayLayer(u64 layer_id) {
242 LOG_WARNING(Service_VI, "(STUBBED) called. layer_id={}", layer_id); 243 LOG_WARNING(Service_VI, "(STUBBED) called. layer_id={}", layer_id);
243 m_nvnflinger.DestroyLayer(layer_id); 244 m_surface_flinger->DestroyLayer(layer_id);
244 R_SUCCEED(); 245 R_SUCCEED();
245} 246}
246 247
@@ -248,7 +249,7 @@ Result IApplicationDisplayService::GetDisplayVsyncEvent(
248 OutCopyHandle<Kernel::KReadableEvent> out_vsync_event, u64 display_id) { 249 OutCopyHandle<Kernel::KReadableEvent> out_vsync_event, u64 display_id) {
249 LOG_DEBUG(Service_VI, "called. display_id={}", display_id); 250 LOG_DEBUG(Service_VI, "called. display_id={}", display_id);
250 251
251 const auto result = m_nvnflinger.FindVsyncEvent(out_vsync_event, display_id); 252 const auto result = m_surface_flinger->FindVsyncEvent(out_vsync_event, display_id);
252 if (result != ResultSuccess) { 253 if (result != ResultSuccess) {
253 if (result == ResultNotFound) { 254 if (result == ResultNotFound) {
254 LOG_ERROR(Service_VI, "Vsync event was not found for display_id={}", display_id); 255 LOG_ERROR(Service_VI, "Vsync event was not found for display_id={}", display_id);
diff --git a/src/core/hle/service/vi/application_display_service.h b/src/core/hle/service/vi/application_display_service.h
index 5dff4bb31..e56490f9f 100644
--- a/src/core/hle/service/vi/application_display_service.h
+++ b/src/core/hle/service/vi/application_display_service.h
@@ -9,26 +9,30 @@ namespace Kernel {
9class KReadableEvent; 9class KReadableEvent;
10} 10}
11 11
12namespace Service::Nvnflinger {
13class Nvnflinger;
14class IHOSBinderDriver;
15} // namespace Service::Nvnflinger
16
12namespace Service::VI { 17namespace Service::VI {
13 18
14class IHOSBinderDriver;
15class IManagerDisplayService; 19class IManagerDisplayService;
16class ISystemDisplayService; 20class ISystemDisplayService;
17 21
18class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> { 22class IApplicationDisplayService final : public ServiceFramework<IApplicationDisplayService> {
19public: 23public:
20 IApplicationDisplayService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 24 IApplicationDisplayService(Core::System& system_,
21 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server); 25 std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service);
22 ~IApplicationDisplayService() override; 26 ~IApplicationDisplayService() override;
23 27
24private: 28private:
25 Result GetRelayService(Out<SharedPointer<IHOSBinderDriver>> out_relay_service); 29 Result GetRelayService(Out<SharedPointer<Nvnflinger::IHOSBinderDriver>> out_relay_service);
26 Result GetSystemDisplayService( 30 Result GetSystemDisplayService(
27 Out<SharedPointer<ISystemDisplayService>> out_system_display_service); 31 Out<SharedPointer<ISystemDisplayService>> out_system_display_service);
28 Result GetManagerDisplayService( 32 Result GetManagerDisplayService(
29 Out<SharedPointer<IManagerDisplayService>> out_manager_display_service); 33 Out<SharedPointer<IManagerDisplayService>> out_manager_display_service);
30 Result GetIndirectDisplayTransactionService( 34 Result GetIndirectDisplayTransactionService(
31 Out<SharedPointer<IHOSBinderDriver>> out_indirect_display_transaction_service); 35 Out<SharedPointer<Nvnflinger::IHOSBinderDriver>> out_indirect_display_transaction_service);
32 Result OpenDisplay(Out<u64> out_display_id, DisplayName display_name); 36 Result OpenDisplay(Out<u64> out_display_id, DisplayName display_name);
33 Result OpenDefaultDisplay(Out<u64> out_display_id); 37 Result OpenDefaultDisplay(Out<u64> out_display_id);
34 Result CloseDisplay(u64 display_id); 38 Result CloseDisplay(u64 display_id);
@@ -56,8 +60,8 @@ private:
56 s64 width, s64 height); 60 s64 width, s64 height);
57 61
58private: 62private:
59 Nvnflinger::Nvnflinger& m_nvnflinger; 63 const std::shared_ptr<Nvnflinger::IHOSBinderDriver> m_binder_service;
60 Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server; 64 const std::shared_ptr<Nvnflinger::Nvnflinger> m_surface_flinger;
61 std::vector<u64> m_stray_layer_ids; 65 std::vector<u64> m_stray_layer_ids;
62 bool m_vsync_event_fetched{false}; 66 bool m_vsync_event_fetched{false};
63}; 67};
diff --git a/src/core/hle/service/vi/application_root_service.cpp b/src/core/hle/service/vi/application_root_service.cpp
index 7af7f062c..501fbdd6a 100644
--- a/src/core/hle/service/vi/application_root_service.cpp
+++ b/src/core/hle/service/vi/application_root_service.cpp
@@ -11,10 +11,8 @@
11namespace Service::VI { 11namespace Service::VI {
12 12
13IApplicationRootService::IApplicationRootService( 13IApplicationRootService::IApplicationRootService(
14 Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 14 Core::System& system_, std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service)
15 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) 15 : ServiceFramework{system_, "vi:u"}, m_binder_service{std::move(binder_service)} {
16 : ServiceFramework{system_, "vi:u"}, m_nvnflinger{nvnflinger}, m_hos_binder_driver_server{
17 hos_binder_driver_server} {
18 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
19 {0, C<&IApplicationRootService::GetDisplayService>, "GetDisplayService"}, 17 {0, C<&IApplicationRootService::GetDisplayService>, "GetDisplayService"},
20 {1, nullptr, "GetDisplayServiceWithProxyNameExchange"}, 18 {1, nullptr, "GetDisplayServiceWithProxyNameExchange"},
@@ -27,8 +25,8 @@ IApplicationRootService::~IApplicationRootService() = default;
27Result IApplicationRootService::GetDisplayService( 25Result IApplicationRootService::GetDisplayService(
28 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) { 26 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) {
29 LOG_DEBUG(Service_VI, "called"); 27 LOG_DEBUG(Service_VI, "called");
30 R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_nvnflinger, 28 R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_binder_service,
31 m_hos_binder_driver_server, Permission::User, policy)); 29 Permission::User, policy));
32} 30}
33 31
34} // namespace Service::VI 32} // namespace Service::VI
diff --git a/src/core/hle/service/vi/application_root_service.h b/src/core/hle/service/vi/application_root_service.h
index 9dbf28cb4..d1f023e9e 100644
--- a/src/core/hle/service/vi/application_root_service.h
+++ b/src/core/hle/service/vi/application_root_service.h
@@ -11,8 +11,7 @@ class System;
11} 11}
12 12
13namespace Service::Nvnflinger { 13namespace Service::Nvnflinger {
14class HosBinderDriverServer; 14class IHOSBinderDriver;
15class Nvnflinger;
16} // namespace Service::Nvnflinger 15} // namespace Service::Nvnflinger
17 16
18namespace Service::VI { 17namespace Service::VI {
@@ -22,8 +21,8 @@ enum class Policy : u32;
22 21
23class IApplicationRootService final : public ServiceFramework<IApplicationRootService> { 22class IApplicationRootService final : public ServiceFramework<IApplicationRootService> {
24public: 23public:
25 explicit IApplicationRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 24 explicit IApplicationRootService(Core::System& system_,
26 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server); 25 std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service);
27 ~IApplicationRootService() override; 26 ~IApplicationRootService() override;
28 27
29private: 28private:
@@ -32,8 +31,7 @@ private:
32 Policy policy); 31 Policy policy);
33 32
34private: 33private:
35 Nvnflinger::Nvnflinger& m_nvnflinger; 34 const std::shared_ptr<Nvnflinger::IHOSBinderDriver> m_binder_service;
36 Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server;
37}; 35};
38 36
39} // namespace Service::VI 37} // namespace Service::VI
diff --git a/src/core/hle/service/vi/manager_display_service.cpp b/src/core/hle/service/vi/manager_display_service.cpp
index 17f2f3b8f..22454ba61 100644
--- a/src/core/hle/service/vi/manager_display_service.cpp
+++ b/src/core/hle/service/vi/manager_display_service.cpp
@@ -8,9 +8,10 @@
8 8
9namespace Service::VI { 9namespace Service::VI {
10 10
11IManagerDisplayService::IManagerDisplayService(Core::System& system_, 11IManagerDisplayService::IManagerDisplayService(
12 Nvnflinger::Nvnflinger& nvnflinger) 12 Core::System& system_, std::shared_ptr<Nvnflinger::Nvnflinger> surface_flinger)
13 : ServiceFramework{system_, "IManagerDisplayService"}, m_nvnflinger{nvnflinger} { 13 : ServiceFramework{system_, "IManagerDisplayService"},
14 m_surface_flinger{std::move(surface_flinger)} {
14 // clang-format off 15 // clang-format off
15 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
16 {200, nullptr, "AllocateProcessHeapBlock"}, 17 {200, nullptr, "AllocateProcessHeapBlock"},
@@ -107,7 +108,7 @@ Result IManagerDisplayService::CreateManagedLayer(Out<u64> out_layer_id, u32 unk
107 LOG_WARNING(Service_VI, "(STUBBED) called. unknown={}, display={}, aruid={}", unknown, 108 LOG_WARNING(Service_VI, "(STUBBED) called. unknown={}, display={}, aruid={}", unknown,
108 display_id, aruid.pid); 109 display_id, aruid.pid);
109 110
110 const auto layer_id = m_nvnflinger.CreateLayer(display_id); 111 const auto layer_id = m_surface_flinger->CreateLayer(display_id);
111 if (!layer_id) { 112 if (!layer_id) {
112 LOG_ERROR(Service_VI, "Layer not found! display={}", display_id); 113 LOG_ERROR(Service_VI, "Layer not found! display={}", display_id);
113 R_THROW(VI::ResultNotFound); 114 R_THROW(VI::ResultNotFound);
diff --git a/src/core/hle/service/vi/manager_display_service.h b/src/core/hle/service/vi/manager_display_service.h
index 60e646ee0..4a3d53ff8 100644
--- a/src/core/hle/service/vi/manager_display_service.h
+++ b/src/core/hle/service/vi/manager_display_service.h
@@ -8,7 +8,8 @@ namespace Service::VI {
8 8
9class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> { 9class IManagerDisplayService final : public ServiceFramework<IManagerDisplayService> {
10public: 10public:
11 explicit IManagerDisplayService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger); 11 explicit IManagerDisplayService(Core::System& system_,
12 std::shared_ptr<Nvnflinger::Nvnflinger> surface_flinger);
12 ~IManagerDisplayService() override; 13 ~IManagerDisplayService() override;
13 14
14private: 15private:
@@ -18,7 +19,7 @@ private:
18 Result SetLayerVisibility(bool visible, u64 layer_id); 19 Result SetLayerVisibility(bool visible, u64 layer_id);
19 20
20private: 21private:
21 Nvnflinger::Nvnflinger& m_nvnflinger; 22 const std::shared_ptr<Nvnflinger::Nvnflinger> m_surface_flinger;
22}; 23};
23 24
24} // namespace Service::VI 25} // namespace Service::VI
diff --git a/src/core/hle/service/vi/manager_root_service.cpp b/src/core/hle/service/vi/manager_root_service.cpp
index a7eee4f04..36b84909a 100644
--- a/src/core/hle/service/vi/manager_root_service.cpp
+++ b/src/core/hle/service/vi/manager_root_service.cpp
@@ -11,10 +11,8 @@
11namespace Service::VI { 11namespace Service::VI {
12 12
13IManagerRootService::IManagerRootService( 13IManagerRootService::IManagerRootService(
14 Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 14 Core::System& system_, std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service)
15 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) 15 : ServiceFramework{system_, "vi:m"}, m_binder_service{std::move(binder_service)} {
16 : ServiceFramework{system_, "vi:m"}, m_nvnflinger{nvnflinger}, m_hos_binder_driver_server{
17 hos_binder_driver_server} {
18 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
19 {2, C<&IManagerRootService::GetDisplayService>, "GetDisplayService"}, 17 {2, C<&IManagerRootService::GetDisplayService>, "GetDisplayService"},
20 {3, nullptr, "GetDisplayServiceWithProxyNameExchange"}, 18 {3, nullptr, "GetDisplayServiceWithProxyNameExchange"},
@@ -31,8 +29,8 @@ IManagerRootService::~IManagerRootService() = default;
31Result IManagerRootService::GetDisplayService( 29Result IManagerRootService::GetDisplayService(
32 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) { 30 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) {
33 LOG_DEBUG(Service_VI, "called"); 31 LOG_DEBUG(Service_VI, "called");
34 R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_nvnflinger, 32 R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_binder_service,
35 m_hos_binder_driver_server, Permission::Manager, policy)); 33 Permission::Manager, policy));
36} 34}
37 35
38} // namespace Service::VI 36} // namespace Service::VI
diff --git a/src/core/hle/service/vi/manager_root_service.h b/src/core/hle/service/vi/manager_root_service.h
index e6cb77aeb..26aa95a88 100644
--- a/src/core/hle/service/vi/manager_root_service.h
+++ b/src/core/hle/service/vi/manager_root_service.h
@@ -11,8 +11,7 @@ class System;
11} 11}
12 12
13namespace Service::Nvnflinger { 13namespace Service::Nvnflinger {
14class HosBinderDriverServer; 14class IHOSBinderDriver;
15class Nvnflinger;
16} // namespace Service::Nvnflinger 15} // namespace Service::Nvnflinger
17 16
18namespace Service::VI { 17namespace Service::VI {
@@ -22,8 +21,8 @@ enum class Policy : u32;
22 21
23class IManagerRootService final : public ServiceFramework<IManagerRootService> { 22class IManagerRootService final : public ServiceFramework<IManagerRootService> {
24public: 23public:
25 explicit IManagerRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 24 explicit IManagerRootService(Core::System& system_,
26 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server); 25 std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service);
27 ~IManagerRootService() override; 26 ~IManagerRootService() override;
28 27
29private: 28private:
@@ -31,8 +30,7 @@ private:
31 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, 30 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service,
32 Policy policy); 31 Policy policy);
33 32
34 Nvnflinger::Nvnflinger& m_nvnflinger; 33 const std::shared_ptr<Nvnflinger::IHOSBinderDriver> m_binder_service;
35 Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server;
36}; 34};
37 35
38} // namespace Service::VI 36} // namespace Service::VI
diff --git a/src/core/hle/service/vi/service_creator.cpp b/src/core/hle/service/vi/service_creator.cpp
index 1de9d61a4..594e57398 100644
--- a/src/core/hle/service/vi/service_creator.cpp
+++ b/src/core/hle/service/vi/service_creator.cpp
@@ -22,9 +22,8 @@ static bool IsValidServiceAccess(Permission permission, Policy policy) {
22 22
23Result GetApplicationDisplayService( 23Result GetApplicationDisplayService(
24 std::shared_ptr<IApplicationDisplayService>* out_application_display_service, 24 std::shared_ptr<IApplicationDisplayService>* out_application_display_service,
25 Core::System& system, Nvnflinger::Nvnflinger& nvnflinger, 25 Core::System& system, std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service,
26 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server, Permission permission, 26 Permission permission, Policy policy) {
27 Policy policy) {
28 27
29 if (!IsValidServiceAccess(permission, policy)) { 28 if (!IsValidServiceAccess(permission, policy)) {
30 LOG_ERROR(Service_VI, "Permission denied for policy {}", policy); 29 LOG_ERROR(Service_VI, "Permission denied for policy {}", policy);
@@ -32,7 +31,7 @@ Result GetApplicationDisplayService(
32 } 31 }
33 32
34 *out_application_display_service = 33 *out_application_display_service =
35 std::make_shared<IApplicationDisplayService>(system, nvnflinger, hos_binder_driver_server); 34 std::make_shared<IApplicationDisplayService>(system, binder_service);
36 R_SUCCEED(); 35 R_SUCCEED();
37} 36}
38 37
diff --git a/src/core/hle/service/vi/service_creator.h b/src/core/hle/service/vi/service_creator.h
index 8963bcd26..bdfac8a08 100644
--- a/src/core/hle/service/vi/service_creator.h
+++ b/src/core/hle/service/vi/service_creator.h
@@ -12,8 +12,7 @@ class System;
12} 12}
13 13
14namespace Service::Nvnflinger { 14namespace Service::Nvnflinger {
15class HosBinderDriverServer; 15class IHOSBinderDriver;
16class Nvnflinger;
17} // namespace Service::Nvnflinger 16} // namespace Service::Nvnflinger
18 17
19union Result; 18union Result;
@@ -26,8 +25,7 @@ enum class Policy : u32;
26 25
27Result GetApplicationDisplayService( 26Result GetApplicationDisplayService(
28 std::shared_ptr<IApplicationDisplayService>* out_application_display_service, 27 std::shared_ptr<IApplicationDisplayService>* out_application_display_service,
29 Core::System& system, Nvnflinger::Nvnflinger& nvnflinger, 28 Core::System& system, std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service,
30 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server, Permission permission, 29 Permission permission, Policy policy);
31 Policy policy);
32 30
33} // namespace Service::VI 31} // namespace Service::VI
diff --git a/src/core/hle/service/vi/system_display_service.cpp b/src/core/hle/service/vi/system_display_service.cpp
index 1e1cfc817..8d6c3f04c 100644
--- a/src/core/hle/service/vi/system_display_service.cpp
+++ b/src/core/hle/service/vi/system_display_service.cpp
@@ -9,9 +9,10 @@
9 9
10namespace Service::VI { 10namespace Service::VI {
11 11
12ISystemDisplayService::ISystemDisplayService(Core::System& system_, 12ISystemDisplayService::ISystemDisplayService(
13 Nvnflinger::Nvnflinger& nvnflinger) 13 Core::System& system_, std::shared_ptr<Nvnflinger::Nvnflinger> surface_flinger)
14 : ServiceFramework{system_, "ISystemDisplayService"}, m_nvnflinger{nvnflinger} { 14 : ServiceFramework{system_, "ISystemDisplayService"},
15 m_surface_flinger{std::move(surface_flinger)} {
15 // clang-format off 16 // clang-format off
16 static const FunctionInfo functions[] = { 17 static const FunctionInfo functions[] = {
17 {1200, nullptr, "GetZOrderCountMin"}, 18 {1200, nullptr, "GetZOrderCountMin"},
@@ -104,7 +105,7 @@ Result ISystemDisplayService::GetSharedBufferMemoryHandleId(
104 u64 buffer_id, ClientAppletResourceUserId aruid) { 105 u64 buffer_id, ClientAppletResourceUserId aruid) {
105 LOG_INFO(Service_VI, "called. buffer_id={}, aruid={:#x}", buffer_id, aruid.pid); 106 LOG_INFO(Service_VI, "called. buffer_id={}, aruid={:#x}", buffer_id, aruid.pid);
106 107
107 R_RETURN(m_nvnflinger.GetSystemBufferManager().GetSharedBufferMemoryHandleId( 108 R_RETURN(m_surface_flinger->GetSystemBufferManager().GetSharedBufferMemoryHandleId(
108 out_size, out_nvmap_handle, out_pool_layout, buffer_id, aruid.pid)); 109 out_size, out_nvmap_handle, out_pool_layout, buffer_id, aruid.pid));
109} 110}
110 111
@@ -122,7 +123,7 @@ Result ISystemDisplayService::AcquireSharedFrameBuffer(Out<android::Fence> out_f
122 Out<std::array<s32, 4>> out_slots, 123 Out<std::array<s32, 4>> out_slots,
123 Out<s64> out_target_slot, u64 layer_id) { 124 Out<s64> out_target_slot, u64 layer_id) {
124 LOG_DEBUG(Service_VI, "called"); 125 LOG_DEBUG(Service_VI, "called");
125 R_RETURN(m_nvnflinger.GetSystemBufferManager().AcquireSharedFrameBuffer( 126 R_RETURN(m_surface_flinger->GetSystemBufferManager().AcquireSharedFrameBuffer(
126 out_fence, *out_slots, out_target_slot, layer_id)); 127 out_fence, *out_slots, out_target_slot, layer_id));
127} 128}
128 129
@@ -131,15 +132,15 @@ Result ISystemDisplayService::PresentSharedFrameBuffer(android::Fence fence,
131 u32 window_transform, s32 swap_interval, 132 u32 window_transform, s32 swap_interval,
132 u64 layer_id, s64 surface_id) { 133 u64 layer_id, s64 surface_id) {
133 LOG_DEBUG(Service_VI, "called"); 134 LOG_DEBUG(Service_VI, "called");
134 R_RETURN(m_nvnflinger.GetSystemBufferManager().PresentSharedFrameBuffer( 135 R_RETURN(m_surface_flinger->GetSystemBufferManager().PresentSharedFrameBuffer(
135 fence, crop_region, window_transform, swap_interval, layer_id, surface_id)); 136 fence, crop_region, window_transform, swap_interval, layer_id, surface_id));
136} 137}
137 138
138Result ISystemDisplayService::GetSharedFrameBufferAcquirableEvent( 139Result ISystemDisplayService::GetSharedFrameBufferAcquirableEvent(
139 OutCopyHandle<Kernel::KReadableEvent> out_event, u64 layer_id) { 140 OutCopyHandle<Kernel::KReadableEvent> out_event, u64 layer_id) {
140 LOG_DEBUG(Service_VI, "called"); 141 LOG_DEBUG(Service_VI, "called");
141 R_RETURN(m_nvnflinger.GetSystemBufferManager().GetSharedFrameBufferAcquirableEvent(out_event, 142 R_RETURN(m_surface_flinger->GetSystemBufferManager().GetSharedFrameBufferAcquirableEvent(
142 layer_id)); 143 out_event, layer_id));
143} 144}
144 145
145} // namespace Service::VI 146} // namespace Service::VI
diff --git a/src/core/hle/service/vi/system_display_service.h b/src/core/hle/service/vi/system_display_service.h
index cfcb196fd..6c3f57ad7 100644
--- a/src/core/hle/service/vi/system_display_service.h
+++ b/src/core/hle/service/vi/system_display_service.h
@@ -7,14 +7,16 @@
7#include "core/hle/service/service.h" 7#include "core/hle/service/service.h"
8 8
9namespace Service::Nvnflinger { 9namespace Service::Nvnflinger {
10class Nvnflinger;
10struct SharedMemoryPoolLayout; 11struct SharedMemoryPoolLayout;
11} 12} // namespace Service::Nvnflinger
12 13
13namespace Service::VI { 14namespace Service::VI {
14 15
15class ISystemDisplayService final : public ServiceFramework<ISystemDisplayService> { 16class ISystemDisplayService final : public ServiceFramework<ISystemDisplayService> {
16public: 17public:
17 explicit ISystemDisplayService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger); 18 explicit ISystemDisplayService(Core::System& system_,
19 std::shared_ptr<Nvnflinger::Nvnflinger> surface_flinger);
18 ~ISystemDisplayService() override; 20 ~ISystemDisplayService() override;
19 21
20private: 22private:
@@ -39,7 +41,7 @@ private:
39 s64 surface_id); 41 s64 surface_id);
40 42
41private: 43private:
42 Nvnflinger::Nvnflinger& m_nvnflinger; 44 const std::shared_ptr<Nvnflinger::Nvnflinger> m_surface_flinger;
43}; 45};
44 46
45} // namespace Service::VI 47} // namespace Service::VI
diff --git a/src/core/hle/service/vi/system_root_service.cpp b/src/core/hle/service/vi/system_root_service.cpp
index 8789b4cfb..1d435ed6b 100644
--- a/src/core/hle/service/vi/system_root_service.cpp
+++ b/src/core/hle/service/vi/system_root_service.cpp
@@ -10,10 +10,9 @@
10 10
11namespace Service::VI { 11namespace Service::VI {
12 12
13ISystemRootService::ISystemRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 13ISystemRootService::ISystemRootService(Core::System& system_,
14 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) 14 std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service)
15 : ServiceFramework{system_, "vi:s"}, m_nvnflinger{nvnflinger}, m_hos_binder_driver_server{ 15 : ServiceFramework{system_, "vi:s"}, m_binder_service{std::move(binder_service)} {
16 hos_binder_driver_server} {
17 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
18 {1, C<&ISystemRootService::GetDisplayService>, "GetDisplayService"}, 17 {1, C<&ISystemRootService::GetDisplayService>, "GetDisplayService"},
19 {3, nullptr, "GetDisplayServiceWithProxyNameExchange"}, 18 {3, nullptr, "GetDisplayServiceWithProxyNameExchange"},
@@ -26,8 +25,8 @@ ISystemRootService::~ISystemRootService() = default;
26Result ISystemRootService::GetDisplayService( 25Result ISystemRootService::GetDisplayService(
27 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) { 26 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, Policy policy) {
28 LOG_DEBUG(Service_VI, "called"); 27 LOG_DEBUG(Service_VI, "called");
29 R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_nvnflinger, 28 R_RETURN(GetApplicationDisplayService(out_application_display_service, system, m_binder_service,
30 m_hos_binder_driver_server, Permission::System, policy)); 29 Permission::System, policy));
31} 30}
32 31
33} // namespace Service::VI 32} // namespace Service::VI
diff --git a/src/core/hle/service/vi/system_root_service.h b/src/core/hle/service/vi/system_root_service.h
index 2c547faa5..6f07c39fd 100644
--- a/src/core/hle/service/vi/system_root_service.h
+++ b/src/core/hle/service/vi/system_root_service.h
@@ -11,8 +11,7 @@ class System;
11} 11}
12 12
13namespace Service::Nvnflinger { 13namespace Service::Nvnflinger {
14class HosBinderDriverServer; 14class IHOSBinderDriver;
15class Nvnflinger;
16} // namespace Service::Nvnflinger 15} // namespace Service::Nvnflinger
17 16
18namespace Service::VI { 17namespace Service::VI {
@@ -22,8 +21,8 @@ enum class Policy : u32;
22 21
23class ISystemRootService final : public ServiceFramework<ISystemRootService> { 22class ISystemRootService final : public ServiceFramework<ISystemRootService> {
24public: 23public:
25 explicit ISystemRootService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger, 24 explicit ISystemRootService(Core::System& system_,
26 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server); 25 std::shared_ptr<Nvnflinger::IHOSBinderDriver> binder_service);
27 ~ISystemRootService() override; 26 ~ISystemRootService() override;
28 27
29private: 28private:
@@ -31,8 +30,7 @@ private:
31 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service, 30 Out<SharedPointer<IApplicationDisplayService>> out_application_display_service,
32 Policy policy); 31 Policy policy);
33 32
34 Nvnflinger::Nvnflinger& m_nvnflinger; 33 const std::shared_ptr<Nvnflinger::IHOSBinderDriver> m_binder_service;
35 Nvnflinger::HosBinderDriverServer& m_hos_binder_driver_server;
36}; 34};
37 35
38} // namespace Service::VI 36} // namespace Service::VI
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index 304e589b7..d20f1fdea 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -1,7 +1,10 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/core.h"
5#include "core/hle/service/nvnflinger/hos_binder_driver.h"
4#include "core/hle/service/server_manager.h" 6#include "core/hle/service/server_manager.h"
7#include "core/hle/service/sm/sm.h"
5#include "core/hle/service/vi/application_display_service.h" 8#include "core/hle/service/vi/application_display_service.h"
6#include "core/hle/service/vi/application_root_service.h" 9#include "core/hle/service/vi/application_root_service.h"
7#include "core/hle/service/vi/manager_root_service.h" 10#include "core/hle/service/vi/manager_root_service.h"
@@ -10,16 +13,17 @@
10 13
11namespace Service::VI { 14namespace Service::VI {
12 15
13void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nvnflinger, 16void LoopProcess(Core::System& system) {
14 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server) { 17 const auto binder_service =
18 system.ServiceManager().GetService<Nvnflinger::IHOSBinderDriver>("dispdrv", true);
15 auto server_manager = std::make_unique<ServerManager>(system); 19 auto server_manager = std::make_unique<ServerManager>(system);
16 20
17 server_manager->RegisterNamedService("vi:m", std::make_shared<IManagerRootService>(
18 system, nvnflinger, hos_binder_driver_server));
19 server_manager->RegisterNamedService( 21 server_manager->RegisterNamedService(
20 "vi:s", std::make_shared<ISystemRootService>(system, nvnflinger, hos_binder_driver_server)); 22 "vi:m", std::make_shared<IManagerRootService>(system, binder_service));
21 server_manager->RegisterNamedService("vi:u", std::make_shared<IApplicationRootService>( 23 server_manager->RegisterNamedService(
22 system, nvnflinger, hos_binder_driver_server)); 24 "vi:s", std::make_shared<ISystemRootService>(system, binder_service));
25 server_manager->RegisterNamedService(
26 "vi:u", std::make_shared<IApplicationRootService>(system, binder_service));
23 ServerManager::RunServer(std::move(server_manager)); 27 ServerManager::RunServer(std::move(server_manager));
24} 28}
25 29
diff --git a/src/core/hle/service/vi/vi.h b/src/core/hle/service/vi/vi.h
index 8e681370d..0c3dc175d 100644
--- a/src/core/hle/service/vi/vi.h
+++ b/src/core/hle/service/vi/vi.h
@@ -7,14 +7,8 @@ namespace Core {
7class System; 7class System;
8} 8}
9 9
10namespace Service::Nvnflinger {
11class HosBinderDriverServer;
12class Nvnflinger;
13} // namespace Service::Nvnflinger
14
15namespace Service::VI { 10namespace Service::VI {
16 11
17void LoopProcess(Core::System& system, Nvnflinger::Nvnflinger& nvnflinger, 12void LoopProcess(Core::System& system);
18 Nvnflinger::HosBinderDriverServer& hos_binder_driver_server);
19 13
20} // namespace Service::VI 14} // namespace Service::VI