From ee8eccc5fa473f2ce210eb4e242e8eca40594db7 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 14 Feb 2024 11:39:42 -0500 Subject: nvnflinger: convert to process --- .../hle/service/nvnflinger/hos_binder_driver.cpp | 56 ++++++++++++++++++++++ .../hle/service/nvnflinger/hos_binder_driver.h | 39 +++++++++++++++ src/core/hle/service/nvnflinger/nvnflinger.cpp | 53 ++++++++++---------- src/core/hle/service/nvnflinger/nvnflinger.h | 6 +-- 4 files changed, 123 insertions(+), 31 deletions(-) create mode 100644 src/core/hle/service/nvnflinger/hos_binder_driver.cpp create mode 100644 src/core/hle/service/nvnflinger/hos_binder_driver.h (limited to 'src/core/hle/service/nvnflinger') diff --git a/src/core/hle/service/nvnflinger/hos_binder_driver.cpp b/src/core/hle/service/nvnflinger/hos_binder_driver.cpp new file mode 100644 index 000000000..e09d72047 --- /dev/null +++ b/src/core/hle/service/nvnflinger/hos_binder_driver.cpp @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/nvnflinger/binder.h" +#include "core/hle/service/nvnflinger/hos_binder_driver.h" +#include "core/hle/service/nvnflinger/hos_binder_driver_server.h" + +namespace Service::Nvnflinger { + +IHOSBinderDriver::IHOSBinderDriver(Core::System& system_, + std::shared_ptr server, + std::shared_ptr surface_flinger) + : ServiceFramework{system_, "IHOSBinderDriver"}, m_server(server), + m_surface_flinger(surface_flinger) { + static const FunctionInfo functions[] = { + {0, C<&IHOSBinderDriver::TransactParcel>, "TransactParcel"}, + {1, C<&IHOSBinderDriver::AdjustRefcount>, "AdjustRefcount"}, + {2, C<&IHOSBinderDriver::GetNativeHandle>, "GetNativeHandle"}, + {3, C<&IHOSBinderDriver::TransactParcelAuto>, "TransactParcelAuto"}, + }; + RegisterHandlers(functions); +} + +IHOSBinderDriver::~IHOSBinderDriver() = default; + +Result IHOSBinderDriver::TransactParcel(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, + u32 flags) { + LOG_DEBUG(Service_VI, "called. id={} transaction={}, flags={}", binder_id, transaction_id, + flags); + m_server->TryGetProducer(binder_id)->Transact(transaction_id, flags, parcel_data, parcel_reply); + R_SUCCEED(); +} + +Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) { + LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={}, type={}", binder_id, addval, type); + R_SUCCEED(); +} + +Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id, + OutCopyHandle out_handle) { + LOG_WARNING(Service_VI, "(STUBBED) called id={}, type_id={}", binder_id, type_id); + *out_handle = &m_server->TryGetProducer(binder_id)->GetNativeHandle(); + R_SUCCEED(); +} + +Result IHOSBinderDriver::TransactParcelAuto(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, + u32 flags) { + R_RETURN(this->TransactParcel(binder_id, transaction_id, parcel_data, parcel_reply, flags)); +} + +} // namespace Service::Nvnflinger diff --git a/src/core/hle/service/nvnflinger/hos_binder_driver.h b/src/core/hle/service/nvnflinger/hos_binder_driver.h new file mode 100644 index 000000000..aa9e3121a --- /dev/null +++ b/src/core/hle/service/nvnflinger/hos_binder_driver.h @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/nvnflinger/binder.h" +#include "core/hle/service/service.h" + +namespace Service::Nvnflinger { + +class HosBinderDriverServer; +class Nvnflinger; + +class IHOSBinderDriver final : public ServiceFramework { +public: + explicit IHOSBinderDriver(Core::System& system_, std::shared_ptr server, + std::shared_ptr surface_flinger); + ~IHOSBinderDriver() override; + + std::shared_ptr GetSurfaceFlinger() { + return m_surface_flinger; + } + +private: + Result TransactParcel(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, u32 flags); + Result AdjustRefcount(s32 binder_id, s32 addval, s32 type); + Result GetNativeHandle(s32 binder_id, u32 type_id, + OutCopyHandle out_handle); + Result TransactParcelAuto(s32 binder_id, android::TransactionId transaction_id, + InBuffer parcel_data, + OutBuffer parcel_reply, u32 flags); + +private: + const std::shared_ptr m_server; + const std::shared_ptr m_surface_flinger; +}; + +} // 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 @@ // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later -#include -#include - -#include "common/assert.h" -#include "common/logging/log.h" #include "common/microprofile.h" #include "common/scope_exit.h" #include "common/settings.h" -#include "common/thread.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/nvdrv/devices/nvdisp_disp0.h" #include "core/hle/service/nvdrv/nvdrv.h" -#include "core/hle/service/nvnflinger/buffer_item_consumer.h" -#include "core/hle/service/nvnflinger/buffer_queue_core.h" +#include "core/hle/service/nvdrv/nvdrv_interface.h" #include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" #include "core/hle/service/nvnflinger/hardware_composer.h" +#include "core/hle/service/nvnflinger/hos_binder_driver.h" #include "core/hle/service/nvnflinger/hos_binder_driver_server.h" #include "core/hle/service/nvnflinger/nvnflinger.h" -#include "core/hle/service/nvnflinger/ui/graphic_buffer.h" +#include "core/hle/service/server_manager.h" +#include "core/hle/service/sm/sm.h" #include "core/hle/service/vi/display/vi_display.h" #include "core/hle/service/vi/layer/vi_layer.h" #include "core/hle/service/vi/vi_results.h" -#include "video_core/gpu.h" -#include "video_core/host1x/host1x.h" -#include "video_core/host1x/syncpoint_manager.h" namespace Service::Nvnflinger { @@ -47,6 +38,11 @@ void Nvnflinger::SplitVSync(std::stop_token stop_token) { while (!stop_token.stop_requested()) { vsync_signal.Wait(); + if (system.IsShuttingDown()) { + ShutdownLayers(); + return; + } + const auto lock_guard = Lock(); if (!is_abandoned) { @@ -65,6 +61,9 @@ Nvnflinger::Nvnflinger(Core::System& system_, HosBinderDriverServer& hos_binder_ displays.emplace_back(4, "Null", hos_binder_driver_server, service_context, system); guard = std::make_shared(); + nvdrv = system.ServiceManager().GetService("nvdrv:s", true)->GetModule(); + disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {}); + // Schedule the screen composition events multi_composition_event = Core::Timing::CreateEvent( "ScreenComposition", @@ -110,22 +109,12 @@ Nvnflinger::~Nvnflinger() { void Nvnflinger::ShutdownLayers() { // Abandon consumers. - { - const auto lock_guard = Lock(); - for (auto& display : displays) { - display.Abandon(); - } - - is_abandoned = true; + const auto lock_guard = Lock(); + for (auto& display : displays) { + display.Abandon(); } - // Join the vsync thread, if it exists. - vsync_thread = {}; -} - -void Nvnflinger::SetNVDrvInstance(std::shared_ptr instance) { - nvdrv = std::move(instance); - disp_fd = nvdrv->Open("/dev/nvdisp_disp0", {}); + is_abandoned = true; } std::optional Nvnflinger::OpenDisplay(std::string_view name) { @@ -332,4 +321,14 @@ FbShareBufferManager& Nvnflinger::GetSystemBufferManager() { return *system_buffer_manager; } +void LoopProcess(Core::System& system) { + const auto binder_server = std::make_shared(system); + const auto surface_flinger = std::make_shared(system, *binder_server); + + auto server_manager = std::make_unique(system); + server_manager->RegisterNamedService( + "dispdrv", std::make_shared(system, binder_server, surface_flinger)); + ServerManager::RunServer(std::move(server_manager)); +} + } // 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 @@ #include #include #include -#include #include "common/common_types.h" #include "common/polyfill_thread.h" @@ -57,9 +56,6 @@ public: void ShutdownLayers(); - /// Sets the NVDrv module instance to use to send buffers to the GPU. - void SetNVDrvInstance(std::shared_ptr instance); - /// Opens the specified display and returns the ID. /// /// If an invalid display name is provided, then an empty optional is returned. @@ -169,4 +165,6 @@ private: HosBinderDriverServer& hos_binder_driver_server; }; +void LoopProcess(Core::System& system); + } // namespace Service::Nvnflinger -- cgit v1.2.3