1 // Copyright 2016 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 <memory> 8 #include <utility> 9 #include "core/frontend/emu_window.h" 10 11 struct SDL_Window; 12 13 class SharedContext_SDL2 : public Frontend::GraphicsContext { 14 public: 15 using SDL_GLContext = void*; 16 17 SharedContext_SDL2(); 18 19 ~SharedContext_SDL2() override; 20 21 void MakeCurrent() override; 22 23 void DoneCurrent() override; 24 25 private: 26 SDL_GLContext context; 27 SDL_Window* window; 28 }; 29 30 class EmuWindow_SDL2 : public Frontend::EmuWindow { 31 public: 32 explicit EmuWindow_SDL2(bool fullscreen); 33 ~EmuWindow_SDL2(); 34 35 void Present(); 36 37 /// Polls window events 38 void PollEvents() override; 39 40 /// Makes the graphics context current for the caller thread 41 void MakeCurrent() override; 42 43 /// Releases the GL context from the caller thread 44 void DoneCurrent() override; 45 46 /// Whether the window is still open, and a close request hasn't yet been sent 47 bool IsOpen() const; 48 49 /// Creates a new context that is shared with the current context 50 std::unique_ptr<GraphicsContext> CreateSharedContext() const override; 51 52 private: 53 /// Called by PollEvents when a key is pressed or released. 54 void OnKeyEvent(int key, u8 state); 55 56 /// Called by PollEvents when the mouse moves. 57 void OnMouseMotion(s32 x, s32 y); 58 59 /// Called by PollEvents when a mouse button is pressed or released 60 void OnMouseButton(u32 button, u8 state, s32 x, s32 y); 61 62 /// Translates pixel position (0..1) to pixel positions 63 std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const; 64 65 /// Called by PollEvents when a finger starts touching the touchscreen 66 void OnFingerDown(float x, float y); 67 68 /// Called by PollEvents when a finger moves while touching the touchscreen 69 void OnFingerMotion(float x, float y); 70 71 /// Called by PollEvents when a finger stops touching the touchscreen 72 void OnFingerUp(); 73 74 /// Called by PollEvents when any event that may cause the window to be resized occurs 75 void OnResize(); 76 77 /// Called when user passes the fullscreen parameter flag 78 void Fullscreen(); 79 80 /// Called when a configuration change affects the minimal size of the window 81 void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override; 82 83 /// Is the window still open? 84 bool is_open = true; 85 86 /// Internal SDL2 render window 87 SDL_Window* render_window; 88 89 /// Fake hidden window for the core context 90 SDL_Window* dummy_window; 91 92 using SDL_GLContext = void*; 93 94 /// The OpenGL context associated with the window 95 SDL_GLContext window_context; 96 97 /// The OpenGL context associated with the core 98 std::unique_ptr<Frontend::GraphicsContext> core_context; 99 100 /// Keeps track of how often to update the title bar during gameplay 101 u32 last_time = 0; 102 }; 103