am.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <chrono>
  6. #include <memory>
  7. #include <queue>
  8. #include "core/hle/kernel/writable_event.h"
  9. #include "core/hle/service/service.h"
  10. namespace Kernel {
  11. class KernelCore;
  12. class TransferMemory;
  13. } // namespace Kernel
  14. namespace Service::NVFlinger {
  15. class NVFlinger;
  16. }
  17. namespace Service::AM {
  18. enum SystemLanguage {
  19. Japanese = 0,
  20. English = 1, // en-US
  21. French = 2,
  22. German = 3,
  23. Italian = 4,
  24. Spanish = 5,
  25. Chinese = 6,
  26. Korean = 7,
  27. Dutch = 8,
  28. Portuguese = 9,
  29. Russian = 10,
  30. Taiwanese = 11,
  31. BritishEnglish = 12, // en-GB
  32. CanadianFrench = 13,
  33. LatinAmericanSpanish = 14, // es-419
  34. // 4.0.0+
  35. SimplifiedChinese = 15,
  36. TraditionalChinese = 16,
  37. };
  38. class AppletMessageQueue {
  39. public:
  40. enum class AppletMessage : u32 {
  41. NoMessage = 0,
  42. ExitRequested = 4,
  43. FocusStateChanged = 15,
  44. OperationModeChanged = 30,
  45. PerformanceModeChanged = 31,
  46. };
  47. explicit AppletMessageQueue(Kernel::KernelCore& kernel);
  48. ~AppletMessageQueue();
  49. const std::shared_ptr<Kernel::ReadableEvent>& GetMesssageRecieveEvent() const;
  50. const std::shared_ptr<Kernel::ReadableEvent>& GetOperationModeChangedEvent() const;
  51. void PushMessage(AppletMessage msg);
  52. AppletMessage PopMessage();
  53. std::size_t GetMessageCount() const;
  54. void OperationModeChanged();
  55. void RequestExit();
  56. private:
  57. std::queue<AppletMessage> messages;
  58. Kernel::EventPair on_new_message;
  59. Kernel::EventPair on_operation_mode_changed;
  60. };
  61. class IWindowController final : public ServiceFramework<IWindowController> {
  62. public:
  63. explicit IWindowController(Core::System& system_);
  64. ~IWindowController() override;
  65. private:
  66. void GetAppletResourceUserId(Kernel::HLERequestContext& ctx);
  67. void AcquireForegroundRights(Kernel::HLERequestContext& ctx);
  68. Core::System& system;
  69. };
  70. class IAudioController final : public ServiceFramework<IAudioController> {
  71. public:
  72. IAudioController();
  73. ~IAudioController() override;
  74. private:
  75. void SetExpectedMasterVolume(Kernel::HLERequestContext& ctx);
  76. void GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx);
  77. void GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx);
  78. void ChangeMainAppletMasterVolume(Kernel::HLERequestContext& ctx);
  79. void SetTransparentAudioRate(Kernel::HLERequestContext& ctx);
  80. static constexpr float min_allowed_volume = 0.0f;
  81. static constexpr float max_allowed_volume = 1.0f;
  82. float main_applet_volume{0.25f};
  83. float library_applet_volume{max_allowed_volume};
  84. float transparent_volume_rate{min_allowed_volume};
  85. // Volume transition fade time in nanoseconds.
  86. // e.g. If the main applet volume was 0% and was changed to 50%
  87. // with a fade of 50ns, then over the course of 50ns,
  88. // the volume will gradually fade up to 50%
  89. std::chrono::nanoseconds fade_time_ns{0};
  90. };
  91. class IDisplayController final : public ServiceFramework<IDisplayController> {
  92. public:
  93. IDisplayController();
  94. ~IDisplayController() override;
  95. };
  96. class IDebugFunctions final : public ServiceFramework<IDebugFunctions> {
  97. public:
  98. IDebugFunctions();
  99. ~IDebugFunctions() override;
  100. };
  101. class ISelfController final : public ServiceFramework<ISelfController> {
  102. public:
  103. explicit ISelfController(Core::System& system_,
  104. std::shared_ptr<NVFlinger::NVFlinger> nvflinger_);
  105. ~ISelfController() override;
  106. private:
  107. void Exit(Kernel::HLERequestContext& ctx);
  108. void LockExit(Kernel::HLERequestContext& ctx);
  109. void UnlockExit(Kernel::HLERequestContext& ctx);
  110. void EnterFatalSection(Kernel::HLERequestContext& ctx);
  111. void LeaveFatalSection(Kernel::HLERequestContext& ctx);
  112. void GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx);
  113. void SetScreenShotPermission(Kernel::HLERequestContext& ctx);
  114. void SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx);
  115. void SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx);
  116. void SetFocusHandlingMode(Kernel::HLERequestContext& ctx);
  117. void SetRestartMessageEnabled(Kernel::HLERequestContext& ctx);
  118. void SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx);
  119. void SetAlbumImageOrientation(Kernel::HLERequestContext& ctx);
  120. void CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx);
  121. void CreateManagedDisplaySeparableLayer(Kernel::HLERequestContext& ctx);
  122. void SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx);
  123. void SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx);
  124. void GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx);
  125. void SetAutoSleepDisabled(Kernel::HLERequestContext& ctx);
  126. void IsAutoSleepDisabled(Kernel::HLERequestContext& ctx);
  127. void GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext& ctx);
  128. void GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequestContext& ctx);
  129. enum class ScreenshotPermission : u32 {
  130. Inherit = 0,
  131. Enable = 1,
  132. Disable = 2,
  133. };
  134. Core::System& system;
  135. std::shared_ptr<NVFlinger::NVFlinger> nvflinger;
  136. Kernel::EventPair launchable_event;
  137. Kernel::EventPair accumulated_suspended_tick_changed_event;
  138. u32 idle_time_detection_extension = 0;
  139. u64 num_fatal_sections_entered = 0;
  140. bool is_auto_sleep_disabled = false;
  141. ScreenshotPermission screenshot_permission = ScreenshotPermission::Inherit;
  142. };
  143. class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> {
  144. public:
  145. explicit ICommonStateGetter(Core::System& system,
  146. std::shared_ptr<AppletMessageQueue> msg_queue);
  147. ~ICommonStateGetter() override;
  148. private:
  149. enum class FocusState : u8 {
  150. InFocus = 1,
  151. NotInFocus = 2,
  152. };
  153. enum class OperationMode : u8 {
  154. Handheld = 0,
  155. Docked = 1,
  156. };
  157. void GetEventHandle(Kernel::HLERequestContext& ctx);
  158. void ReceiveMessage(Kernel::HLERequestContext& ctx);
  159. void GetCurrentFocusState(Kernel::HLERequestContext& ctx);
  160. void GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx);
  161. void GetOperationMode(Kernel::HLERequestContext& ctx);
  162. void GetPerformanceMode(Kernel::HLERequestContext& ctx);
  163. void GetBootMode(Kernel::HLERequestContext& ctx);
  164. void IsVrModeEnabled(Kernel::HLERequestContext& ctx);
  165. void SetVrModeEnabled(Kernel::HLERequestContext& ctx);
  166. void SetLcdBacklighOffEnabled(Kernel::HLERequestContext& ctx);
  167. void EndVrModeEx(Kernel::HLERequestContext& ctx);
  168. void GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx);
  169. void SetCpuBoostMode(Kernel::HLERequestContext& ctx);
  170. Core::System& system;
  171. std::shared_ptr<AppletMessageQueue> msg_queue;
  172. bool vr_mode_state{};
  173. };
  174. class IStorageImpl {
  175. public:
  176. virtual ~IStorageImpl();
  177. virtual std::vector<u8>& GetData() = 0;
  178. virtual const std::vector<u8>& GetData() const = 0;
  179. virtual std::size_t GetSize() const = 0;
  180. };
  181. class IStorage final : public ServiceFramework<IStorage> {
  182. public:
  183. explicit IStorage(std::vector<u8>&& buffer);
  184. ~IStorage() override;
  185. std::vector<u8>& GetData() {
  186. return impl->GetData();
  187. }
  188. const std::vector<u8>& GetData() const {
  189. return impl->GetData();
  190. }
  191. std::size_t GetSize() const {
  192. return impl->GetSize();
  193. }
  194. private:
  195. void Register();
  196. void Open(Kernel::HLERequestContext& ctx);
  197. std::shared_ptr<IStorageImpl> impl;
  198. };
  199. class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
  200. public:
  201. explicit IStorageAccessor(IStorage& backing);
  202. ~IStorageAccessor() override;
  203. private:
  204. void GetSize(Kernel::HLERequestContext& ctx);
  205. void Write(Kernel::HLERequestContext& ctx);
  206. void Read(Kernel::HLERequestContext& ctx);
  207. IStorage& backing;
  208. };
  209. class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
  210. public:
  211. explicit ILibraryAppletCreator(Core::System& system_);
  212. ~ILibraryAppletCreator() override;
  213. private:
  214. void CreateLibraryApplet(Kernel::HLERequestContext& ctx);
  215. void CreateStorage(Kernel::HLERequestContext& ctx);
  216. void CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx);
  217. Core::System& system;
  218. };
  219. class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> {
  220. public:
  221. explicit IApplicationFunctions(Core::System& system_);
  222. ~IApplicationFunctions() override;
  223. private:
  224. void PopLaunchParameter(Kernel::HLERequestContext& ctx);
  225. void CreateApplicationAndRequestToStartForQuest(Kernel::HLERequestContext& ctx);
  226. void EnsureSaveData(Kernel::HLERequestContext& ctx);
  227. void SetTerminateResult(Kernel::HLERequestContext& ctx);
  228. void GetDisplayVersion(Kernel::HLERequestContext& ctx);
  229. void GetDesiredLanguage(Kernel::HLERequestContext& ctx);
  230. void InitializeGamePlayRecording(Kernel::HLERequestContext& ctx);
  231. void SetGamePlayRecordingState(Kernel::HLERequestContext& ctx);
  232. void NotifyRunning(Kernel::HLERequestContext& ctx);
  233. void GetPseudoDeviceId(Kernel::HLERequestContext& ctx);
  234. void ExtendSaveData(Kernel::HLERequestContext& ctx);
  235. void GetSaveDataSize(Kernel::HLERequestContext& ctx);
  236. void BeginBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx);
  237. void EndBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx);
  238. void BeginBlockingHomeButton(Kernel::HLERequestContext& ctx);
  239. void EndBlockingHomeButton(Kernel::HLERequestContext& ctx);
  240. void EnableApplicationCrashReport(Kernel::HLERequestContext& ctx);
  241. void InitializeApplicationCopyrightFrameBuffer(Kernel::HLERequestContext& ctx);
  242. void SetApplicationCopyrightImage(Kernel::HLERequestContext& ctx);
  243. void SetApplicationCopyrightVisibility(Kernel::HLERequestContext& ctx);
  244. void QueryApplicationPlayStatistics(Kernel::HLERequestContext& ctx);
  245. void QueryApplicationPlayStatisticsByUid(Kernel::HLERequestContext& ctx);
  246. void GetPreviousProgramIndex(Kernel::HLERequestContext& ctx);
  247. void GetGpuErrorDetectedSystemEvent(Kernel::HLERequestContext& ctx);
  248. void GetFriendInvitationStorageChannelEvent(Kernel::HLERequestContext& ctx);
  249. bool launch_popped_application_specific = false;
  250. bool launch_popped_account_preselect = false;
  251. s32 previous_program_index{-1};
  252. Kernel::EventPair gpu_error_detected_event;
  253. Kernel::EventPair friend_invitation_storage_channel_event;
  254. Core::System& system;
  255. };
  256. class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
  257. public:
  258. explicit IHomeMenuFunctions(Kernel::KernelCore& kernel);
  259. ~IHomeMenuFunctions() override;
  260. private:
  261. void RequestToGetForeground(Kernel::HLERequestContext& ctx);
  262. void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx);
  263. Kernel::EventPair pop_from_general_channel_event;
  264. Kernel::KernelCore& kernel;
  265. };
  266. class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
  267. public:
  268. IGlobalStateController();
  269. ~IGlobalStateController() override;
  270. };
  271. class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
  272. public:
  273. IApplicationCreator();
  274. ~IApplicationCreator() override;
  275. };
  276. class IProcessWindingController final : public ServiceFramework<IProcessWindingController> {
  277. public:
  278. IProcessWindingController();
  279. ~IProcessWindingController() override;
  280. };
  281. /// Registers all AM services with the specified service manager.
  282. void InstallInterfaces(SM::ServiceManager& service_manager,
  283. std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system);
  284. } // namespace Service::AM