nvnflinger: convert to process

This commit is contained in:
Liam
2024-02-14 11:39:42 -05:00
parent 7b79cddacd
commit ee8eccc5fa
44 changed files with 241 additions and 273 deletions

View File

@@ -8,13 +8,13 @@
namespace Service::AM {
void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system) {
void LoopProcess(Core::System& system) {
auto server_manager = std::make_unique<ServerManager>(system);
server_manager->RegisterNamedService(
"appletAE", std::make_shared<IAllSystemAppletProxiesService>(system, nvnflinger));
server_manager->RegisterNamedService(
"appletOE", std::make_shared<IApplicationProxyService>(system, nvnflinger));
server_manager->RegisterNamedService("appletAE",
std::make_shared<IAllSystemAppletProxiesService>(system));
server_manager->RegisterNamedService("appletOE",
std::make_shared<IApplicationProxyService>(system));
ServerManager::RunServer(std::move(server_manager));
}

View File

@@ -7,12 +7,8 @@ namespace Core {
class System;
}
namespace Service::Nvnflinger {
class Nvnflinger;
}
namespace Service::AM {
void LoopProcess(Nvnflinger::Nvnflinger& nvnflinger, Core::System& system);
void LoopProcess(Core::System& system);
} // namespace Service::AM

View File

@@ -1,9 +1,12 @@
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/core.h"
#include "core/hle/service/am/display_layer_manager.h"
#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
#include "core/hle/service/nvnflinger/hos_binder_driver.h"
#include "core/hle/service/nvnflinger/nvnflinger.h"
#include "core/hle/service/sm/sm.h"
#include "core/hle/service/vi/vi_results.h"
namespace Service::AM {
@@ -13,10 +16,12 @@ DisplayLayerManager::~DisplayLayerManager() {
this->Finalize();
}
void DisplayLayerManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process,
void DisplayLayerManager::Initialize(Core::System& system, Kernel::KProcess* process,
AppletId applet_id, LibraryAppletMode mode) {
m_process = process;
m_nvnflinger = nvnflinger;
m_surface_flinger = system.ServiceManager()
.GetService<Nvnflinger::IHOSBinderDriver>("dispdrv", true)
->GetSurfaceFlinger();
m_system_shared_buffer_id = 0;
m_system_shared_layer_id = 0;
m_applet_id = applet_id;
@@ -26,36 +31,36 @@ void DisplayLayerManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel:
}
void DisplayLayerManager::Finalize() {
if (!m_nvnflinger) {
if (!m_surface_flinger) {
return;
}
// Clean up managed layers.
for (const auto& layer : m_managed_display_layers) {
m_nvnflinger->DestroyLayer(layer);
m_surface_flinger->DestroyLayer(layer);
}
for (const auto& layer : m_managed_display_recording_layers) {
m_nvnflinger->DestroyLayer(layer);
m_surface_flinger->DestroyLayer(layer);
}
// Clean up shared layers.
if (m_buffer_sharing_enabled) {
m_nvnflinger->GetSystemBufferManager().Finalize(m_process);
m_surface_flinger->GetSystemBufferManager().Finalize(m_process);
}
m_nvnflinger = nullptr;
m_surface_flinger = nullptr;
}
Result DisplayLayerManager::CreateManagedDisplayLayer(u64* out_layer) {
R_UNLESS(m_nvnflinger != nullptr, VI::ResultOperationFailed);
R_UNLESS(m_surface_flinger != nullptr, VI::ResultOperationFailed);
// TODO(Subv): Find out how AM determines the display to use, for now just
// create the layer in the Default display.
const auto display_id = m_nvnflinger->OpenDisplay("Default");
const auto layer_id = m_nvnflinger->CreateLayer(*display_id);
const auto display_id = m_surface_flinger->OpenDisplay("Default");
const auto layer_id = m_surface_flinger->CreateLayer(*display_id);
m_nvnflinger->SetLayerVisibility(*layer_id, m_visible);
m_surface_flinger->SetLayerVisibility(*layer_id, m_visible);
m_managed_display_layers.emplace(*layer_id);
*out_layer = *layer_id;
@@ -65,7 +70,7 @@ Result DisplayLayerManager::CreateManagedDisplayLayer(u64* out_layer) {
Result DisplayLayerManager::CreateManagedDisplaySeparableLayer(u64* out_layer,
u64* out_recording_layer) {
R_UNLESS(m_nvnflinger != nullptr, VI::ResultOperationFailed);
R_UNLESS(m_surface_flinger != nullptr, VI::ResultOperationFailed);
// TODO(Subv): Find out how AM determines the display to use, for now just
// create the layer in the Default display.
@@ -74,10 +79,10 @@ Result DisplayLayerManager::CreateManagedDisplaySeparableLayer(u64* out_layer,
// Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse
// side effects.
// TODO: Support multiple layers
const auto display_id = m_nvnflinger->OpenDisplay("Default");
const auto layer_id = m_nvnflinger->CreateLayer(*display_id);
const auto display_id = m_surface_flinger->OpenDisplay("Default");
const auto layer_id = m_surface_flinger->CreateLayer(*display_id);
m_nvnflinger->SetLayerVisibility(*layer_id, m_visible);
m_surface_flinger->SetLayerVisibility(*layer_id, m_visible);
m_managed_display_layers.emplace(*layer_id);
*out_layer = *layer_id;
@@ -91,19 +96,19 @@ Result DisplayLayerManager::IsSystemBufferSharingEnabled() {
R_SUCCEED_IF(m_buffer_sharing_enabled);
// Ensure we can access shared layers.
R_UNLESS(m_nvnflinger != nullptr, VI::ResultOperationFailed);
R_UNLESS(m_surface_flinger != nullptr, VI::ResultOperationFailed);
R_UNLESS(m_applet_id != AppletId::Application, VI::ResultPermissionDenied);
// Create the shared layer.
const auto blend =
m_blending_enabled ? Nvnflinger::LayerBlending::Coverage : Nvnflinger::LayerBlending::None;
const auto display_id = m_nvnflinger->OpenDisplay("Default").value();
R_TRY(m_nvnflinger->GetSystemBufferManager().Initialize(
const auto display_id = m_surface_flinger->OpenDisplay("Default").value();
R_TRY(m_surface_flinger->GetSystemBufferManager().Initialize(
m_process, &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id, blend));
// We succeeded, so set up remaining state.
m_buffer_sharing_enabled = true;
m_nvnflinger->SetLayerVisibility(m_system_shared_layer_id, m_visible);
m_surface_flinger->SetLayerVisibility(m_system_shared_layer_id, m_visible);
R_SUCCEED();
}
@@ -124,13 +129,13 @@ void DisplayLayerManager::SetWindowVisibility(bool visible) {
m_visible = visible;
if (m_nvnflinger) {
if (m_surface_flinger) {
if (m_system_shared_layer_id) {
m_nvnflinger->SetLayerVisibility(m_system_shared_layer_id, m_visible);
m_surface_flinger->SetLayerVisibility(m_system_shared_layer_id, m_visible);
}
for (const auto layer_id : m_managed_display_layers) {
m_nvnflinger->SetLayerVisibility(layer_id, m_visible);
m_surface_flinger->SetLayerVisibility(layer_id, m_visible);
}
}
}
@@ -142,7 +147,7 @@ bool DisplayLayerManager::GetWindowVisibility() const {
Result DisplayLayerManager::WriteAppletCaptureBuffer(bool* out_was_written,
s32* out_fbshare_layer_index) {
R_UNLESS(m_buffer_sharing_enabled, VI::ResultPermissionDenied);
R_RETURN(m_nvnflinger->GetSystemBufferManager().WriteAppletCaptureBuffer(
R_RETURN(m_surface_flinger->GetSystemBufferManager().WriteAppletCaptureBuffer(
out_was_written, out_fbshare_layer_index));
}

View File

@@ -9,6 +9,10 @@
#include "core/hle/result.h"
#include "core/hle/service/am/am_types.h"
namespace Core {
class System;
}
namespace Kernel {
class KProcess;
}
@@ -24,8 +28,8 @@ public:
explicit DisplayLayerManager();
~DisplayLayerManager();
void Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process,
AppletId applet_id, LibraryAppletMode mode);
void Initialize(Core::System& system, Kernel::KProcess* process, AppletId applet_id,
LibraryAppletMode mode);
void Finalize();
Result CreateManagedDisplayLayer(u64* out_layer);
@@ -42,7 +46,7 @@ public:
private:
Kernel::KProcess* m_process{};
Nvnflinger::Nvnflinger* m_nvnflinger{};
std::shared_ptr<Nvnflinger::Nvnflinger> m_surface_flinger{};
std::set<u64> m_managed_display_layers{};
std::set<u64> m_managed_display_recording_layers{};
u64 m_system_shared_buffer_id{};

View File

@@ -10,9 +10,8 @@
namespace Service::AM {
IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_,
Nvnflinger::Nvnflinger& nvnflinger)
: ServiceFramework{system_, "appletAE"}, m_nvnflinger{nvnflinger} {
IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_)
: ServiceFramework{system_, "appletAE"} {
// clang-format off
static const FunctionInfo functions[] = {
{100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"},
@@ -37,8 +36,8 @@ Result IAllSystemAppletProxiesService::OpenSystemAppletProxy(
LOG_DEBUG(Service_AM, "called");
if (const auto applet = this->GetAppletFromProcessId(pid); applet) {
*out_system_applet_proxy = std::make_shared<ISystemAppletProxy>(
system, applet, process_handle.Get(), m_nvnflinger);
*out_system_applet_proxy =
std::make_shared<ISystemAppletProxy>(system, applet, process_handle.Get());
R_SUCCEED();
} else {
UNIMPLEMENTED();
@@ -53,8 +52,8 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxy(
LOG_DEBUG(Service_AM, "called");
if (const auto applet = this->GetAppletFromProcessId(pid); applet) {
*out_library_applet_proxy = std::make_shared<ILibraryAppletProxy>(
system, applet, process_handle.Get(), m_nvnflinger);
*out_library_applet_proxy =
std::make_shared<ILibraryAppletProxy>(system, applet, process_handle.Get());
R_SUCCEED();
} else {
UNIMPLEMENTED();

View File

@@ -8,10 +8,6 @@
namespace Service {
namespace Nvnflinger {
class Nvnflinger;
}
namespace AM {
struct Applet;
@@ -22,8 +18,7 @@ class ISystemAppletProxy;
class IAllSystemAppletProxiesService final
: public ServiceFramework<IAllSystemAppletProxiesService> {
public:
explicit IAllSystemAppletProxiesService(Core::System& system_,
Nvnflinger::Nvnflinger& nvnflinger);
explicit IAllSystemAppletProxiesService(Core::System& system_);
~IAllSystemAppletProxiesService() override;
private:
@@ -40,7 +35,6 @@ private:
private:
std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);
Nvnflinger::Nvnflinger& m_nvnflinger;
};
} // namespace AM

View File

@@ -17,9 +17,9 @@
namespace Service::AM {
IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger)
: ServiceFramework{system_, "IApplicationProxy"},
m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} {
Kernel::KProcess* process)
: ServiceFramework{system_, "IApplicationProxy"}, m_process{process}, m_applet{
std::move(applet)} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -77,8 +77,7 @@ Result IApplicationProxy::GetWindowController(
Result IApplicationProxy::GetSelfController(
Out<SharedPointer<ISelfController>> out_self_controller) {
LOG_DEBUG(Service_AM, "called");
*out_self_controller =
std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger);
*out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process);
R_SUCCEED();
}

View File

@@ -22,7 +22,7 @@ class IWindowController;
class IApplicationProxy final : public ServiceFramework<IApplicationProxy> {
public:
explicit IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger);
Kernel::KProcess* process);
~IApplicationProxy();
private:
@@ -40,7 +40,6 @@ private:
Out<SharedPointer<IApplicationFunctions>> out_application_functions);
private:
Nvnflinger::Nvnflinger& m_nvnflinger;
Kernel::KProcess* const m_process;
const std::shared_ptr<Applet> m_applet;
};

View File

@@ -10,9 +10,8 @@
namespace Service::AM {
IApplicationProxyService::IApplicationProxyService(Core::System& system_,
Nvnflinger::Nvnflinger& nvnflinger)
: ServiceFramework{system_, "appletOE"}, m_nvnflinger{nvnflinger} {
IApplicationProxyService::IApplicationProxyService(Core::System& system_)
: ServiceFramework{system_, "appletOE"} {
static const FunctionInfo functions[] = {
{0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"},
};
@@ -28,7 +27,7 @@ Result IApplicationProxyService::OpenApplicationProxy(
if (const auto applet = this->GetAppletFromProcessId(pid)) {
*out_application_proxy =
std::make_shared<IApplicationProxy>(system, applet, process_handle.Get(), m_nvnflinger);
std::make_shared<IApplicationProxy>(system, applet, process_handle.Get());
R_SUCCEED();
} else {
UNIMPLEMENTED();

View File

@@ -8,10 +8,6 @@
namespace Service {
namespace Nvnflinger {
class Nvnflinger;
}
namespace AM {
struct Applet;
@@ -19,7 +15,7 @@ class IApplicationProxy;
class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> {
public:
explicit IApplicationProxyService(Core::System& system_, Nvnflinger::Nvnflinger& nvnflinger);
explicit IApplicationProxyService(Core::System& system_);
~IApplicationProxyService() override;
private:
@@ -28,7 +24,6 @@ private:
private:
std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);
Nvnflinger::Nvnflinger& m_nvnflinger;
};
} // namespace AM

View File

@@ -19,10 +19,9 @@
namespace Service::AM {
ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process,
Nvnflinger::Nvnflinger& nvnflinger)
: ServiceFramework{system_, "ILibraryAppletProxy"},
m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} {
Kernel::KProcess* process)
: ServiceFramework{system_, "ILibraryAppletProxy"}, m_process{process}, m_applet{
std::move(applet)} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -83,8 +82,7 @@ Result ILibraryAppletProxy::GetWindowController(
Result ILibraryAppletProxy::GetSelfController(
Out<SharedPointer<ISelfController>> out_self_controller) {
LOG_DEBUG(Service_AM, "called");
*out_self_controller =
std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger);
*out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process);
R_SUCCEED();
}

View File

@@ -25,7 +25,7 @@ class IWindowController;
class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> {
public:
explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger);
Kernel::KProcess* process);
~ILibraryAppletProxy();
private:
@@ -47,7 +47,6 @@ private:
Result GetGlobalStateController(
Out<SharedPointer<IGlobalStateController>> out_global_state_controller);
Nvnflinger::Nvnflinger& m_nvnflinger;
Kernel::KProcess* const m_process;
const std::shared_ptr<Applet> m_applet;
};

View File

@@ -15,9 +15,9 @@
namespace Service::AM {
ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger)
: ServiceFramework{system_, "ISelfController"}, m_nvnflinger{nvnflinger}, m_process{process},
m_applet{std::move(applet)} {
Kernel::KProcess* process)
: ServiceFramework{system_, "ISelfController"}, m_process{process}, m_applet{
std::move(applet)} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&ISelfController::Exit>, "Exit"},
@@ -74,7 +74,7 @@ ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet>
RegisterHandlers(functions);
std::scoped_lock lk{m_applet->lock};
m_applet->display_layer_manager.Initialize(&m_nvnflinger, m_process, m_applet->applet_id,
m_applet->display_layer_manager.Initialize(system, m_process, m_applet->applet_id,
m_applet->library_applet_mode);
}

View File

@@ -23,7 +23,7 @@ struct Applet;
class ISelfController final : public ServiceFramework<ISelfController> {
public:
explicit ISelfController(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger);
Kernel::KProcess* process);
~ISelfController() override;
private:
@@ -64,7 +64,6 @@ private:
Result SaveCurrentScreenshot(Capture::AlbumReportOption album_report_option);
Result SetRecordVolumeMuted(bool muted);
Nvnflinger::Nvnflinger& m_nvnflinger;
Kernel::KProcess* const m_process;
const std::shared_ptr<Applet> m_applet;
};

View File

@@ -19,10 +19,9 @@
namespace Service::AM {
ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
Kernel::KProcess* process,
Nvnflinger::Nvnflinger& nvnflinger)
: ServiceFramework{system_, "ISystemAppletProxy"},
m_nvnflinger{nvnflinger}, m_process{process}, m_applet{std::move(applet)} {
Kernel::KProcess* process)
: ServiceFramework{system_, "ISystemAppletProxy"}, m_process{process}, m_applet{
std::move(applet)} {
// clang-format off
static const FunctionInfo functions[] = {
{0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -83,8 +82,7 @@ Result ISystemAppletProxy::GetWindowController(
Result ISystemAppletProxy::GetSelfController(
Out<SharedPointer<ISelfController>> out_self_controller) {
LOG_DEBUG(Service_AM, "called");
*out_self_controller =
std::make_shared<ISelfController>(system, m_applet, m_process, m_nvnflinger);
*out_self_controller = std::make_shared<ISelfController>(system, m_applet, m_process);
R_SUCCEED();
}

View File

@@ -25,7 +25,7 @@ class IWindowController;
class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> {
public:
explicit ISystemAppletProxy(Core::System& system, std::shared_ptr<Applet> applet,
Kernel::KProcess* process, Nvnflinger::Nvnflinger& nvnflinger);
Kernel::KProcess* process);
~ISystemAppletProxy();
private:
@@ -46,7 +46,6 @@ private:
Result GetGlobalStateController(
Out<SharedPointer<IGlobalStateController>> out_global_state_controller);
Nvnflinger::Nvnflinger& m_nvnflinger;
Kernel::KProcess* const m_process;
const std::shared_ptr<Applet> m_applet;
};