summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Narr the Reg2023-09-29 00:13:56 -0600
committerGravatar Narr the Reg2023-10-01 11:38:30 -0600
commit2687a83f6a6f7fb98069d2b35a9972bc0c9027a1 (patch)
tree04dd5213ac472adc0fca939ed226445791645e20 /src
parentservice: nvnflinger: Implement shared buffer (diff)
downloadyuzu-2687a83f6a6f7fb98069d2b35a9972bc0c9027a1.tar.gz
yuzu-2687a83f6a6f7fb98069d2b35a9972bc0c9027a1.tar.xz
yuzu-2687a83f6a6f7fb98069d2b35a9972bc0c9027a1.zip
service: am: Implement shared buffer
Co-authored-by: Liam <byteslice@airmail.cc>
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/am/am.cpp119
-rw-r--r--src/core/hle/service/am/am.h16
2 files changed, 125 insertions, 10 deletions
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 2f6503427..05182a6ab 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -35,11 +35,13 @@
35#include "core/hle/service/filesystem/filesystem.h" 35#include "core/hle/service/filesystem/filesystem.h"
36#include "core/hle/service/ipc_helpers.h" 36#include "core/hle/service/ipc_helpers.h"
37#include "core/hle/service/ns/ns.h" 37#include "core/hle/service/ns/ns.h"
38#include "core/hle/service/nvnflinger/fb_share_buffer_manager.h"
38#include "core/hle/service/nvnflinger/nvnflinger.h" 39#include "core/hle/service/nvnflinger/nvnflinger.h"
39#include "core/hle/service/pm/pm.h" 40#include "core/hle/service/pm/pm.h"
40#include "core/hle/service/server_manager.h" 41#include "core/hle/service/server_manager.h"
41#include "core/hle/service/sm/sm.h" 42#include "core/hle/service/sm/sm.h"
42#include "core/hle/service/vi/vi.h" 43#include "core/hle/service/vi/vi.h"
44#include "core/hle/service/vi/vi_results.h"
43#include "core/memory.h" 45#include "core/memory.h"
44 46
45namespace Service::AM { 47namespace Service::AM {
@@ -192,7 +194,7 @@ IDisplayController::IDisplayController(Core::System& system_)
192 {4, nullptr, "UpdateCallerAppletCaptureImage"}, 194 {4, nullptr, "UpdateCallerAppletCaptureImage"},
193 {5, nullptr, "GetLastForegroundCaptureImageEx"}, 195 {5, nullptr, "GetLastForegroundCaptureImageEx"},
194 {6, nullptr, "GetLastApplicationCaptureImageEx"}, 196 {6, nullptr, "GetLastApplicationCaptureImageEx"},
195 {7, nullptr, "GetCallerAppletCaptureImageEx"}, 197 {7, &IDisplayController::GetCallerAppletCaptureImageEx, "GetCallerAppletCaptureImageEx"},
196 {8, &IDisplayController::TakeScreenShotOfOwnLayer, "TakeScreenShotOfOwnLayer"}, 198 {8, &IDisplayController::TakeScreenShotOfOwnLayer, "TakeScreenShotOfOwnLayer"},
197 {9, nullptr, "CopyBetweenCaptureBuffers"}, 199 {9, nullptr, "CopyBetweenCaptureBuffers"},
198 {10, nullptr, "AcquireLastApplicationCaptureBuffer"}, 200 {10, nullptr, "AcquireLastApplicationCaptureBuffer"},
@@ -210,8 +212,8 @@ IDisplayController::IDisplayController(Core::System& system_)
210 {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"}, 212 {23, nullptr, "ReleaseLastApplicationCaptureSharedBuffer"},
211 {24, nullptr, "AcquireLastForegroundCaptureSharedBuffer"}, 213 {24, nullptr, "AcquireLastForegroundCaptureSharedBuffer"},
212 {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"}, 214 {25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"},
213 {26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"}, 215 {26, &IDisplayController::AcquireCallerAppletCaptureSharedBuffer, "AcquireCallerAppletCaptureSharedBuffer"},
214 {27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"}, 216 {27, &IDisplayController::ReleaseCallerAppletCaptureSharedBuffer, "ReleaseCallerAppletCaptureSharedBuffer"},
215 {28, nullptr, "TakeScreenShotOfOwnLayerEx"}, 217 {28, nullptr, "TakeScreenShotOfOwnLayerEx"},
216 }; 218 };
217 // clang-format on 219 // clang-format on
@@ -221,6 +223,15 @@ IDisplayController::IDisplayController(Core::System& system_)
221 223
222IDisplayController::~IDisplayController() = default; 224IDisplayController::~IDisplayController() = default;
223 225
226void IDisplayController::GetCallerAppletCaptureImageEx(HLERequestContext& ctx) {
227 LOG_WARNING(Service_AM, "(STUBBED) called");
228
229 IPC::ResponseBuilder rb{ctx, 4};
230 rb.Push(ResultSuccess);
231 rb.Push(1u);
232 rb.Push(0);
233}
234
224void IDisplayController::TakeScreenShotOfOwnLayer(HLERequestContext& ctx) { 235void IDisplayController::TakeScreenShotOfOwnLayer(HLERequestContext& ctx) {
225 LOG_WARNING(Service_AM, "(STUBBED) called"); 236 LOG_WARNING(Service_AM, "(STUBBED) called");
226 237
@@ -228,6 +239,22 @@ void IDisplayController::TakeScreenShotOfOwnLayer(HLERequestContext& ctx) {
228 rb.Push(ResultSuccess); 239 rb.Push(ResultSuccess);
229} 240}
230 241
242void IDisplayController::AcquireCallerAppletCaptureSharedBuffer(HLERequestContext& ctx) {
243 LOG_WARNING(Service_AM, "(STUBBED) called");
244
245 IPC::ResponseBuilder rb{ctx, 4};
246 rb.Push(ResultSuccess);
247 rb.Push(1U);
248 rb.Push(0);
249}
250
251void IDisplayController::ReleaseCallerAppletCaptureSharedBuffer(HLERequestContext& ctx) {
252 LOG_WARNING(Service_AM, "(STUBBED) called");
253
254 IPC::ResponseBuilder rb{ctx, 2};
255 rb.Push(ResultSuccess);
256}
257
231IDebugFunctions::IDebugFunctions(Core::System& system_) 258IDebugFunctions::IDebugFunctions(Core::System& system_)
232 : ServiceFramework{system_, "IDebugFunctions"} { 259 : ServiceFramework{system_, "IDebugFunctions"} {
233 // clang-format off 260 // clang-format off
@@ -287,14 +314,14 @@ ISelfController::ISelfController(Core::System& system_, Nvnflinger::Nvnflinger&
287 {20, nullptr, "SetDesirableKeyboardLayout"}, 314 {20, nullptr, "SetDesirableKeyboardLayout"},
288 {21, nullptr, "GetScreenShotProgramId"}, 315 {21, nullptr, "GetScreenShotProgramId"},
289 {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"}, 316 {40, &ISelfController::CreateManagedDisplayLayer, "CreateManagedDisplayLayer"},
290 {41, nullptr, "IsSystemBufferSharingEnabled"}, 317 {41, &ISelfController::IsSystemBufferSharingEnabled, "IsSystemBufferSharingEnabled"},
291 {42, nullptr, "GetSystemSharedLayerHandle"}, 318 {42, &ISelfController::GetSystemSharedLayerHandle, "GetSystemSharedLayerHandle"},
292 {43, nullptr, "GetSystemSharedBufferHandle"}, 319 {43, &ISelfController::GetSystemSharedBufferHandle, "GetSystemSharedBufferHandle"},
293 {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"}, 320 {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"},
294 {45, nullptr, "SetManagedDisplayLayerSeparationMode"}, 321 {45, nullptr, "SetManagedDisplayLayerSeparationMode"},
295 {46, nullptr, "SetRecordingLayerCompositionEnabled"}, 322 {46, nullptr, "SetRecordingLayerCompositionEnabled"},
296 {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"}, 323 {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"},
297 {51, nullptr, "ApproveToDisplay"}, 324 {51, &ISelfController::ApproveToDisplay, "ApproveToDisplay"},
298 {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"}, 325 {60, nullptr, "OverrideAutoSleepTimeAndDimmingTime"},
299 {61, nullptr, "SetMediaPlaybackState"}, 326 {61, nullptr, "SetMediaPlaybackState"},
300 {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"}, 327 {62, &ISelfController::SetIdleTimeDetectionExtension, "SetIdleTimeDetectionExtension"},
@@ -493,6 +520,50 @@ void ISelfController::CreateManagedDisplayLayer(HLERequestContext& ctx) {
493 rb.Push(*layer_id); 520 rb.Push(*layer_id);
494} 521}
495 522
523void ISelfController::IsSystemBufferSharingEnabled(HLERequestContext& ctx) {
524 LOG_WARNING(Service_AM, "(STUBBED) called");
525
526 IPC::ResponseBuilder rb{ctx, 2};
527 rb.Push(this->EnsureBufferSharingEnabled());
528}
529
530void ISelfController::GetSystemSharedLayerHandle(HLERequestContext& ctx) {
531 LOG_WARNING(Service_AM, "(STUBBED) called");
532
533 IPC::ResponseBuilder rb{ctx, 6};
534 rb.Push(this->EnsureBufferSharingEnabled());
535 rb.Push<s64>(system_shared_buffer_id);
536 rb.Push<s64>(system_shared_layer_id);
537}
538
539void ISelfController::GetSystemSharedBufferHandle(HLERequestContext& ctx) {
540 LOG_WARNING(Service_AM, "(STUBBED) called");
541
542 IPC::ResponseBuilder rb{ctx, 4};
543 rb.Push(this->EnsureBufferSharingEnabled());
544 rb.Push<s64>(system_shared_buffer_id);
545}
546
547Result ISelfController::EnsureBufferSharingEnabled() {
548 if (buffer_sharing_enabled) {
549 return ResultSuccess;
550 }
551
552 if (system.GetAppletManager().GetCurrentAppletId() <= Applets::AppletId::Application) {
553 return VI::ResultOperationFailed;
554 }
555
556 const auto display_id = nvnflinger.OpenDisplay("Default");
557 const auto result = nvnflinger.GetSystemBufferManager().Initialize(
558 &system_shared_buffer_id, &system_shared_layer_id, *display_id);
559
560 if (result.IsSuccess()) {
561 buffer_sharing_enabled = true;
562 }
563
564 return result;
565}
566
496void ISelfController::CreateManagedDisplaySeparableLayer(HLERequestContext& ctx) { 567void ISelfController::CreateManagedDisplaySeparableLayer(HLERequestContext& ctx) {
497 LOG_WARNING(Service_AM, "(STUBBED) called"); 568 LOG_WARNING(Service_AM, "(STUBBED) called");
498 569
@@ -518,6 +589,13 @@ void ISelfController::SetHandlesRequestToDisplay(HLERequestContext& ctx) {
518 rb.Push(ResultSuccess); 589 rb.Push(ResultSuccess);
519} 590}
520 591
592void ISelfController::ApproveToDisplay(HLERequestContext& ctx) {
593 LOG_WARNING(Service_AM, "(STUBBED) called");
594
595 IPC::ResponseBuilder rb{ctx, 2};
596 rb.Push(ResultSuccess);
597}
598
521void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) { 599void ISelfController::SetIdleTimeDetectionExtension(HLERequestContext& ctx) {
522 IPC::RequestParser rp{ctx}; 600 IPC::RequestParser rp{ctx};
523 idle_time_detection_extension = rp.Pop<u32>(); 601 idle_time_detection_extension = rp.Pop<u32>();
@@ -688,7 +766,8 @@ void AppletMessageQueue::OperationModeChanged() {
688 766
689ICommonStateGetter::ICommonStateGetter(Core::System& system_, 767ICommonStateGetter::ICommonStateGetter(Core::System& system_,
690 std::shared_ptr<AppletMessageQueue> msg_queue_) 768 std::shared_ptr<AppletMessageQueue> msg_queue_)
691 : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)} { 769 : ServiceFramework{system_, "ICommonStateGetter"}, msg_queue{std::move(msg_queue_)},
770 service_context{system_, "ICommonStateGetter"} {
692 // clang-format off 771 // clang-format off
693 static const FunctionInfo functions[] = { 772 static const FunctionInfo functions[] = {
694 {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"}, 773 {0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
@@ -701,10 +780,10 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_,
701 {7, nullptr, "GetCradleStatus"}, 780 {7, nullptr, "GetCradleStatus"},
702 {8, &ICommonStateGetter::GetBootMode, "GetBootMode"}, 781 {8, &ICommonStateGetter::GetBootMode, "GetBootMode"},
703 {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"}, 782 {9, &ICommonStateGetter::GetCurrentFocusState, "GetCurrentFocusState"},
704 {10, nullptr, "RequestToAcquireSleepLock"}, 783 {10, &ICommonStateGetter::RequestToAcquireSleepLock, "RequestToAcquireSleepLock"},
705 {11, nullptr, "ReleaseSleepLock"}, 784 {11, nullptr, "ReleaseSleepLock"},
706 {12, nullptr, "ReleaseSleepLockTransiently"}, 785 {12, nullptr, "ReleaseSleepLockTransiently"},
707 {13, nullptr, "GetAcquiredSleepLockEvent"}, 786 {13, &ICommonStateGetter::GetAcquiredSleepLockEvent, "GetAcquiredSleepLockEvent"},
708 {14, nullptr, "GetWakeupCount"}, 787 {14, nullptr, "GetWakeupCount"},
709 {20, nullptr, "PushToGeneralChannel"}, 788 {20, nullptr, "PushToGeneralChannel"},
710 {30, nullptr, "GetHomeButtonReaderLockAccessor"}, 789 {30, nullptr, "GetHomeButtonReaderLockAccessor"},
@@ -747,6 +826,8 @@ ICommonStateGetter::ICommonStateGetter(Core::System& system_,
747 826
748 RegisterHandlers(functions); 827 RegisterHandlers(functions);
749 828
829 sleep_lock_event = service_context.CreateEvent("ICommonStateGetter::SleepLockEvent");
830
750 // Configure applets to be in foreground state 831 // Configure applets to be in foreground state
751 msg_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged); 832 msg_queue->PushMessage(AppletMessageQueue::AppletMessage::FocusStateChanged);
752 msg_queue->PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground); 833 msg_queue->PushMessage(AppletMessageQueue::AppletMessage::ChangeIntoForeground);
@@ -795,6 +876,24 @@ void ICommonStateGetter::GetCurrentFocusState(HLERequestContext& ctx) {
795 rb.Push(static_cast<u8>(FocusState::InFocus)); 876 rb.Push(static_cast<u8>(FocusState::InFocus));
796} 877}
797 878
879void ICommonStateGetter::RequestToAcquireSleepLock(HLERequestContext& ctx) {
880 LOG_WARNING(Service_AM, "(STUBBED) called");
881
882 // Sleep lock is acquired immediately.
883 sleep_lock_event->Signal();
884
885 IPC::ResponseBuilder rb{ctx, 2};
886 rb.Push(ResultSuccess);
887}
888
889void ICommonStateGetter::GetAcquiredSleepLockEvent(HLERequestContext& ctx) {
890 LOG_WARNING(Service_AM, "called");
891
892 IPC::ResponseBuilder rb{ctx, 2, 1};
893 rb.Push(ResultSuccess);
894 rb.PushCopyObjects(sleep_lock_event->GetReadableEvent());
895}
896
798void ICommonStateGetter::IsVrModeEnabled(HLERequestContext& ctx) { 897void ICommonStateGetter::IsVrModeEnabled(HLERequestContext& ctx) {
799 LOG_DEBUG(Service_AM, "called"); 898 LOG_DEBUG(Service_AM, "called");
800 899
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index 10b79188f..349482dcc 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -122,7 +122,10 @@ public:
122 ~IDisplayController() override; 122 ~IDisplayController() override;
123 123
124private: 124private:
125 void GetCallerAppletCaptureImageEx(HLERequestContext& ctx);
125 void TakeScreenShotOfOwnLayer(HLERequestContext& ctx); 126 void TakeScreenShotOfOwnLayer(HLERequestContext& ctx);
127 void AcquireCallerAppletCaptureSharedBuffer(HLERequestContext& ctx);
128 void ReleaseCallerAppletCaptureSharedBuffer(HLERequestContext& ctx);
126}; 129};
127 130
128class IDebugFunctions final : public ServiceFramework<IDebugFunctions> { 131class IDebugFunctions final : public ServiceFramework<IDebugFunctions> {
@@ -150,9 +153,13 @@ private:
150 void SetRestartMessageEnabled(HLERequestContext& ctx); 153 void SetRestartMessageEnabled(HLERequestContext& ctx);
151 void SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx); 154 void SetOutOfFocusSuspendingEnabled(HLERequestContext& ctx);
152 void SetAlbumImageOrientation(HLERequestContext& ctx); 155 void SetAlbumImageOrientation(HLERequestContext& ctx);
156 void IsSystemBufferSharingEnabled(HLERequestContext& ctx);
157 void GetSystemSharedBufferHandle(HLERequestContext& ctx);
158 void GetSystemSharedLayerHandle(HLERequestContext& ctx);
153 void CreateManagedDisplayLayer(HLERequestContext& ctx); 159 void CreateManagedDisplayLayer(HLERequestContext& ctx);
154 void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx); 160 void CreateManagedDisplaySeparableLayer(HLERequestContext& ctx);
155 void SetHandlesRequestToDisplay(HLERequestContext& ctx); 161 void SetHandlesRequestToDisplay(HLERequestContext& ctx);
162 void ApproveToDisplay(HLERequestContext& ctx);
156 void SetIdleTimeDetectionExtension(HLERequestContext& ctx); 163 void SetIdleTimeDetectionExtension(HLERequestContext& ctx);
157 void GetIdleTimeDetectionExtension(HLERequestContext& ctx); 164 void GetIdleTimeDetectionExtension(HLERequestContext& ctx);
158 void ReportUserIsActive(HLERequestContext& ctx); 165 void ReportUserIsActive(HLERequestContext& ctx);
@@ -164,6 +171,8 @@ private:
164 void SaveCurrentScreenshot(HLERequestContext& ctx); 171 void SaveCurrentScreenshot(HLERequestContext& ctx);
165 void SetRecordVolumeMuted(HLERequestContext& ctx); 172 void SetRecordVolumeMuted(HLERequestContext& ctx);
166 173
174 Result EnsureBufferSharingEnabled();
175
167 enum class ScreenshotPermission : u32 { 176 enum class ScreenshotPermission : u32 {
168 Inherit = 0, 177 Inherit = 0,
169 Enable = 1, 178 Enable = 1,
@@ -179,7 +188,10 @@ private:
179 188
180 u32 idle_time_detection_extension = 0; 189 u32 idle_time_detection_extension = 0;
181 u64 num_fatal_sections_entered = 0; 190 u64 num_fatal_sections_entered = 0;
191 u64 system_shared_buffer_id = 0;
192 u64 system_shared_layer_id = 0;
182 bool is_auto_sleep_disabled = false; 193 bool is_auto_sleep_disabled = false;
194 bool buffer_sharing_enabled = false;
183 ScreenshotPermission screenshot_permission = ScreenshotPermission::Inherit; 195 ScreenshotPermission screenshot_permission = ScreenshotPermission::Inherit;
184}; 196};
185 197
@@ -223,6 +235,8 @@ private:
223 void GetEventHandle(HLERequestContext& ctx); 235 void GetEventHandle(HLERequestContext& ctx);
224 void ReceiveMessage(HLERequestContext& ctx); 236 void ReceiveMessage(HLERequestContext& ctx);
225 void GetCurrentFocusState(HLERequestContext& ctx); 237 void GetCurrentFocusState(HLERequestContext& ctx);
238 void RequestToAcquireSleepLock(HLERequestContext& ctx);
239 void GetAcquiredSleepLockEvent(HLERequestContext& ctx);
226 void GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx); 240 void GetDefaultDisplayResolutionChangeEvent(HLERequestContext& ctx);
227 void GetOperationMode(HLERequestContext& ctx); 241 void GetOperationMode(HLERequestContext& ctx);
228 void GetPerformanceMode(HLERequestContext& ctx); 242 void GetPerformanceMode(HLERequestContext& ctx);
@@ -240,6 +254,8 @@ private:
240 254
241 std::shared_ptr<AppletMessageQueue> msg_queue; 255 std::shared_ptr<AppletMessageQueue> msg_queue;
242 bool vr_mode_state{}; 256 bool vr_mode_state{};
257 Kernel::KEvent* sleep_lock_event;
258 KernelHelpers::ServiceContext service_context;
243}; 259};
244 260
245class IStorageImpl { 261class IStorageImpl {