am.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. std::shared_ptr<NVFlinger::NVFlinger> nvflinger;
  117. Kernel::EventPair launchable_event;
  118. u32 idle_time_detection_extension = 0;
  119. u64 num_fatal_sections_entered = 0;
  120. };
  121. class ICommonStateGetter final : public ServiceFramework<ICommonStateGetter> {
  122. public:
  123. explicit ICommonStateGetter(std::shared_ptr<AppletMessageQueue> msg_queue);
  124. ~ICommonStateGetter() override;
  125. private:
  126. enum class FocusState : u8 {
  127. InFocus = 1,
  128. NotInFocus = 2,
  129. };
  130. enum class OperationMode : u8 {
  131. Handheld = 0,
  132. Docked = 1,
  133. };
  134. void GetEventHandle(Kernel::HLERequestContext& ctx);
  135. void ReceiveMessage(Kernel::HLERequestContext& ctx);
  136. void GetCurrentFocusState(Kernel::HLERequestContext& ctx);
  137. void GetDefaultDisplayResolutionChangeEvent(Kernel::HLERequestContext& ctx);
  138. void GetOperationMode(Kernel::HLERequestContext& ctx);
  139. void GetPerformanceMode(Kernel::HLERequestContext& ctx);
  140. void GetBootMode(Kernel::HLERequestContext& ctx);
  141. void GetDefaultDisplayResolution(Kernel::HLERequestContext& ctx);
  142. std::shared_ptr<AppletMessageQueue> msg_queue;
  143. };
  144. class IStorage final : public ServiceFramework<IStorage> {
  145. public:
  146. explicit IStorage(std::vector<u8> buffer);
  147. ~IStorage() override;
  148. const std::vector<u8>& GetData() const;
  149. private:
  150. void Open(Kernel::HLERequestContext& ctx);
  151. std::vector<u8> buffer;
  152. friend class IStorageAccessor;
  153. };
  154. class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
  155. public:
  156. explicit IStorageAccessor(IStorage& backing);
  157. ~IStorageAccessor() override;
  158. private:
  159. void GetSize(Kernel::HLERequestContext& ctx);
  160. void Write(Kernel::HLERequestContext& ctx);
  161. void Read(Kernel::HLERequestContext& ctx);
  162. IStorage& backing;
  163. };
  164. class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
  165. public:
  166. ILibraryAppletCreator();
  167. ~ILibraryAppletCreator() override;
  168. private:
  169. void CreateLibraryApplet(Kernel::HLERequestContext& ctx);
  170. void CreateStorage(Kernel::HLERequestContext& ctx);
  171. void CreateTransferMemoryStorage(Kernel::HLERequestContext& ctx);
  172. };
  173. class IApplicationFunctions final : public ServiceFramework<IApplicationFunctions> {
  174. public:
  175. IApplicationFunctions();
  176. ~IApplicationFunctions() override;
  177. private:
  178. void PopLaunchParameter(Kernel::HLERequestContext& ctx);
  179. void CreateApplicationAndRequestToStartForQuest(Kernel::HLERequestContext& ctx);
  180. void EnsureSaveData(Kernel::HLERequestContext& ctx);
  181. void SetTerminateResult(Kernel::HLERequestContext& ctx);
  182. void GetDisplayVersion(Kernel::HLERequestContext& ctx);
  183. void GetDesiredLanguage(Kernel::HLERequestContext& ctx);
  184. void InitializeGamePlayRecording(Kernel::HLERequestContext& ctx);
  185. void SetGamePlayRecordingState(Kernel::HLERequestContext& ctx);
  186. void NotifyRunning(Kernel::HLERequestContext& ctx);
  187. void GetPseudoDeviceId(Kernel::HLERequestContext& ctx);
  188. void ExtendSaveData(Kernel::HLERequestContext& ctx);
  189. void GetSaveDataSize(Kernel::HLERequestContext& ctx);
  190. void BeginBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx);
  191. void EndBlockingHomeButtonShortAndLongPressed(Kernel::HLERequestContext& ctx);
  192. void BeginBlockingHomeButton(Kernel::HLERequestContext& ctx);
  193. void EndBlockingHomeButton(Kernel::HLERequestContext& ctx);
  194. void EnableApplicationCrashReport(Kernel::HLERequestContext& ctx);
  195. };
  196. class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
  197. public:
  198. IHomeMenuFunctions();
  199. ~IHomeMenuFunctions() override;
  200. private:
  201. void RequestToGetForeground(Kernel::HLERequestContext& ctx);
  202. };
  203. class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
  204. public:
  205. IGlobalStateController();
  206. ~IGlobalStateController() override;
  207. };
  208. class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
  209. public:
  210. IApplicationCreator();
  211. ~IApplicationCreator() override;
  212. };
  213. class IProcessWindingController final : public ServiceFramework<IProcessWindingController> {
  214. public:
  215. IProcessWindingController();
  216. ~IProcessWindingController() override;
  217. };
  218. /// Registers all AM services with the specified service manager.
  219. void InstallInterfaces(SM::ServiceManager& service_manager,
  220. std::shared_ptr<NVFlinger::NVFlinger> nvflinger);
  221. } // namespace AM
  222. } // namespace Service