diff options
Diffstat (limited to '')
| -rw-r--r-- | src/common/emu_window.h | 128 |
1 files changed, 94 insertions, 34 deletions
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index 6c2b598f6..4cb94fed1 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -9,17 +9,33 @@ | |||
| 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 | * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please | ||
| 28 | * re-read the upper points again and think about it if you don't see this. | ||
| 29 | */ | ||
| 14 | class EmuWindow | 30 | class EmuWindow |
| 15 | { | 31 | { |
| 16 | |||
| 17 | public: | 32 | public: |
| 18 | /// Data structure to store an emuwindow configuration | 33 | /// Data structure to store emuwindow configuration |
| 19 | struct WindowConfig { | 34 | struct WindowConfig { |
| 20 | bool fullscreen; | 35 | bool fullscreen; |
| 21 | int res_width; | 36 | int res_width; |
| 22 | int res_height; | 37 | int res_height; |
| 38 | std::pair<unsigned,unsigned> min_client_area_size; | ||
| 23 | }; | 39 | }; |
| 24 | 40 | ||
| 25 | /// Swap buffers to display the next frame | 41 | /// Swap buffers to display the next frame |
| @@ -42,52 +58,96 @@ public: | |||
| 42 | /// Signals a key release action to the HID module | 58 | /// Signals a key release action to the HID module |
| 43 | static void KeyReleased(KeyMap::HostDeviceKey key); | 59 | static void KeyReleased(KeyMap::HostDeviceKey key); |
| 44 | 60 | ||
| 45 | WindowConfig GetConfig() const { | 61 | /** |
| 46 | return m_config; | 62 | * Returns currently active configuration. |
| 63 | * @note Accesses to the returned object need not be consistent because it may be modified in another thread | ||
| 64 | */ | ||
| 65 | const WindowConfig& GetActiveConfig() const { | ||
| 66 | return active_config; | ||
| 47 | } | 67 | } |
| 48 | 68 | ||
| 69 | /** | ||
| 70 | * Requests the internal configuration to be replaced by the specified argument at some point in the future. | ||
| 71 | * @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. | ||
| 72 | */ | ||
| 49 | void SetConfig(const WindowConfig& val) { | 73 | void SetConfig(const WindowConfig& val) { |
| 50 | m_config = val; | 74 | config = val; |
| 51 | } | ||
| 52 | |||
| 53 | int GetClientAreaWidth() const { | ||
| 54 | return m_client_area_width; | ||
| 55 | } | 75 | } |
| 56 | 76 | ||
| 57 | void SetClientAreaWidth(const int val) { | 77 | /** |
| 58 | m_client_area_width = val; | 78 | * Gets the framebuffer size in pixels. |
| 79 | * @note This method is thread-safe | ||
| 80 | */ | ||
| 81 | const std::pair<unsigned,unsigned> GetFramebufferSize() const { | ||
| 82 | return framebuffer_size; | ||
| 59 | } | 83 | } |
| 60 | 84 | ||
| 61 | int GetClientAreaHeight() const { | 85 | /** |
| 62 | return m_client_area_height; | 86 | * Gets window client area width in logical coordinates. |
| 87 | * @note For high-DPI systems, this is smaller than the framebuffer size. | ||
| 88 | * @note This method is thread-safe | ||
| 89 | */ | ||
| 90 | std::pair<unsigned,unsigned> GetClientAreaSize() const { | ||
| 91 | return std::make_pair(client_area_width, client_area_height); | ||
| 63 | } | 92 | } |
| 64 | 93 | ||
| 65 | void SetClientAreaHeight(const int val) { | 94 | protected: |
| 66 | m_client_area_height = val; | 95 | EmuWindow() |
| 96 | { | ||
| 97 | // TODO: Find a better place to set this. | ||
| 98 | config.min_client_area_size = std::make_pair(400u, 480u); | ||
| 99 | active_config = config; | ||
| 67 | } | 100 | } |
| 101 | virtual ~EmuWindow() {} | ||
| 68 | 102 | ||
| 69 | std::string GetWindowTitle() const { | 103 | /** |
| 70 | return m_window_title; | 104 | * Processes any pending configuration changes from the last SetConfig call. |
| 105 | * This method invokes OnMinimalClientAreaChangeRequest if the corresponding configuration | ||
| 106 | * field changed. | ||
| 107 | * @note Implementations will usually want to call this from the GUI thread. | ||
| 108 | * @todo Actually call this in existing implementations. | ||
| 109 | */ | ||
| 110 | void ProcessConfigurationChanges() { | ||
| 111 | // TODO: For proper thread safety, we should eventually implement a proper | ||
| 112 | // multiple-writer/single-reader queue... | ||
| 113 | |||
| 114 | if (config.min_client_area_size != active_config.min_client_area_size) { | ||
| 115 | OnMinimalClientAreaChangeRequest(config.min_client_area_size); | ||
| 116 | config.min_client_area_size = active_config.min_client_area_size; | ||
| 117 | } | ||
| 71 | } | 118 | } |
| 72 | 119 | ||
| 73 | void SetWindowTitle(std::string val) { | 120 | /** |
| 74 | m_window_title = val; | 121 | * Update internal framebuffer size with the given parameter. |
| 122 | * @note EmuWindow implementations will usually use this in window resize event handlers. | ||
| 123 | */ | ||
| 124 | void NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) { | ||
| 125 | framebuffer_size = size; | ||
| 75 | } | 126 | } |
| 76 | 127 | ||
| 77 | protected: | 128 | /** |
| 78 | EmuWindow(): | 129 | * Update internal client area size with the given parameter. |
| 79 | m_window_title(Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc)), | 130 | * @note EmuWindow implementations will usually use this in window resize event handlers. |
| 80 | m_client_area_width(640), | 131 | */ |
| 81 | m_client_area_height(480) | 132 | void NotifyClientAreaSizeChanged(const std::pair<unsigned,unsigned>& size) { |
| 82 | {} | 133 | client_area_width = size.first; |
| 83 | virtual ~EmuWindow() {} | 134 | client_area_height = size.second; |
| 135 | } | ||
| 84 | 136 | ||
| 85 | std::string m_window_title; ///< Current window title, should be used by window impl. | 137 | private: |
| 138 | /** | ||
| 139 | * Handler called when the minimal client area was requested to be changed via SetConfig. | ||
| 140 | * For the request to be honored, EmuWindow implementations will usually reimplement this function. | ||
| 141 | */ | ||
| 142 | virtual void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) { | ||
| 143 | // By default, ignore this request and do nothing. | ||
| 144 | } | ||
| 86 | 145 | ||
| 87 | int m_client_area_width; ///< Current client width, should be set by window impl. | 146 | std::pair<unsigned,unsigned> framebuffer_size; |
| 88 | int m_client_area_height; ///< Current client height, should be set by window impl. | ||
| 89 | 147 | ||
| 90 | private: | 148 | unsigned client_area_width; ///< Current client width, should be set by window impl. |
| 91 | WindowConfig m_config; ///< Internal configuration | 149 | unsigned client_area_height; ///< Current client height, should be set by window impl. |
| 92 | 150 | ||
| 151 | WindowConfig config; ///< Internal configuration (changes pending for being applied in ProcessConfigurationChanges) | ||
| 152 | WindowConfig active_config; ///< Internal active configuration | ||
| 93 | }; | 153 | }; |