2016-03-01 12:24:18 -05:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-12-11 16:32:41 -05:00
|
|
|
#include <memory>
|
2016-03-01 12:24:18 -05:00
|
|
|
#include <utility>
|
2016-12-23 08:37:40 -05:00
|
|
|
#include "core/frontend/emu_window.h"
|
2016-03-01 12:24:18 -05:00
|
|
|
|
|
|
|
struct SDL_Window;
|
|
|
|
|
2020-02-17 15:35:14 -05:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2020-08-27 15:16:47 -04:00
|
|
|
namespace InputCommon {
|
|
|
|
class InputSubsystem;
|
|
|
|
}
|
|
|
|
|
2021-02-23 21:39:02 -05:00
|
|
|
namespace MouseInput {
|
|
|
|
enum class MouseButton;
|
|
|
|
}
|
|
|
|
|
2018-08-11 20:20:19 -04:00
|
|
|
class EmuWindow_SDL2 : public Core::Frontend::EmuWindow {
|
2016-03-01 12:24:18 -05:00
|
|
|
public:
|
2020-09-19 16:15:02 -04:00
|
|
|
explicit EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem);
|
2016-03-01 12:24:18 -05:00
|
|
|
~EmuWindow_SDL2();
|
|
|
|
|
|
|
|
/// Whether the window is still open, and a close request hasn't yet been sent
|
|
|
|
bool IsOpen() const;
|
|
|
|
|
2020-01-21 14:40:53 -05:00
|
|
|
/// Returns if window is shown (not minimized)
|
|
|
|
bool IsShown() const override;
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Wait for the next event on the main thread.
|
|
|
|
void WaitEvent();
|
|
|
|
|
2021-02-14 03:20:41 -05:00
|
|
|
// Sets the window icon from yuzu.bmp
|
|
|
|
void SetWindowIcon();
|
|
|
|
|
2019-05-25 16:47:13 -04:00
|
|
|
protected:
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when a key is pressed or released.
|
2016-03-01 12:24:18 -05:00
|
|
|
void OnKeyEvent(int key, u8 state);
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when the mouse moves.
|
2016-03-01 12:24:18 -05:00
|
|
|
void OnMouseMotion(s32 x, s32 y);
|
|
|
|
|
2021-02-23 21:39:02 -05:00
|
|
|
/// Converts a SDL mouse button into MouseInput mouse button
|
|
|
|
MouseInput::MouseButton SDLButtonToMouseButton(u32 button) const;
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when a mouse button is pressed or released
|
2016-03-01 12:24:18 -05:00
|
|
|
void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
|
|
|
|
|
2018-10-01 15:42:49 -04:00
|
|
|
/// Translates pixel position (0..1) to pixel positions
|
|
|
|
std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const;
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when a finger starts touching the touchscreen
|
2018-10-01 15:42:49 -04:00
|
|
|
void OnFingerDown(float x, float y);
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when a finger moves while touching the touchscreen
|
2018-10-01 15:42:49 -04:00
|
|
|
void OnFingerMotion(float x, float y);
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when a finger stops touching the touchscreen
|
2018-10-01 15:42:49 -04:00
|
|
|
void OnFingerUp();
|
|
|
|
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 16:05:18 -05:00
|
|
|
/// Called by WaitEvent when any event that may cause the window to be resized occurs
|
2016-03-01 12:24:18 -05:00
|
|
|
void OnResize();
|
|
|
|
|
2018-04-21 03:52:34 -04:00
|
|
|
/// Called when user passes the fullscreen parameter flag
|
|
|
|
void Fullscreen();
|
|
|
|
|
2016-03-01 12:24:18 -05:00
|
|
|
/// Called when a configuration change affects the minimal size of the window
|
2021-04-23 11:17:33 -04:00
|
|
|
void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
|
2016-03-01 12:24:18 -05:00
|
|
|
|
|
|
|
/// Is the window still open?
|
|
|
|
bool is_open = true;
|
|
|
|
|
2019-05-25 16:47:13 -04:00
|
|
|
/// Is the window being shown?
|
|
|
|
bool is_shown = true;
|
|
|
|
|
2016-03-01 12:24:18 -05:00
|
|
|
/// Internal SDL2 render window
|
2020-02-17 15:35:14 -05:00
|
|
|
SDL_Window* render_window{};
|
2019-09-22 09:40:57 -04:00
|
|
|
|
|
|
|
/// Keeps track of how often to update the title bar during gameplay
|
|
|
|
u32 last_time = 0;
|
2020-08-27 15:16:47 -04:00
|
|
|
|
|
|
|
/// Input subsystem to use with this window.
|
|
|
|
InputCommon::InputSubsystem* input_subsystem;
|
2016-03-01 12:24:18 -05:00
|
|
|
};
|