diff options
| -rw-r--r-- | src/common/emu_window.h | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index baacc6da2..1465743f2 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -9,13 +9,26 @@ | |||
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | #include "common/key_map.h" | 10 | #include "common/key_map.h" |
| 11 | 11 | ||
| 12 | // Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, | 12 | /** |
| 13 | // QGLWidget, GLFW, etc...) | 13 | * Abstraction class used to provide an interface between emulation code and the frontend |
| 14 | * (e.g. SDL, QGLWidget, GLFW, etc...). | ||
| 15 | * | ||
| 16 | * Design notes on the interaction between EmuWindow and the emulation core: | ||
| 17 | * - Generally, decisions on anything visible to the user should be left up to the GUI. | ||
| 18 | * For example, the emulation core should not try to dictate some window title or size. | ||
| 19 | * This stuff is not the core's business and only causes problems with regards to thread-safety | ||
| 20 | * anyway. | ||
| 21 | * - Under certain circumstances, it may be desirable for the core to politely request the GUI | ||
| 22 | * to set e.g. a minimum window size. However, the GUI should always be free to ignore any | ||
| 23 | * such hints. | ||
| 24 | * - EmuWindow may expose some of its state as read-only to the emulation core, however care | ||
| 25 | * should be taken to make sure the provided information is self-consistent. This requires | ||
| 26 | * some sort of synchronization (most of this is still a TODO). | ||
| 27 | */ | ||
| 14 | class EmuWindow | 28 | class EmuWindow |
| 15 | { | 29 | { |
| 16 | |||
| 17 | public: | 30 | public: |
| 18 | /// Data structure to store an emuwindow configuration | 31 | /// Data structure to store emuwindow configuration |
| 19 | struct WindowConfig { | 32 | struct WindowConfig { |
| 20 | bool fullscreen; | 33 | bool fullscreen; |
| 21 | int res_width; | 34 | int res_width; |
| @@ -43,48 +56,51 @@ public: | |||
| 43 | /// Signals a key release action to the HID module | 56 | /// Signals a key release action to the HID module |
| 44 | static void KeyReleased(KeyMap::HostDeviceKey key); | 57 | static void KeyReleased(KeyMap::HostDeviceKey key); |
| 45 | 58 | ||
| 59 | /** | ||
| 60 | * Returns currently active configuration. | ||
| 61 | * @note Accesses to the returned object need not be consistent because it may be modified in another thread | ||
| 62 | */ | ||
| 46 | const WindowConfig& GetActiveConfig() const { | 63 | const WindowConfig& GetActiveConfig() const { |
| 47 | return active_config; | 64 | return active_config; |
| 48 | } | 65 | } |
| 49 | 66 | ||
| 67 | /** | ||
| 68 | * Requests the internal configuration to be replaced by the specified argument at some point in the future. | ||
| 69 | * @note This method is thread-safe, because it delays configuration changes to the GUI event loop. Hence there is no guarantee on when the requested configuration will be active. | ||
| 70 | */ | ||
| 50 | void SetConfig(const WindowConfig& val) { | 71 | void SetConfig(const WindowConfig& val) { |
| 51 | config = val; | 72 | config = val; |
| 52 | } | 73 | } |
| 53 | 74 | ||
| 54 | /** | 75 | /** |
| 55 | * Gets the size of the framebuffer in pixels | 76 | * Gets the framebuffer size in pixels. |
| 77 | * @note This method is thread-safe | ||
| 56 | */ | 78 | */ |
| 57 | const std::pair<unsigned,unsigned> GetFramebufferSize() const { | 79 | const std::pair<unsigned,unsigned> GetFramebufferSize() const { |
| 58 | return framebuffer_size; | 80 | return framebuffer_size; |
| 59 | } | 81 | } |
| 60 | 82 | ||
| 61 | /** | 83 | /** |
| 62 | * Gets window client area width in logical coordinates | 84 | * Gets window client area width in logical coordinates. |
| 85 | * @note For high-DPI systems, this is smaller than the framebuffer size. | ||
| 86 | * @note This method is thread-safe | ||
| 63 | */ | 87 | */ |
| 64 | std::pair<unsigned,unsigned> GetClientAreaSize() const { | 88 | std::pair<unsigned,unsigned> GetClientAreaSize() const { |
| 65 | return std::make_pair(client_area_width, client_area_height); | 89 | return std::make_pair(client_area_width, client_area_height); |
| 66 | } | 90 | } |
| 67 | 91 | ||
| 92 | // TODO: Remove | ||
| 68 | std::string GetWindowTitle() const { | 93 | std::string GetWindowTitle() const { |
| 69 | return window_title; | 94 | return window_title; |
| 70 | } | 95 | } |
| 71 | 96 | ||
| 97 | // TODO: Remove | ||
| 72 | void SetWindowTitle(const std::string& val) { | 98 | void SetWindowTitle(const std::string& val) { |
| 73 | window_title = val; | 99 | window_title = val; |
| 74 | } | 100 | } |
| 75 | 101 | ||
| 76 | // Only call this from the GUI thread! | ||
| 77 | void ProcessConfigurationChanges() { | ||
| 78 | // TODO: For proper thread safety, we should eventually implement a proper | ||
| 79 | // multiple-writer/single-reader queue... | ||
| 80 | |||
| 81 | if (config.min_client_area_size != active_config.min_client_area_size) { | ||
| 82 | OnMinimalClientAreaChangeRequest(config.min_client_area_size); | ||
| 83 | config.min_client_area_size = active_config.min_client_area_size; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | protected: | 102 | protected: |
| 103 | // TODO: Remove window title initialization | ||
| 88 | EmuWindow() : | 104 | EmuWindow() : |
| 89 | window_title(Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc)) | 105 | window_title(Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc)) |
| 90 | { | 106 | { |
| @@ -94,10 +110,32 @@ protected: | |||
| 94 | } | 110 | } |
| 95 | virtual ~EmuWindow() {} | 111 | virtual ~EmuWindow() {} |
| 96 | 112 | ||
| 97 | std::pair<unsigned,unsigned> NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) { | 113 | /** |
| 114 | * Processes any pending configuration changes from the last SetConfig call. | ||
| 115 | * @note Implementations will usually want to call this from the GUI thread. | ||
| 116 | */ | ||
| 117 | void ProcessConfigurationChanges() { | ||
| 118 | // TODO: For proper thread safety, we should eventually implement a proper | ||
| 119 | // multiple-writer/single-reader queue... | ||
| 120 | |||
| 121 | if (config.min_client_area_size != active_config.min_client_area_size) { | ||
| 122 | OnMinimalClientAreaChangeRequest(config.min_client_area_size); | ||
| 123 | config.min_client_area_size = active_config.min_client_area_size; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Update internal framebuffer size with the given parameter. | ||
| 129 | * @note EmuWindow implementations will usually use this in window resize event handlers. | ||
| 130 | */ | ||
| 131 | void NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) { | ||
| 98 | framebuffer_size = size; | 132 | framebuffer_size = size; |
| 99 | } | 133 | } |
| 100 | 134 | ||
| 135 | /** | ||
| 136 | * Update internal client area size with the given parameter. | ||
| 137 | * @note EmuWindow implementations will usually use this in window resize event handlers. | ||
| 138 | */ | ||
| 101 | void NotifyClientAreaSizeChanged(const std::pair<unsigned,unsigned>& size) { | 139 | void NotifyClientAreaSizeChanged(const std::pair<unsigned,unsigned>& size) { |
| 102 | client_area_width = size.first; | 140 | client_area_width = size.first; |
| 103 | client_area_height = size.second; | 141 | client_area_height = size.second; |
| @@ -107,6 +145,7 @@ private: | |||
| 107 | virtual void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) { | 145 | virtual void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) { |
| 108 | } | 146 | } |
| 109 | 147 | ||
| 148 | // TODO: Remove | ||
| 110 | std::string window_title; ///< Current window title, should be used by window impl. | 149 | std::string window_title; ///< Current window title, should be used by window impl. |
| 111 | 150 | ||
| 112 | std::pair<unsigned,unsigned> framebuffer_size; | 151 | std::pair<unsigned,unsigned> framebuffer_size; |