am.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 Service {
  11. namespace NVFlinger {
  12. class NVFlinger;
  13. }
  14. namespace AM {
  15. enum SystemLanguage {
  16. Japanese = 0,
  17. English = 1, // en-US
  18. French = 2,
  19. German = 3,
  20. Italian = 4,
  21. Spanish = 5,
  22. Chinese = 6,
  23. Korean = 7,
  24. Dutch = 8,
  25. Portuguese = 9,
  26. Russian = 10,
  27. Taiwanese = 11,
  28. BritishEnglish = 12, // en-GB
  29. CanadianFrench = 13,
  30. LatinAmericanSpanish = 14, // es-419
  31. // 4.0.0+
  32. SimplifiedChinese = 15,
  33. TraditionalChinese = 16,
  34. };
  35. class AppletMessageQueue {
  36. public:
  37. enum class AppletMessage : u32 {
  38. NoMessage = 0,
  39. FocusStateChanged = 15,
  40. OperationModeChanged = 30,
  41. PerformanceModeChanged = 31,
  42. };
  43. AppletMessageQueue();
  44. ~AppletMessageQueue();
  45. const Kernel::SharedPtr<Kernel::ReadableEvent>& GetMesssageRecieveEvent() const;
  46. const Kernel::SharedPtr<Kernel::ReadableEvent>& GetOperationModeChangedEvent() const;
  47. void PushMessage(AppletMessage msg);
  48. AppletMessage PopMessage();
  49. std::size_t GetMessageCount() const;
  50. void OperationModeChanged();
  51. private:
  52. std::queue<AppletMessage> messages;
  53. Kernel::EventPair on_new_message;
  54. Kernel::EventPair on_operation_mode_changed;
  55. };
  56. class IWindowController final : public ServiceFramework<IWindowController> {
  57. public:
  58. IWindowController();
  59. ~IWindowController() override;
  60. private:
  61. void GetAppletResourceUserId(Kernel::HLERequestContext& ctx);
  62. void AcquireForegroundRights(Kernel::HLERequestContext& ctx);
  63. };
  64. class IAudioController final : public ServiceFramework<IAudioController> {
  65. public:
  66. IAudioController();
  67. ~IAudioController() override;
  68. private:
  69. void SetExpectedMasterVolume(Kernel::HLERequestContext& ctx);
  70. void GetMainAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx);
  71. void GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestContext& ctx);
  72. void ChangeMainAppletMasterVolume(Kernel::HLERequestContext& ctx);
  73. void SetTransparentAudioRate(Kernel::HLERequestContext& ctx);
  74. static constexpr float min_allowed_volume = 0.0f;
  75. static constexpr float max_allowed_volume = 1.0f;
  76. float main_applet_volume{0.25f};
  77. float library_applet_volume{max_allowed_volume};
  78. float transparent_volume_rate{min_allowed_volume};
  79. // Volume transition fade time in nanoseconds.
  80. // e.g. If the main applet volume was 0% and was changed to 50%
  81. // with a fade of 50ns, then over the course of 50ns,
  82. // the volume will gradually fade up to 50%
  83. std::chrono::nanoseconds fade_time_ns{0};
  84. };
  85. class IDisplayController final : public ServiceFramework<IDisplayController> {
  86. public:
  87. IDisplayController();
  88. ~IDisplayController() override;
  89. };
  90. class IDebugFunctions final : public ServiceFramework<IDebugFunctions> {
  91. public:
  92. IDebugFunctions();
  93. ~IDebugFunctions() override;
  94. };
  95. class ISelfController final : public ServiceFramework<ISelfController> {
  96. public:
  97. explicit ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger);
  98. ~ISelfController() override;
  99. private:
  100. void LockExit(Kernel::HLERequestContext& ctx);
  101. void UnlockExit(Kernel::HLERequestContext& ctx);
  102. void EnterFatalSection(Kernel::HLERequestContext& ctx);
  103. void LeaveFatalSection(Kernel::HLERequestContext& ctx);
  104. void GetLibraryAppletLaunchableEvent(Kernel::HLERequestContext& ctx);
  105. void SetScreenShotPermission(Kernel::HLERequestContext& ctx);
  106. void SetOperationModeChangedNotification(Kernel::HLERequestContext& ctx);
  107. void SetPerformanceModeChangedNotification(Kernel::HLERequestContext& ctx);
  108. void SetFocusHandlingMode(Kernel::HLERequestContext& ctx);
  109. void SetRestartMessageEnabled(Kernel::HLERequestContext& ctx);
  110. void SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx);
  111. void SetScreenShotImageOrientation(Kernel::HLERequestContext& ctx);
  112. void CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx);
  113. void SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx);
  114. void SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx);
  115. void GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx);
  116. void SetAutoSleepDisabled(Kernel::HLERequestContext& ctx);
  117. void IsAutoSleepDisabled(Kernel::HLERequestContext& ctx);
  118. void GetAccumulatedSuspendedTickValue(Kernel::HLERequestContext& ctx);
  119. void GetAccumulatedSuspendedTickChangedEvent(Kernel::HLERequestContext& ctx);
  120. std::shared_ptr<NVFlinger::NVFlinger> nvflinger;
  121. Kernel::EventPair launchable_event;
  122. Kernel::EventPair accumulated_suspended_tick_changed_event;
  123. u32 idle_time_detection_extension = 0;
  124. u64 num_fatal_sections_entered = 0;
  125. bool is_auto_sleep_disabled = false;
  126. };
  127. class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> {
  128. public:
  129. explicit ICommonStateGetter(Core::System& system,
  130. std::shared_ptr<AppletMessageQueue> msg_queue);
  131. ~ICommonStateGetter() override;
  132. private:
  133. enum class FocusState : u8 {
  134. InFocus = 1,
  135. NotInFocus = 2,
  136. };
  137. enum class OperationMode : u8 {
  138. Handheld = 0,
  139. Docked = 1,
  140. };
  141. void GetEventHandle(Kernel::HLERequestContext& ctx);
  142. void ReceiveMessage(Kernel::HLERequestContext& ctx);
  143. void GetCurrentFocusState(Kernel::HLERequestContext& ctx);
  144. void GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx);
  145. void GetOperationMode(Kernel::HLERequestContext& ctx);
  146. void GetPerformanceMode(Kernel::HLERequestContext& ctx);
  147. void GetBootMode(Kernel::HLERequestContext& ctx);
  148. void GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx);
  149. void SetCpuBoostMode(Kernel::HLERequestContext& ctx);
  150. Core::System& system;
  151. std::shared_ptr<AppletMessageQueue> msg_queue;
  152. };
  153. class IStorage final : public ServiceFramework<IStorage> {
  154. public:
  155. explicit IStorage(std::vector<u8> buffer);
  156. ~IStorage() override;
  157. const std::vector<u8>& GetData() const;
  158. private:
  159. void Open(Kernel::HLERequestContext& ctx);
  160. std::vector<u8> buffer;
  161. friend class IStorageAccessor;
  162. };
  163. class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
  164. public:
  165. explicit IStorageAccessor(IStorage& backing);
  166. ~IStorageAccessor() override;
  167. private:
  168. void GetSize(Kernel::HLERequestContext& ctx);
  169. void Write(Kernel::HLERequestContext& ctx);
  170. void Read(Kernel::HLERequestContext& ctx);
  171. IStorage& backing;
  172. };
  173. class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
  174. public:
  175. ILibraryAppletCreator(u64 current_process_title_id);
  176. ~ILibraryAppletCreator() override;
  177. private:
  178. void CreateLibraryApplet(Kernel::HLERequestContext& ctx);
  179. void CreateStorage(Kernel::HLERequestContext& ctx);
  180. void CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx);
  181. u64 current_process_title_id;
  182. };
  183. class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> {
  184. public:
  185. IApplicationFunctions();
  186. ~IApplicationFunctions() override;
  187. private:
  188. void PopLaunchParameter(Kernel::HLERequestContext& ctx);
  189. void CreateApplicationAndRequestToStartForQuest(Kernel::HLERequestContext& ctx);
  190. void EnsureSaveData(Kernel::HLERequestContext& ctx);
  191. void SetTerminateResult(Kernel::HLERequestContext& ctx);
  192. void GetDisplayVersion(Kernel::HLERequestContext& ctx);
  193. void GetDesiredLanguage(Kernel::HLERequestContext& ctx);
  194. void InitializeGamePlayRecording(Kernel::HLERequestContext& ctx);
  195. void SetGamePlayRecordingState(Kernel::HLERequestContext& ctx);
  196. void NotifyRunning(Kernel::HLERequestContext& ctx);
  197. void GetPseudoDeviceId(Kernel::HLERequestContext& ctx);
  198. void ExtendSaveData(Kernel::HLERequestContext& ctx);
  199. void GetSaveDataSize(Kernel::HLERequestContext& ctx);
  200. void BeginBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx);
  201. void EndBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx);
  202. void BeginBlockingHomeButton(Kernel::HLERequestContext& ctx);
  203. void EndBlockingHomeButton(Kernel::HLERequestContext& ctx);
  204. void EnableApplicationCrashReport(Kernel::HLERequestContext& ctx);
  205. };
  206. class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
  207. public:
  208. IHomeMenuFunctions();
  209. ~IHomeMenuFunctions() override;
  210. private:
  211. void RequestToGetForeground(Kernel::HLERequestContext& ctx);
  212. };
  213. class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
  214. public:
  215. IGlobalStateController();
  216. ~IGlobalStateController() override;
  217. };
  218. class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
  219. public:
  220. IApplicationCreator();
  221. ~IApplicationCreator() override;
  222. };
  223. class IProcessWindingController final : public ServiceFramework<IProcessWindingController> {
  224. public:
  225. IProcessWindingController();
  226. ~IProcessWindingController() override;
  227. };
  228. /// Registers all AM services with the specified service manager.
  229. void InstallInterfaces(SM::ServiceManager& service_manager,
  230. std::shared_ptr<NVFlinger::NVFlinger> nvflinger, Core::System& system);
  231. } // namespace AM
  232. } // namespace Service