VERY experimental Nintendo Switch 2 emulator
C++
HLE/Applets: Use the correct size for the framebuffer SharedMemory in the swkbd and MiiSelector applets.
Subv6b0496175da1
diff --git a/src/core/hle/applets/mii_selector.cpp b/src/core/hle/applets/mii_selector.cppindex 708d2f630b..1dd6757f76 100644--- a/src/core/hle/applets/mii_selector.cpp+++ b/src/core/hle/applets/mii_selector.cpp@@ -21,13 +21,6 @@namespace HLE {namespace Applets {-MiiSelector::MiiSelector(Service::APT::AppletId id) : Applet(id), started(false) {- // Create the SharedMemory that will hold the framebuffer data- // TODO(Subv): What size should we use here?- using Kernel::MemoryPermission;- framebuffer_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, "MiiSelector Memory");-}-ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& parameter) {if (parameter.signal != static_cast<u32>(Service::APT::SignalType::LibAppJustStarted)) {LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);@@ -36,8 +29,18 @@ ResultCode MiiSelector::ReceiveParameter(const Service::APT::MessageParameter& preturn ResultCode(-1);}+ // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared memory.+ // Create the SharedMemory that will hold the framebuffer data+ Service::APT::CaptureBufferInfo capture_info;+ ASSERT(sizeof(capture_info) == parameter.buffer_size);++ memcpy(&capture_info, parameter.data, sizeof(capture_info));+ using Kernel::MemoryPermission;+ framebuffer_memory = Kernel::SharedMemory::Create(capture_info.size, MemoryPermission::ReadWrite,+ MemoryPermission::ReadWrite, "MiiSelector Memory");++ // Send the response message with the newly created SharedMemoryService::APT::MessageParameter result;- // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInforesult.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished);result.data = nullptr;result.buffer_size = 0;diff --git a/src/core/hle/applets/mii_selector.h b/src/core/hle/applets/mii_selector.hindex 6a3e7c8ebf..5619f83990 100644--- a/src/core/hle/applets/mii_selector.h+++ b/src/core/hle/applets/mii_selector.h@@ -18,15 +18,15 @@ namespace Applets {class MiiSelector final : public Applet {public:- MiiSelector(Service::APT::AppletId id);+ MiiSelector(Service::APT::AppletId id) : Applet(id), started(false) { }ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;void Update() override;bool IsRunning() const override { return started; }- /// TODO(Subv): Find out what this is actually used for.- /// It is believed that the application stores the current screen image here.+ /// This SharedMemory will be created when we receive the LibAppJustStarted message.+ /// It holds the framebuffer info retrieved by the application with GSPGPU::ImportDisplayCaptureInfoKernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory;/// Whether this applet is currently running instead of the host application or not.diff --git a/src/core/hle/applets/swkbd.cpp b/src/core/hle/applets/swkbd.cppindex 1db6b5a175..87238aa1c9 100644--- a/src/core/hle/applets/swkbd.cpp+++ b/src/core/hle/applets/swkbd.cpp@@ -24,13 +24,6 @@namespace HLE {namespace Applets {-SoftwareKeyboard::SoftwareKeyboard(Service::APT::AppletId id) : Applet(id), started(false) {- // Create the SharedMemory that will hold the framebuffer data- // TODO(Subv): What size should we use here?- using Kernel::MemoryPermission;- framebuffer_memory = Kernel::SharedMemory::Create(0x1000, MemoryPermission::ReadWrite, MemoryPermission::ReadWrite, "SoftwareKeyboard Memory");-}-ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter const& parameter) {if (parameter.signal != static_cast<u32>(Service::APT::SignalType::LibAppJustStarted)) {LOG_ERROR(Service_APT, "unsupported signal %u", parameter.signal);@@ -39,8 +32,19 @@ ResultCode SoftwareKeyboard::ReceiveParameter(Service::APT::MessageParameter conreturn ResultCode(-1);}+ // The LibAppJustStarted message contains a buffer with the size of the framebuffer shared memory.+ // Create the SharedMemory that will hold the framebuffer data+ Service::APT::CaptureBufferInfo capture_info;+ ASSERT(sizeof(capture_info) == parameter.buffer_size);++ memcpy(&capture_info, parameter.data, sizeof(capture_info));++ using Kernel::MemoryPermission;+ framebuffer_memory = Kernel::SharedMemory::Create(capture_info.size, MemoryPermission::ReadWrite,+ MemoryPermission::ReadWrite, "SoftwareKeyboard Memory");++ // Send the response message with the newly created SharedMemoryService::APT::MessageParameter result;- // The buffer passed in parameter contains the data returned by GSPGPU::ImportDisplayCaptureInforesult.signal = static_cast<u32>(Service::APT::SignalType::LibAppFinished);result.data = nullptr;result.buffer_size = 0;diff --git a/src/core/hle/applets/swkbd.h b/src/core/hle/applets/swkbd.hindex cb95b8d90a..cf26a8fb79 100644--- a/src/core/hle/applets/swkbd.h+++ b/src/core/hle/applets/swkbd.h@@ -53,8 +53,7 @@ static_assert(sizeof(SoftwareKeyboardConfig) == 0x400, "Software Keyboard Configclass SoftwareKeyboard final : public Applet {public:- SoftwareKeyboard(Service::APT::AppletId id);- ~SoftwareKeyboard() {}+ SoftwareKeyboard(Service::APT::AppletId id) : Applet(id), started(false) { }ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) override;ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) override;@@ -72,8 +71,8 @@ public:*/void Finalize();- /// TODO(Subv): Find out what this is actually used for.- /// It is believed that the application stores the current screen image here.+ /// This SharedMemory will be created when we receive the LibAppJustStarted message.+ /// It holds the framebuffer info retrieved by the application with GSPGPU::ImportDisplayCaptureInfoKernel::SharedPtr<Kernel::SharedMemory> framebuffer_memory;/// SharedMemory where the output text will be storeddiff --git a/src/core/hle/service/apt/apt.h b/src/core/hle/service/apt/apt.hindex 668b4a66f2..1a1034fcce 100644--- a/src/core/hle/service/apt/apt.h+++ b/src/core/hle/service/apt/apt.h@@ -5,6 +5,7 @@#pragma once#include "common/common_types.h"+#include "common/swap.h"#include "core/hle/kernel/kernel.h"@@ -31,6 +32,20 @@ struct AppletStartupParameter {u8* data = nullptr;};+/// Used by the application to pass information about the current framebuffer to applets.+struct CaptureBufferInfo {+ u32_le size;+ u8 is_3d;+ INSERT_PADDING_BYTES(0x3); // Padding for alignment+ u32_le top_screen_left_offset;+ u32_le top_screen_right_offset;+ u32_le top_screen_format;+ u32_le bottom_screen_left_offset;+ u32_le bottom_screen_right_offset;+ u32_le bottom_screen_format;+};+static_assert(sizeof(CaptureBufferInfo) == 0x20, "CaptureBufferInfo struct has incorrect size");+/// Signals used by APT functionsenum class SignalType : u32 {None = 0x0,