diff options
| author | 2016-12-23 13:37:40 +0000 | |
|---|---|---|
| committer | 2016-12-23 13:42:39 +0000 | |
| commit | 64f98f4d0f33b5c626d86a05ab9dd8060e160cc5 (patch) | |
| tree | 8874f16f9f840add798f58981d5c2fcdf4da3c84 /src/common/emu_window.h | |
| parent | Merge pull request #2364 from mailwl/nwm-services (diff) | |
| download | yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.tar.gz yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.tar.xz yuzu-64f98f4d0f33b5c626d86a05ab9dd8060e160cc5.zip | |
core: Move emu_window and key_map into core
* Removes circular dependences (common should not depend on core)
Diffstat (limited to 'src/common/emu_window.h')
| -rw-r--r-- | src/common/emu_window.h | 290 |
1 files changed, 0 insertions, 290 deletions
diff --git a/src/common/emu_window.h b/src/common/emu_window.h deleted file mode 100644 index 835c4d500..000000000 --- a/src/common/emu_window.h +++ /dev/null | |||
| @@ -1,290 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <tuple> | ||
| 8 | #include <utility> | ||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "common/framebuffer_layout.h" | ||
| 11 | #include "common/math_util.h" | ||
| 12 | #include "core/hle/service/hid/hid.h" | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Abstraction class used to provide an interface between emulation code and the frontend | ||
| 16 | * (e.g. SDL, QGLWidget, GLFW, etc...). | ||
| 17 | * | ||
| 18 | * Design notes on the interaction between EmuWindow and the emulation core: | ||
| 19 | * - Generally, decisions on anything visible to the user should be left up to the GUI. | ||
| 20 | * For example, the emulation core should not try to dictate some window title or size. | ||
| 21 | * This stuff is not the core's business and only causes problems with regards to thread-safety | ||
| 22 | * anyway. | ||
| 23 | * - Under certain circumstances, it may be desirable for the core to politely request the GUI | ||
| 24 | * to set e.g. a minimum window size. However, the GUI should always be free to ignore any | ||
| 25 | * such hints. | ||
| 26 | * - EmuWindow may expose some of its state as read-only to the emulation core, however care | ||
| 27 | * should be taken to make sure the provided information is self-consistent. This requires | ||
| 28 | * some sort of synchronization (most of this is still a TODO). | ||
| 29 | * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please | ||
| 30 | * re-read the upper points again and think about it if you don't see this. | ||
| 31 | */ | ||
| 32 | class EmuWindow { | ||
| 33 | public: | ||
| 34 | /// Data structure to store emuwindow configuration | ||
| 35 | struct WindowConfig { | ||
| 36 | bool fullscreen; | ||
| 37 | int res_width; | ||
| 38 | int res_height; | ||
| 39 | std::pair<unsigned, unsigned> min_client_area_size; | ||
| 40 | }; | ||
| 41 | |||
| 42 | /// Swap buffers to display the next frame | ||
| 43 | virtual void SwapBuffers() = 0; | ||
| 44 | |||
| 45 | /// Polls window events | ||
| 46 | virtual void PollEvents() = 0; | ||
| 47 | |||
| 48 | /// Makes the graphics context current for the caller thread | ||
| 49 | virtual void MakeCurrent() = 0; | ||
| 50 | |||
| 51 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread | ||
| 52 | virtual void DoneCurrent() = 0; | ||
| 53 | |||
| 54 | virtual void ReloadSetKeymaps() = 0; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Signals a button press action to the HID module. | ||
| 58 | * @param pad_state indicates which button to press | ||
| 59 | * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad. | ||
| 60 | */ | ||
| 61 | void ButtonPressed(Service::HID::PadState pad_state); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Signals a button release action to the HID module. | ||
| 65 | * @param pad_state indicates which button to press | ||
| 66 | * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad. | ||
| 67 | */ | ||
| 68 | void ButtonReleased(Service::HID::PadState pad_state); | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Signals a circle pad change action to the HID module. | ||
| 72 | * @param x new x-coordinate of the circle pad, in the range [-1.0, 1.0] | ||
| 73 | * @param y new y-coordinate of the circle pad, in the range [-1.0, 1.0] | ||
| 74 | * @note the coordinates will be normalized if the radius is larger than 1 | ||
| 75 | */ | ||
| 76 | void CirclePadUpdated(float x, float y); | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Signal that a touch pressed event has occurred (e.g. mouse click pressed) | ||
| 80 | * @param framebuffer_x Framebuffer x-coordinate that was pressed | ||
| 81 | * @param framebuffer_y Framebuffer y-coordinate that was pressed | ||
| 82 | */ | ||
| 83 | void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y); | ||
| 84 | |||
| 85 | /// Signal that a touch released event has occurred (e.g. mouse click released) | ||
| 86 | void TouchReleased(); | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window) | ||
| 90 | * @param framebuffer_x Framebuffer x-coordinate | ||
| 91 | * @param framebuffer_y Framebuffer y-coordinate | ||
| 92 | */ | ||
| 93 | void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y); | ||
| 94 | |||
| 95 | /** | ||
| 96 | * Gets the current pad state (which buttons are pressed). | ||
| 97 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 98 | * @note This doesn't include analog input like circle pad direction | ||
| 99 | * @todo Fix this function to be thread-safe. | ||
| 100 | * @return PadState object indicating the current pad state | ||
| 101 | */ | ||
| 102 | Service::HID::PadState GetPadState() const { | ||
| 103 | return pad_state; | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Gets the current circle pad state. | ||
| 108 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 109 | * @todo Fix this function to be thread-safe. | ||
| 110 | * @return std::tuple of (x, y), where `x` and `y` are the circle pad coordinates | ||
| 111 | */ | ||
| 112 | std::tuple<s16, s16> GetCirclePadState() const { | ||
| 113 | return std::make_tuple(circle_pad_x, circle_pad_y); | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed). | ||
| 118 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 119 | * @todo Fix this function to be thread-safe. | ||
| 120 | * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and | ||
| 121 | * `pressed` is true if the touch screen is currently being pressed | ||
| 122 | */ | ||
| 123 | std::tuple<u16, u16, bool> GetTouchState() const { | ||
| 124 | return std::make_tuple(touch_x, touch_y, touch_pressed); | ||
| 125 | } | ||
| 126 | |||
| 127 | /** | ||
| 128 | * Gets the current accelerometer state (acceleration along each three axis). | ||
| 129 | * Axis explained: | ||
| 130 | * +x is the same direction as LEFT on D-pad. | ||
| 131 | * +y is normal to the touch screen, pointing outward. | ||
| 132 | * +z is the same direction as UP on D-pad. | ||
| 133 | * Units: | ||
| 134 | * 1 unit of return value = 1/512 g (measured by hw test), | ||
| 135 | * where g is the gravitational acceleration (9.8 m/sec2). | ||
| 136 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 137 | * @todo Implement accelerometer input in front-end. | ||
| 138 | * @return std::tuple of (x, y, z) | ||
| 139 | */ | ||
| 140 | std::tuple<s16, s16, s16> GetAccelerometerState() const { | ||
| 141 | // stubbed | ||
| 142 | return std::make_tuple(0, -512, 0); | ||
| 143 | } | ||
| 144 | |||
| 145 | /** | ||
| 146 | * Gets the current gyroscope state (angular rates about each three axis). | ||
| 147 | * Axis explained: | ||
| 148 | * +x is the same direction as LEFT on D-pad. | ||
| 149 | * +y is normal to the touch screen, pointing outward. | ||
| 150 | * +z is the same direction as UP on D-pad. | ||
| 151 | * Orientation is determined by right-hand rule. | ||
| 152 | * Units: | ||
| 153 | * 1 unit of return value = (1/coef) deg/sec, | ||
| 154 | * where coef is the return value of GetGyroscopeRawToDpsCoefficient(). | ||
| 155 | * @note This should be called by the core emu thread to get a state set by the window thread. | ||
| 156 | * @todo Implement gyroscope input in front-end. | ||
| 157 | * @return std::tuple of (x, y, z) | ||
| 158 | */ | ||
| 159 | std::tuple<s16, s16, s16> GetGyroscopeState() const { | ||
| 160 | // stubbed | ||
| 161 | return std::make_tuple(0, 0, 0); | ||
| 162 | } | ||
| 163 | |||
| 164 | /** | ||
| 165 | * Gets the coefficient for units conversion of gyroscope state. | ||
| 166 | * The conversion formula is r = coefficient * v, | ||
| 167 | * where v is angular rate in deg/sec, | ||
| 168 | * and r is the gyroscope state. | ||
| 169 | * @return float-type coefficient | ||
| 170 | */ | ||
| 171 | f32 GetGyroscopeRawToDpsCoefficient() const { | ||
| 172 | return 14.375f; // taken from hw test, and gyroscope's document | ||
| 173 | } | ||
| 174 | |||
| 175 | /** | ||
| 176 | * Returns currently active configuration. | ||
| 177 | * @note Accesses to the returned object need not be consistent because it may be modified in | ||
| 178 | * another thread | ||
| 179 | */ | ||
| 180 | const WindowConfig& GetActiveConfig() const { | ||
| 181 | return active_config; | ||
| 182 | } | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Requests the internal configuration to be replaced by the specified argument at some point in | ||
| 186 | * the future. | ||
| 187 | * @note This method is thread-safe, because it delays configuration changes to the GUI event | ||
| 188 | * loop. Hence there is no guarantee on when the requested configuration will be active. | ||
| 189 | */ | ||
| 190 | void SetConfig(const WindowConfig& val) { | ||
| 191 | config = val; | ||
| 192 | } | ||
| 193 | |||
| 194 | /** | ||
| 195 | * Gets the framebuffer layout (width, height, and screen regions) | ||
| 196 | * @note This method is thread-safe | ||
| 197 | */ | ||
| 198 | const Layout::FramebufferLayout& GetFramebufferLayout() const { | ||
| 199 | return framebuffer_layout; | ||
| 200 | } | ||
| 201 | |||
| 202 | /** | ||
| 203 | * Convenience method to update the current frame layout | ||
| 204 | * Read from the current settings to determine which layout to use. | ||
| 205 | */ | ||
| 206 | void UpdateCurrentFramebufferLayout(unsigned width, unsigned height); | ||
| 207 | |||
| 208 | protected: | ||
| 209 | EmuWindow() { | ||
| 210 | // TODO: Find a better place to set this. | ||
| 211 | config.min_client_area_size = std::make_pair(400u, 480u); | ||
| 212 | active_config = config; | ||
| 213 | pad_state.hex = 0; | ||
| 214 | touch_x = 0; | ||
| 215 | touch_y = 0; | ||
| 216 | circle_pad_x = 0; | ||
| 217 | circle_pad_y = 0; | ||
| 218 | touch_pressed = false; | ||
| 219 | } | ||
| 220 | virtual ~EmuWindow() {} | ||
| 221 | |||
| 222 | /** | ||
| 223 | * Processes any pending configuration changes from the last SetConfig call. | ||
| 224 | * This method invokes OnMinimalClientAreaChangeRequest if the corresponding configuration | ||
| 225 | * field changed. | ||
| 226 | * @note Implementations will usually want to call this from the GUI thread. | ||
| 227 | * @todo Actually call this in existing implementations. | ||
| 228 | */ | ||
| 229 | void ProcessConfigurationChanges() { | ||
| 230 | // TODO: For proper thread safety, we should eventually implement a proper | ||
| 231 | // multiple-writer/single-reader queue... | ||
| 232 | |||
| 233 | if (config.min_client_area_size != active_config.min_client_area_size) { | ||
| 234 | OnMinimalClientAreaChangeRequest(config.min_client_area_size); | ||
| 235 | config.min_client_area_size = active_config.min_client_area_size; | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | /** | ||
| 240 | * Update framebuffer layout with the given parameter. | ||
| 241 | * @note EmuWindow implementations will usually use this in window resize event handlers. | ||
| 242 | */ | ||
| 243 | void NotifyFramebufferLayoutChanged(const Layout::FramebufferLayout& layout) { | ||
| 244 | framebuffer_layout = layout; | ||
| 245 | } | ||
| 246 | |||
| 247 | /** | ||
| 248 | * Update internal client area size with the given parameter. | ||
| 249 | * @note EmuWindow implementations will usually use this in window resize event handlers. | ||
| 250 | */ | ||
| 251 | void NotifyClientAreaSizeChanged(const std::pair<unsigned, unsigned>& size) { | ||
| 252 | client_area_width = size.first; | ||
| 253 | client_area_height = size.second; | ||
| 254 | } | ||
| 255 | |||
| 256 | private: | ||
| 257 | /** | ||
| 258 | * Handler called when the minimal client area was requested to be changed via SetConfig. | ||
| 259 | * For the request to be honored, EmuWindow implementations will usually reimplement this | ||
| 260 | * function. | ||
| 261 | */ | ||
| 262 | virtual void OnMinimalClientAreaChangeRequest( | ||
| 263 | const std::pair<unsigned, unsigned>& minimal_size) { | ||
| 264 | // By default, ignore this request and do nothing. | ||
| 265 | } | ||
| 266 | |||
| 267 | Layout::FramebufferLayout framebuffer_layout; ///< Current framebuffer layout | ||
| 268 | |||
| 269 | unsigned client_area_width; ///< Current client width, should be set by window impl. | ||
| 270 | unsigned client_area_height; ///< Current client height, should be set by window impl. | ||
| 271 | |||
| 272 | WindowConfig config; ///< Internal configuration (changes pending for being applied in | ||
| 273 | /// ProcessConfigurationChanges) | ||
| 274 | WindowConfig active_config; ///< Internal active configuration | ||
| 275 | |||
| 276 | bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false | ||
| 277 | |||
| 278 | u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320) | ||
| 279 | u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240) | ||
| 280 | |||
| 281 | s16 circle_pad_x; ///< Circle pad X-position in native 3DS pixel coordinates (-156 - 156) | ||
| 282 | s16 circle_pad_y; ///< Circle pad Y-position in native 3DS pixel coordinates (-156 - 156) | ||
| 283 | |||
| 284 | /** | ||
| 285 | * Clip the provided coordinates to be inside the touchscreen area. | ||
| 286 | */ | ||
| 287 | std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y); | ||
| 288 | |||
| 289 | Service::HID::PadState pad_state; | ||
| 290 | }; | ||