summaryrefslogtreecommitdiff
path: root/src/core/hle/service/am
diff options
context:
space:
mode:
authorGravatar Narr the Reg2024-02-11 20:58:28 -0600
committerGravatar GitHub2024-02-11 20:58:28 -0600
commit2ff45cd0da941dce2564f5c18c580d0283da27bf (patch)
tree81fea8c23f9afa39c167288e03ff57eb25413ee4 /src/core/hle/service/am
parentMerge pull request #12991 from german77/news2 (diff)
parentam: use applet program loading for tested versions (diff)
downloadyuzu-2ff45cd0da941dce2564f5c18c580d0283da27bf.tar.gz
yuzu-2ff45cd0da941dce2564f5c18c580d0283da27bf.tar.xz
yuzu-2ff45cd0da941dce2564f5c18c580d0283da27bf.zip
Merge pull request #12756 from liamwhite/applet-multiprocess-hwc
general: applet multiprocess
Diffstat (limited to 'src/core/hle/service/am')
-rw-r--r--src/core/hle/service/am/am_types.h6
-rw-r--r--src/core/hle/service/am/frontend/applet_software_keyboard.cpp12
-rw-r--r--src/core/hle/service/am/frontend/applet_software_keyboard.h2
-rw-r--r--src/core/hle/service/am/library_applet_creator.cpp81
-rw-r--r--src/core/hle/service/am/process.cpp23
-rw-r--r--src/core/hle/service/am/process.h2
-rw-r--r--src/core/hle/service/am/self_controller.cpp18
-rw-r--r--src/core/hle/service/am/self_controller.h2
-rw-r--r--src/core/hle/service/am/system_buffer_manager.cpp19
-rw-r--r--src/core/hle/service/am/system_buffer_manager.h3
-rw-r--r--src/core/hle/service/am/window_controller.cpp4
11 files changed, 126 insertions, 46 deletions
diff --git a/src/core/hle/service/am/am_types.h b/src/core/hle/service/am/am_types.h
index a2b852b12..8c33feb15 100644
--- a/src/core/hle/service/am/am_types.h
+++ b/src/core/hle/service/am/am_types.h
@@ -130,9 +130,9 @@ enum class AppletProgramId : u64 {
130 130
131enum class LibraryAppletMode : u32 { 131enum class LibraryAppletMode : u32 {
132 AllForeground = 0, 132 AllForeground = 0,
133 Background = 1, 133 PartialForeground = 1,
134 NoUI = 2, 134 NoUi = 2,
135 BackgroundIndirectDisplay = 3, 135 PartialForegroundIndirectDisplay = 3,
136 AllForegroundInitiallyHidden = 4, 136 AllForegroundInitiallyHidden = 4,
137}; 137};
138 138
diff --git a/src/core/hle/service/am/frontend/applet_software_keyboard.cpp b/src/core/hle/service/am/frontend/applet_software_keyboard.cpp
index fbf75d379..034c62f32 100644
--- a/src/core/hle/service/am/frontend/applet_software_keyboard.cpp
+++ b/src/core/hle/service/am/frontend/applet_software_keyboard.cpp
@@ -68,9 +68,9 @@ void SoftwareKeyboard::Initialize() {
68 case LibraryAppletMode::AllForeground: 68 case LibraryAppletMode::AllForeground:
69 InitializeForeground(); 69 InitializeForeground();
70 break; 70 break;
71 case LibraryAppletMode::Background: 71 case LibraryAppletMode::PartialForeground:
72 case LibraryAppletMode::BackgroundIndirectDisplay: 72 case LibraryAppletMode::PartialForegroundIndirectDisplay:
73 InitializeBackground(applet_mode); 73 InitializePartialForeground(applet_mode);
74 break; 74 break;
75 default: 75 default:
76 ASSERT_MSG(false, "Invalid LibraryAppletMode={}", applet_mode); 76 ASSERT_MSG(false, "Invalid LibraryAppletMode={}", applet_mode);
@@ -243,7 +243,7 @@ void SoftwareKeyboard::InitializeForeground() {
243 InitializeFrontendNormalKeyboard(); 243 InitializeFrontendNormalKeyboard();
244} 244}
245 245
246void SoftwareKeyboard::InitializeBackground(LibraryAppletMode library_applet_mode) { 246void SoftwareKeyboard::InitializePartialForeground(LibraryAppletMode library_applet_mode) {
247 LOG_INFO(Service_AM, "Initializing Inline Software Keyboard Applet."); 247 LOG_INFO(Service_AM, "Initializing Inline Software Keyboard Applet.");
248 248
249 is_background = true; 249 is_background = true;
@@ -258,9 +258,9 @@ void SoftwareKeyboard::InitializeBackground(LibraryAppletMode library_applet_mod
258 swkbd_inline_initialize_arg.size()); 258 swkbd_inline_initialize_arg.size());
259 259
260 if (swkbd_initialize_arg.library_applet_mode_flag) { 260 if (swkbd_initialize_arg.library_applet_mode_flag) {
261 ASSERT(library_applet_mode == LibraryAppletMode::Background); 261 ASSERT(library_applet_mode == LibraryAppletMode::PartialForeground);
262 } else { 262 } else {
263 ASSERT(library_applet_mode == LibraryAppletMode::BackgroundIndirectDisplay); 263 ASSERT(library_applet_mode == LibraryAppletMode::PartialForegroundIndirectDisplay);
264 } 264 }
265} 265}
266 266
diff --git a/src/core/hle/service/am/frontend/applet_software_keyboard.h b/src/core/hle/service/am/frontend/applet_software_keyboard.h
index f464b7e15..2a7d01b96 100644
--- a/src/core/hle/service/am/frontend/applet_software_keyboard.h
+++ b/src/core/hle/service/am/frontend/applet_software_keyboard.h
@@ -62,7 +62,7 @@ private:
62 void InitializeForeground(); 62 void InitializeForeground();
63 63
64 /// Initializes the inline software keyboard. 64 /// Initializes the inline software keyboard.
65 void InitializeBackground(LibraryAppletMode library_applet_mode); 65 void InitializePartialForeground(LibraryAppletMode library_applet_mode);
66 66
67 /// Processes the text check sent by the application. 67 /// Processes the text check sent by the application.
68 void ProcessTextCheck(); 68 void ProcessTextCheck();
diff --git a/src/core/hle/service/am/library_applet_creator.cpp b/src/core/hle/service/am/library_applet_creator.cpp
index 47bab7528..00d5a0705 100644
--- a/src/core/hle/service/am/library_applet_creator.cpp
+++ b/src/core/hle/service/am/library_applet_creator.cpp
@@ -1,6 +1,7 @@
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 "common/settings.h"
4#include "core/hle/kernel/k_transfer_memory.h" 5#include "core/hle/kernel/k_transfer_memory.h"
5#include "core/hle/service/am/applet_data_broker.h" 6#include "core/hle/service/am/applet_data_broker.h"
6#include "core/hle/service/am/applet_manager.h" 7#include "core/hle/service/am/applet_manager.h"
@@ -16,6 +17,34 @@ namespace Service::AM {
16 17
17namespace { 18namespace {
18 19
20bool ShouldCreateGuestApplet(AppletId applet_id) {
21#define X(Name, name) \
22 if (applet_id == AppletId::Name && \
23 Settings::values.name##_applet_mode.GetValue() != Settings::AppletMode::LLE) { \
24 return false; \
25 }
26
27 X(Cabinet, cabinet)
28 X(Controller, controller)
29 X(DataErase, data_erase)
30 X(Error, error)
31 X(NetConnect, net_connect)
32 X(ProfileSelect, player_select)
33 X(SoftwareKeyboard, swkbd)
34 X(MiiEdit, mii_edit)
35 X(Web, web)
36 X(Shop, shop)
37 X(PhotoViewer, photo_viewer)
38 X(OfflineWeb, offline_web)
39 X(LoginShare, login_share)
40 X(WebAuth, wifi_web_auth)
41 X(MyPage, my_page)
42
43#undef X
44
45 return true;
46}
47
19AppletProgramId AppletIdToProgramId(AppletId applet_id) { 48AppletProgramId AppletIdToProgramId(AppletId applet_id) {
20 switch (applet_id) { 49 switch (applet_id) {
21 case AppletId::OverlayDisplay: 50 case AppletId::OverlayDisplay:
@@ -63,17 +92,26 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) {
63 } 92 }
64} 93}
65 94
66[[maybe_unused]] std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet( 95std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system,
67 Core::System& system, std::shared_ptr<Applet> caller_applet, AppletId applet_id, 96 std::shared_ptr<Applet> caller_applet,
68 LibraryAppletMode mode) { 97 AppletId applet_id,
98 LibraryAppletMode mode) {
69 const auto program_id = static_cast<u64>(AppletIdToProgramId(applet_id)); 99 const auto program_id = static_cast<u64>(AppletIdToProgramId(applet_id));
70 if (program_id == 0) { 100 if (program_id == 0) {
71 // Unknown applet 101 // Unknown applet
72 return {}; 102 return {};
73 } 103 }
74 104
105 // TODO: enable other versions of applets
106 enum : u8 {
107 Firmware1400 = 14,
108 Firmware1500 = 15,
109 Firmware1600 = 16,
110 Firmware1700 = 17,
111 };
112
75 auto process = std::make_unique<Process>(system); 113 auto process = std::make_unique<Process>(system);
76 if (!process->Initialize(program_id)) { 114 if (!process->Initialize(program_id, Firmware1400, Firmware1700)) {
77 // Couldn't initialize the guest process 115 // Couldn't initialize the guest process
78 return {}; 116 return {};
79 } 117 }
@@ -87,24 +125,18 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) {
87 // Set focus state 125 // Set focus state
88 switch (mode) { 126 switch (mode) {
89 case LibraryAppletMode::AllForeground: 127 case LibraryAppletMode::AllForeground:
90 case LibraryAppletMode::NoUI: 128 case LibraryAppletMode::NoUi:
91 applet->focus_state = FocusState::InFocus; 129 case LibraryAppletMode::PartialForeground:
130 case LibraryAppletMode::PartialForegroundIndirectDisplay:
92 applet->hid_registration.EnableAppletToGetInput(true); 131 applet->hid_registration.EnableAppletToGetInput(true);
132 applet->focus_state = FocusState::InFocus;
93 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); 133 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
94 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
95 break; 134 break;
96 case LibraryAppletMode::AllForegroundInitiallyHidden: 135 case LibraryAppletMode::AllForegroundInitiallyHidden:
97 applet->system_buffer_manager.SetWindowVisibility(false);
98 applet->focus_state = FocusState::NotInFocus;
99 applet->hid_registration.EnableAppletToGetInput(false); 136 applet->hid_registration.EnableAppletToGetInput(false);
100 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); 137 applet->focus_state = FocusState::NotInFocus;
101 break; 138 applet->system_buffer_manager.SetWindowVisibility(false);
102 case LibraryAppletMode::Background: 139 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoBackground);
103 case LibraryAppletMode::BackgroundIndirectDisplay:
104 default:
105 applet->focus_state = FocusState::Background;
106 applet->hid_registration.EnableAppletToGetInput(true);
107 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
108 break; 140 break;
109 } 141 }
110 142
@@ -117,9 +149,10 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) {
117 return std::make_shared<ILibraryAppletAccessor>(system, broker, applet); 149 return std::make_shared<ILibraryAppletAccessor>(system, broker, applet);
118} 150}
119 151
120[[maybe_unused]] std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet( 152std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet(Core::System& system,
121 Core::System& system, std::shared_ptr<Applet> caller_applet, AppletId applet_id, 153 std::shared_ptr<Applet> caller_applet,
122 LibraryAppletMode mode) { 154 AppletId applet_id,
155 LibraryAppletMode mode) {
123 const auto program_id = static_cast<u64>(AppletIdToProgramId(applet_id)); 156 const auto program_id = static_cast<u64>(AppletIdToProgramId(applet_id));
124 157
125 auto process = std::make_unique<Process>(system); 158 auto process = std::make_unique<Process>(system);
@@ -163,7 +196,13 @@ void ILibraryAppletCreator::CreateLibraryApplet(HLERequestContext& ctx) {
163 LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id, 196 LOG_DEBUG(Service_AM, "called with applet_id={:08X}, applet_mode={:08X}", applet_id,
164 applet_mode); 197 applet_mode);
165 198
166 auto library_applet = CreateFrontendApplet(system, applet, applet_id, applet_mode); 199 std::shared_ptr<ILibraryAppletAccessor> library_applet;
200 if (ShouldCreateGuestApplet(applet_id)) {
201 library_applet = CreateGuestApplet(system, applet, applet_id, applet_mode);
202 }
203 if (!library_applet) {
204 library_applet = CreateFrontendApplet(system, applet, applet_id, applet_mode);
205 }
167 if (!library_applet) { 206 if (!library_applet) {
168 LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id); 207 LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);
169 208
diff --git a/src/core/hle/service/am/process.cpp b/src/core/hle/service/am/process.cpp
index 16b685f86..992c50713 100644
--- a/src/core/hle/service/am/process.cpp
+++ b/src/core/hle/service/am/process.cpp
@@ -3,6 +3,7 @@
3 3
4#include "common/scope_exit.h" 4#include "common/scope_exit.h"
5 5
6#include "core/file_sys/content_archive.h"
6#include "core/file_sys/nca_metadata.h" 7#include "core/file_sys/nca_metadata.h"
7#include "core/file_sys/registered_cache.h" 8#include "core/file_sys/registered_cache.h"
8#include "core/hle/kernel/k_process.h" 9#include "core/hle/kernel/k_process.h"
@@ -20,7 +21,7 @@ Process::~Process() {
20 this->Finalize(); 21 this->Finalize();
21} 22}
22 23
23bool Process::Initialize(u64 program_id) { 24bool Process::Initialize(u64 program_id, u8 minimum_key_generation, u8 maximum_key_generation) {
24 // First, ensure we are not holding another process. 25 // First, ensure we are not holding another process.
25 this->Finalize(); 26 this->Finalize();
26 27
@@ -29,21 +30,33 @@ bool Process::Initialize(u64 program_id) {
29 30
30 // Attempt to load program NCA. 31 // Attempt to load program NCA.
31 const FileSys::RegisteredCache* bis_system{}; 32 const FileSys::RegisteredCache* bis_system{};
32 FileSys::VirtualFile nca{}; 33 FileSys::VirtualFile nca_raw{};
33 34
34 // Get the program NCA from built-in storage. 35 // Get the program NCA from built-in storage.
35 bis_system = fsc.GetSystemNANDContents(); 36 bis_system = fsc.GetSystemNANDContents();
36 if (bis_system) { 37 if (bis_system) {
37 nca = bis_system->GetEntryRaw(program_id, FileSys::ContentRecordType::Program); 38 nca_raw = bis_system->GetEntryRaw(program_id, FileSys::ContentRecordType::Program);
38 } 39 }
39 40
40 // Ensure we retrieved a program NCA. 41 // Ensure we retrieved a program NCA.
41 if (!nca) { 42 if (!nca_raw) {
42 return false; 43 return false;
43 } 44 }
44 45
46 // Ensure we have a suitable version.
47 if (minimum_key_generation > 0) {
48 FileSys::NCA nca(nca_raw);
49 if (nca.GetStatus() == Loader::ResultStatus::Success &&
50 (nca.GetKeyGeneration() < minimum_key_generation ||
51 nca.GetKeyGeneration() > maximum_key_generation)) {
52 LOG_WARNING(Service_LDR, "Skipping program {:016X} with generation {}", program_id,
53 nca.GetKeyGeneration());
54 return false;
55 }
56 }
57
45 // Get the appropriate loader to parse this NCA. 58 // Get the appropriate loader to parse this NCA.
46 auto app_loader = Loader::GetLoader(m_system, nca, program_id, 0); 59 auto app_loader = Loader::GetLoader(m_system, nca_raw, program_id, 0);
47 60
48 // Ensure we have a loader which can parse the NCA. 61 // Ensure we have a loader which can parse the NCA.
49 if (!app_loader) { 62 if (!app_loader) {
diff --git a/src/core/hle/service/am/process.h b/src/core/hle/service/am/process.h
index 4b908ade4..4b8102fb6 100644
--- a/src/core/hle/service/am/process.h
+++ b/src/core/hle/service/am/process.h
@@ -21,7 +21,7 @@ public:
21 explicit Process(Core::System& system); 21 explicit Process(Core::System& system);
22 ~Process(); 22 ~Process();
23 23
24 bool Initialize(u64 program_id); 24 bool Initialize(u64 program_id, u8 minimum_key_generation, u8 maximum_key_generation);
25 void Finalize(); 25 void Finalize();
26 26
27 bool Run(); 27 bool Run();
diff --git a/src/core/hle/service/am/self_controller.cpp b/src/core/hle/service/am/self_controller.cpp
index 0289f5cf1..65e249c0c 100644
--- a/src/core/hle/service/am/self_controller.cpp
+++ b/src/core/hle/service/am/self_controller.cpp
@@ -1,10 +1,13 @@
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 "common/logging/log.h"
5#include "core/hle/result.h"
4#include "core/hle/service/am/am_results.h" 6#include "core/hle/service/am/am_results.h"
5#include "core/hle/service/am/frontend/applets.h" 7#include "core/hle/service/am/frontend/applets.h"
6#include "core/hle/service/am/self_controller.h" 8#include "core/hle/service/am/self_controller.h"
7#include "core/hle/service/caps/caps_su.h" 9#include "core/hle/service/caps/caps_su.h"
10#include "core/hle/service/hle_ipc.h"
8#include "core/hle/service/ipc_helpers.h" 11#include "core/hle/service/ipc_helpers.h"
9#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" 12#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
10#include "core/hle/service/nvnflinger/nvnflinger.h" 13#include "core/hle/service/nvnflinger/nvnflinger.h"
@@ -47,7 +50,7 @@ ISelfController::ISelfController(Core::System& system_, std::shared_ptr<Applet>
47 {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"}, 50 {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
48 {51, &ISelfController::ApproveToDisplay, "ApproveToDisplay"}, 51 {51, &ISelfController::ApproveToDisplay, "ApproveToDisplay"},
49 {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"}, 52 {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
50 {61, nullptr, "SetMediaPlaybackState"}, 53 {61, &ISelfController::SetMediaPlaybackState, "SetMediaPlaybackState"},
51 {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"}, 54 {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
52 {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"}, 55 {63, &ISelfController::GetIdleTimeDetectionExtension, "GetIdleTimeDetectionExtension"},
53 {64, nullptr, "SetInputDetectionSourceSet"}, 56 {64, nullptr, "SetInputDetectionSourceSet"},
@@ -288,7 +291,8 @@ void ISelfController::GetSystemSharedBufferHandle(HLERequestContext& ctx) {
288} 291}
289 292
290Result ISelfController::EnsureBufferSharingEnabled(Kernel::KProcess* process) { 293Result ISelfController::EnsureBufferSharingEnabled(Kernel::KProcess* process) {
291 if (applet->system_buffer_manager.Initialize(&nvnflinger, process, applet->applet_id)) { 294 if (applet->system_buffer_manager.Initialize(&nvnflinger, process, applet->applet_id,
295 applet->library_applet_mode)) {
292 return ResultSuccess; 296 return ResultSuccess;
293 } 297 }
294 298
@@ -323,6 +327,16 @@ void ISelfController::ApproveToDisplay(HLERequestContext& ctx) {
323 rb.Push(ResultSuccess); 327 rb.Push(ResultSuccess);
324} 328}
325 329
330void ISelfController::SetMediaPlaybackState(HLERequestContext& ctx) {
331 IPC::RequestParser rp{ctx};
332 const u8 state = rp.Pop<u8>();
333
334 LOG_WARNING(Service_AM, "(STUBBED) called, state={}", state);
335
336 IPC::ResponseBuilder rb{ctx, 2};
337 rb.Push(ResultSuccess);
338}
339
326void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) { 340void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) {
327 IPC::RequestParser rp{ctx}; 341 IPC::RequestParser rp{ctx};
328 342
diff --git a/src/core/hle/service/am/self_controller.h b/src/core/hle/service/am/self_controller.h
index a63bc2e74..ab21a1881 100644
--- a/src/core/hle/service/am/self_controller.h
+++ b/src/core/hle/service/am/self_controller.h
@@ -3,6 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include "core/hle/service/hle_ipc.h"
6#include "core/hle/service/kernel_helpers.h" 7#include "core/hle/service/kernel_helpers.h"
7#include "core/hle/service/service.h" 8#include "core/hle/service/service.h"
8 9
@@ -38,6 +39,7 @@ private:
38 void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx); 39 void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx);
39 void SetHandlesRequestToDisplay(HLERequestContext& ctx); 40 void SetHandlesRequestToDisplay(HLERequestContext& ctx);
40 void ApproveToDisplay(HLERequestContext& ctx); 41 void ApproveToDisplay(HLERequestContext& ctx);
42 void SetMediaPlaybackState(HLERequestContext& ctx);
41 void SetIdleTimeDetectionExtension(HLERequestContext& ctx); 43 void SetIdleTimeDetectionExtension(HLERequestContext& ctx);
42 void GetIdleTimeDetectionExtension(HLERequestContext& ctx); 44 void GetIdleTimeDetectionExtension(HLERequestContext& ctx);
43 void ReportUserIsActive(HLERequestContext& ctx); 45 void ReportUserIsActive(HLERequestContext& ctx);
diff --git a/src/core/hle/service/am/system_buffer_manager.cpp b/src/core/hle/service/am/system_buffer_manager.cpp
index 60a9afc9d..48923fe41 100644
--- a/src/core/hle/service/am/system_buffer_manager.cpp
+++ b/src/core/hle/service/am/system_buffer_manager.cpp
@@ -17,11 +17,12 @@ SystemBufferManager::~SystemBufferManager() {
17 17
18 // Clean up shared layers. 18 // Clean up shared layers.
19 if (m_buffer_sharing_enabled) { 19 if (m_buffer_sharing_enabled) {
20 m_nvnflinger->GetSystemBufferManager().Finalize(m_process);
20 } 21 }
21} 22}
22 23
23bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process, 24bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel::KProcess* process,
24 AppletId applet_id) { 25 AppletId applet_id, LibraryAppletMode mode) {
25 if (m_nvnflinger) { 26 if (m_nvnflinger) {
26 return m_buffer_sharing_enabled; 27 return m_buffer_sharing_enabled;
27 } 28 }
@@ -36,9 +37,15 @@ bool SystemBufferManager::Initialize(Nvnflinger::Nvnflinger* nvnflinger, Kernel:
36 return false; 37 return false;
37 } 38 }
38 39
40 Nvnflinger::LayerBlending blending = Nvnflinger::LayerBlending::None;
41 if (mode == LibraryAppletMode::PartialForeground ||
42 mode == LibraryAppletMode::PartialForegroundIndirectDisplay) {
43 blending = Nvnflinger::LayerBlending::Coverage;
44 }
45
39 const auto display_id = m_nvnflinger->OpenDisplay("Default").value(); 46 const auto display_id = m_nvnflinger->OpenDisplay("Default").value();
40 const auto res = m_nvnflinger->GetSystemBufferManager().Initialize( 47 const auto res = m_nvnflinger->GetSystemBufferManager().Initialize(
41 &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id); 48 m_process, &m_system_shared_buffer_id, &m_system_shared_layer_id, display_id, blending);
42 49
43 if (res.IsSuccess()) { 50 if (res.IsSuccess()) {
44 m_buffer_sharing_enabled = true; 51 m_buffer_sharing_enabled = true;
@@ -62,8 +69,12 @@ void SystemBufferManager::SetWindowVisibility(bool visible) {
62 69
63Result SystemBufferManager::WriteAppletCaptureBuffer(bool* out_was_written, 70Result SystemBufferManager::WriteAppletCaptureBuffer(bool* out_was_written,
64 s32* out_fbshare_layer_index) { 71 s32* out_fbshare_layer_index) {
65 // TODO 72 if (!m_buffer_sharing_enabled) {
66 R_SUCCEED(); 73 return VI::ResultPermissionDenied;
74 }
75
76 return m_nvnflinger->GetSystemBufferManager().WriteAppletCaptureBuffer(out_was_written,
77 out_fbshare_layer_index);
67} 78}
68 79
69} // namespace Service::AM 80} // namespace Service::AM
diff --git a/src/core/hle/service/am/system_buffer_manager.h b/src/core/hle/service/am/system_buffer_manager.h
index 98c3cf055..0690f68b6 100644
--- a/src/core/hle/service/am/system_buffer_manager.h
+++ b/src/core/hle/service/am/system_buffer_manager.h
@@ -27,7 +27,8 @@ public:
27 SystemBufferManager(); 27 SystemBufferManager();
28 ~SystemBufferManager(); 28 ~SystemBufferManager();
29 29
30 bool Initialize(Nvnflinger::Nvnflinger* flinger, Kernel::KProcess* process, AppletId applet_id); 30 bool Initialize(Nvnflinger::Nvnflinger* flinger, Kernel::KProcess* process, AppletId applet_id,
31 LibraryAppletMode mode);
31 32
32 void GetSystemSharedLayerHandle(u64* out_system_shared_buffer_id, 33 void GetSystemSharedLayerHandle(u64* out_system_shared_buffer_id,
33 u64* out_system_shared_layer_id) { 34 u64* out_system_shared_layer_id) {
diff --git a/src/core/hle/service/am/window_controller.cpp b/src/core/hle/service/am/window_controller.cpp
index f00957f83..c07ef228b 100644
--- a/src/core/hle/service/am/window_controller.cpp
+++ b/src/core/hle/service/am/window_controller.cpp
@@ -62,12 +62,12 @@ void IWindowController::SetAppletWindowVisibility(HLERequestContext& ctx) {
62 applet->hid_registration.EnableAppletToGetInput(visible); 62 applet->hid_registration.EnableAppletToGetInput(visible);
63 63
64 if (visible) { 64 if (visible) {
65 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
66 applet->focus_state = FocusState::InFocus; 65 applet->focus_state = FocusState::InFocus;
66 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
67 } else { 67 } else {
68 applet->focus_state = FocusState::NotInFocus; 68 applet->focus_state = FocusState::NotInFocus;
69 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoBackground);
69 } 70 }
70 applet->message_queue.PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
71 71
72 IPC::ResponseBuilder rb{ctx, 2}; 72 IPC::ResponseBuilder rb{ctx, 2};
73 rb.Push(ResultSuccess); 73 rb.Push(ResultSuccess);