GPUDevice: Remove mouse pointer position

This commit is contained in:
Stenzek 2023-08-27 16:31:08 +10:00
parent 674f9a5b1c
commit 6c185ca17b
9 changed files with 31 additions and 63 deletions

View File

@ -6,7 +6,7 @@
#include "host.h"
#include "system.h"
#include "util/gpu_device.h"
#include "util/input_manager.h"
#include "util/state_wrapper.h"
#include "common/assert.h"
@ -183,8 +183,9 @@ bool GunCon::Transfer(const u8 data_in, u8* data_out)
void GunCon::UpdatePosition()
{
// get screen coordinates
const s32 mouse_x = g_gpu_device->GetMousePositionX();
const s32 mouse_y = g_gpu_device->GetMousePositionY();
const auto& [fmouse_x, fmouse_y] = InputManager::GetPointerAbsolutePosition(0);
const s32 mouse_x = static_cast<s32>(fmouse_x);
const s32 mouse_y = static_cast<s32>(fmouse_y);
// are we within the active display area?
u32 tick, line;

View File

@ -6,7 +6,7 @@
#include "host.h"
#include "system.h"
#include "util/gpu_device.h"
#include "util/input_manager.h"
#include "util/state_wrapper.h"
#include "common/assert.h"
@ -20,8 +20,9 @@ static constexpr std::array<u8, static_cast<size_t>(PlayStationMouse::Button::Co
PlayStationMouse::PlayStationMouse(u32 index) : Controller(index)
{
m_last_host_position_x = g_gpu_device->GetMousePositionX();
m_last_host_position_y = g_gpu_device->GetMousePositionY();
const auto& [x, y] = InputManager::GetPointerAbsolutePosition(0);
m_last_host_position_x = static_cast<s32>(x);
m_last_host_position_y = static_cast<s32>(y);
}
PlayStationMouse::~PlayStationMouse() = default;
@ -161,8 +162,9 @@ bool PlayStationMouse::Transfer(const u8 data_in, u8* data_out)
void PlayStationMouse::UpdatePosition()
{
// get screen coordinates
const s32 mouse_x = g_gpu_device->GetMousePositionX();
const s32 mouse_y = g_gpu_device->GetMousePositionY();
const auto& [fmouse_x, fmouse_y] = InputManager::GetPointerAbsolutePosition(0);
const s32 mouse_x = static_cast<s32>(fmouse_x);
const s32 mouse_y = static_cast<s32>(fmouse_y);
const s32 delta_x = mouse_x - m_last_host_position_x;
const s32 delta_y = mouse_y - m_last_host_position_y;
m_last_host_position_x = mouse_x;

View File

@ -244,7 +244,7 @@ bool DisplayWidget::event(QEvent* event)
const float scaled_x = static_cast<float>(static_cast<qreal>(mouse_pos.x()) * dpr);
const float scaled_y = static_cast<float>(static_cast<qreal>(mouse_pos.y()) * dpr);
emit windowMouseMoveEvent(false, scaled_x, scaled_y);
InputManager::UpdatePointerAbsolutePosition(0, scaled_x, scaled_y);
}
else
{
@ -270,8 +270,10 @@ bool DisplayWidget::event(QEvent* event)
}
#endif
if (dx != 0.0f || dy != 0.0f)
emit windowMouseMoveEvent(true, dx, dy);
if (dx != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::X, dx);
if (dy != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::Y, dy);
}
return true;

View File

@ -38,7 +38,6 @@ Q_SIGNALS:
void windowRestoredEvent();
void windowKeyEvent(int key_code, bool pressed);
void windowTextEntered(const QString& text);
void windowMouseMoveEvent(bool relative, float x, float y);
void windowMouseButtonEvent(int button, bool pressed);
void windowMouseWheelEvent(const QPoint& angle_delta);

View File

@ -568,35 +568,6 @@ void EmuThread::onDisplayWindowTextEntered(const QString& text)
ImGuiManager::AddTextInput(text.toStdString());
}
void EmuThread::onDisplayWindowMouseMoveEvent(bool relative, float x, float y)
{
// display might be null here if the event happened after shutdown
DebugAssert(isOnThread());
if (!relative)
{
if (g_gpu_device)
g_gpu_device->SetMousePosition(static_cast<s32>(x), static_cast<s32>(y));
InputManager::UpdatePointerAbsolutePosition(0, x, y);
ImGuiManager::UpdateMousePosition(x, y);
}
else
{
if (x != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::X, x);
if (y != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::Y, y);
if (g_gpu_device)
{
const float abs_x = static_cast<float>(g_gpu_device->GetMousePositionX()) + x;
const float abs_y = static_cast<float>(g_gpu_device->GetMousePositionY()) + y;
g_gpu_device->SetMousePosition(static_cast<s32>(abs_x), static_cast<s32>(abs_y));
ImGuiManager::UpdateMousePosition(abs_x, abs_y);
}
}
}
void EmuThread::onDisplayWindowMouseButtonEvent(int button, bool pressed)
{
DebugAssert(isOnThread());
@ -733,7 +704,6 @@ void EmuThread::connectDisplaySignals(DisplayWidget* widget)
connect(widget, &DisplayWidget::windowRestoredEvent, this, &EmuThread::redrawDisplayWindow);
connect(widget, &DisplayWidget::windowKeyEvent, this, &EmuThread::onDisplayWindowKeyEvent);
connect(widget, &DisplayWidget::windowTextEntered, this, &EmuThread::onDisplayWindowTextEntered);
connect(widget, &DisplayWidget::windowMouseMoveEvent, this, &EmuThread::onDisplayWindowMouseMoveEvent);
connect(widget, &DisplayWidget::windowMouseButtonEvent, this, &EmuThread::onDisplayWindowMouseButtonEvent);
connect(widget, &DisplayWidget::windowMouseWheelEvent, this, &EmuThread::onDisplayWindowMouseWheelEvent);
}

View File

@ -192,7 +192,6 @@ public Q_SLOTS:
private Q_SLOTS:
void stopInThread();
void onDisplayWindowMouseMoveEvent(bool relative, float x, float y);
void onDisplayWindowMouseButtonEvent(int button, bool pressed);
void onDisplayWindowMouseWheelEvent(const QPoint& delta_angle);
void onDisplayWindowResized(int width, int height, float scale);

View File

@ -793,7 +793,6 @@ void GPUDevice::ClearDisplayTexture()
m_display_texture_view_y = 0;
m_display_texture_view_width = 0;
m_display_texture_view_height = 0;
m_display_changed = true;
}
void GPUDevice::SetDisplayTexture(GPUTexture* texture, s32 view_x, s32 view_y, s32 view_width, s32 view_height)
@ -804,7 +803,6 @@ void GPUDevice::SetDisplayTexture(GPUTexture* texture, s32 view_x, s32 view_y, s
m_display_texture_view_y = view_y;
m_display_texture_view_width = view_width;
m_display_texture_view_height = view_height;
m_display_changed = true;
}
void GPUDevice::SetDisplayTextureRect(s32 view_x, s32 view_y, s32 view_width, s32 view_height)
@ -813,7 +811,6 @@ void GPUDevice::SetDisplayTextureRect(s32 view_x, s32 view_y, s32 view_width, s3
m_display_texture_view_y = view_y;
m_display_texture_view_width = view_width;
m_display_texture_view_height = view_height;
m_display_changed = true;
}
void GPUDevice::SetDisplayParameters(s32 display_width, s32 display_height, s32 active_left, s32 active_top,
@ -826,7 +823,6 @@ void GPUDevice::SetDisplayParameters(s32 display_width, s32 display_height, s32
m_display_active_width = active_width;
m_display_active_height = active_height;
m_display_aspect_ratio = display_aspect_ratio;
m_display_changed = true;
}
bool GPUDevice::GetHostRefreshRate(float* refresh_rate)

View File

@ -506,15 +506,6 @@ public:
ALWAYS_INLINE GPUSampler* GetLinearSampler() const { return m_linear_sampler.get(); }
ALWAYS_INLINE GPUSampler* GetNearestSampler() const { return m_nearest_sampler.get(); }
// Position is relative to the top-left corner of the window.
ALWAYS_INLINE s32 GetMousePositionX() const { return m_mouse_position_x; }
ALWAYS_INLINE s32 GetMousePositionY() const { return m_mouse_position_y; }
ALWAYS_INLINE void SetMousePosition(s32 x, s32 y)
{
m_mouse_position_x = x;
m_mouse_position_y = y;
}
ALWAYS_INLINE const void* GetDisplayTextureHandle() const { return m_display_texture; }
ALWAYS_INLINE s32 GetDisplayWidth() const { return m_display_width; }
ALWAYS_INLINE s32 GetDisplayHeight() const { return m_display_height; }
@ -714,9 +705,6 @@ private:
u64 m_last_frame_displayed_time = 0;
s32 m_mouse_position_x = 0;
s32 m_mouse_position_y = 0;
s32 m_display_width = 0;
s32 m_display_height = 0;
s32 m_display_active_left = 0;
@ -736,8 +724,6 @@ private:
std::unique_ptr<GPUPipeline> m_imgui_pipeline;
std::unique_ptr<GPUTexture> m_imgui_font_texture;
bool m_display_changed = false;
std::unique_ptr<PostProcessingChain> m_post_processing_chain;
};

View File

@ -1038,9 +1038,18 @@ void InputManager::UpdatePointerAbsolutePosition(u32 index, float x, float y)
const float dy = y - std::exchange(s_host_pointer_positions[index][static_cast<u8>(InputPointerAxis::Y)], y);
if (dx != 0.0f)
UpdatePointerRelativeDelta(index, InputPointerAxis::X, dx);
{
s_pointer_state[index][static_cast<u8>(InputPointerAxis::X)].delta.fetch_add(static_cast<s32>(dx * 65536.0f),
std::memory_order_release);
}
if (dy != 0.0f)
UpdatePointerRelativeDelta(index, InputPointerAxis::Y, dy);
{
s_pointer_state[index][static_cast<u8>(InputPointerAxis::Y)].delta.fetch_add(static_cast<s32>(dy * 65536.0f),
std::memory_order_release);
}
if (index == 0)
ImGuiManager::UpdateMousePosition(x, y);
}
void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis, float d, bool raw_input)
@ -1048,8 +1057,12 @@ void InputManager::UpdatePointerRelativeDelta(u32 index, InputPointerAxis axis,
if (raw_input != IsUsingRawInput())
return;
s_host_pointer_positions[index][static_cast<u8>(axis)] += d;
s_pointer_state[index][static_cast<u8>(axis)].delta.fetch_add(static_cast<s32>(d * 65536.0f),
std::memory_order_release);
if (index == 0 && axis <= InputPointerAxis::Y)
ImGuiManager::UpdateMousePosition(s_host_pointer_positions[0][0], s_host_pointer_positions[0][1]);
}
void InputManager::UpdateHostMouseMode()