Fix context resizing and joystick detection.

This commit is contained in:
BearOso 2023-07-15 19:14:44 -05:00
parent e42dd27cd1
commit 3f0f246028
12 changed files with 61 additions and 27 deletions

View File

@ -106,16 +106,11 @@ bool S9xCubebSoundDriver::open_device(int playback_rate, int buffer_size)
uint32_t suggested_latency = playback_rate * buffer_size / 1000;
uint32_t min_latency;
cubeb_get_min_latency(context, &params, &min_latency);
if (min_latency > suggested_latency)
{
suggested_latency = min_latency;
printf("Requires a minimum latency: %d\n", min_latency);
}
auto retval = cubeb_stream_init(context, &stream, "Snes9x",
nullptr, nullptr,
nullptr, &params,
suggested_latency,
min_latency,
&::data_callback,
&state_callback,
this);
@ -127,7 +122,7 @@ bool S9xCubebSoundDriver::open_device(int playback_rate, int buffer_size)
return false;
}
buffer.resize(suggested_latency * 4);
buffer.resize(suggested_latency * 2);
return true;
}

@ -1 +1 @@
Subproject commit 197a273fd494321157f40a962c51b5fa8c9c3581
Subproject commit 4e2fdb25671c742a9fbe93a6034eb1542244c7e1

2
external/glslang vendored

@ -1 +1 @@
Subproject commit 3ebb72cc7429f0ab8218104dc3687c659c0f364d
Subproject commit 9c7fd1a33e5cecbe465e1cd70170167d5e40d398

View File

@ -38,6 +38,12 @@ BindingPanel::~BindingPanel()
void BindingPanel::showEvent(QShowEvent *event)
{
app->joypads_changed_callback = [&]
{
if (joypads_changed)
joypads_changed();
};
QWidget::showEvent(event);
}
@ -45,6 +51,8 @@ void BindingPanel::hideEvent(QHideEvent *event)
{
awaiting_binding = false;
setRedirectInput(false);
app->joypads_changed_callback = nullptr;
QWidget::hideEvent(event);
}
@ -56,16 +64,10 @@ void BindingPanel::setRedirectInput(bool redirect)
{
finalizeCurrentBinding(b);
};
app->joypads_changed_callback = [&] {
if (joypads_changed)
joypads_changed();
};
}
else
{
app->binding_callback = nullptr;
app->joypads_changed_callback = nullptr;
}
}

View File

@ -147,6 +147,12 @@ void ControllerPanel::clearAllControllers()
fillTable();
}
void ControllerPanel::showEvent(QShowEvent *event)
{
BindingPanel::showEvent(event);
recreateAutoAssignMenu();
}
ControllerPanel::~ControllerPanel()
{
}

View File

@ -11,6 +11,7 @@ class ControllerPanel :
public:
ControllerPanel(EmuApplication *app);
~ControllerPanel();
void showEvent(QShowEvent *event) override;
void clearAllControllers();
void clearCurrentController();
void autoPopulateWithKeyboard(int slot);

View File

@ -141,7 +141,7 @@ EmuBinding EmuBinding::from_config_string(std::string string)
{
return joystick_button(device, button);
}
else if (sscanf(substr.c_str(), "%u hat %u %5s", &device, &axis, direction_string))
else if (sscanf(substr.c_str(), "%u hat %u %5s", &device, &axis, direction_string) == 3)
{
uint8_t direction;
if (!strcmp(direction_string, "up"))
@ -188,7 +188,7 @@ std::string EmuBinding::to_string(bool config)
else if (type == Joystick)
{
if (config)
rep += "joystick " + std::to_string(guid) + " ";
rep += "Joystick " + std::to_string(guid) + " ";
else
rep += "J" + std::to_string(guid) + " ";
@ -201,7 +201,12 @@ std::string EmuBinding::to_string(bool config)
{
rep += "Axis ";
rep += std::to_string(axis) + " ";
rep += std::to_string(threshold) + "%";
if (threshold >= 0)
rep += "+";
else if (!config)
rep += "-";
if (config)
rep += std::to_string(threshold) + "%";
}
if (input_type == Hat)
{

View File

@ -323,9 +323,8 @@ void EmuCanvasOpenGL::paintEvent(QPaintEvent *event)
return;
}
#ifdef _WIN32
((WGLContext *)context.get())->resize();
#endif
context->resize();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
context->swap_buffers();

View File

@ -208,12 +208,12 @@ void EmuCanvasVulkan::resizeEvent(QResizeEvent *event)
std::tie(width, height) = wayland_surface->get_size();
// On Wayland, Vulkan WSI provides the buffer for the subsurface,
// so we have to specify a width and height instead of polling the parent.
context->recreate_swapchain(width, height);
context->swapchain->check_and_resize(width, height);
return;
}
#endif
context->recreate_swapchain(-1, -1);
context->swapchain->check_and_resize(event->size().width() * devicePixelRatio(), event->size().height() * devicePixelRatio());
}
void EmuCanvasVulkan::paintEvent(QPaintEvent *event)
@ -226,7 +226,9 @@ void EmuCanvasVulkan::paintEvent(QPaintEvent *event)
if (output_data.ready)
{
if (!window->isActivelyDrawing())
{
draw();
}
return;
}

View File

@ -553,10 +553,10 @@ bool EmuMainWindow::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::Resize)
{
app->suspendThread();
canvas->resizeEvent((QResizeEvent *)event);
app->emu_thread->runOnThread([&] {
canvas->resizeEvent((QResizeEvent *)event);
}, true);
event->accept();
app->unsuspendThread();
return true;
}
else if (event->type() == QEvent::Paint)

View File

@ -90,6 +90,29 @@ vk::Image Swapchain::get_image()
return imageviewfbs[current_swapchain_image].image;
}
bool Swapchain::check_and_resize(int width, int height)
{
vk::SurfaceCapabilitiesKHR surface_capabilities;
if (width == -1 && height == -1)
{
surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(surface);
width = surface_capabilities.currentExtent.width;
height = surface_capabilities.currentExtent.height;
}
if (width < 1 || height < 1)
return false;
if (extents.width != width || extents.height != height)
{
recreate(width, height);
return true;
}
return false;
}
bool Swapchain::create(unsigned int desired_num_swapchain_images, int new_width, int new_height)
{
frames.clear();
@ -217,7 +240,7 @@ bool Swapchain::begin_frame()
if (result_value.result == vk::Result::eErrorOutOfDateKHR ||
result_value.result == vk::Result::eSuboptimalKHR)
{
printf("Out of date\n");
// printf("Out of date\n");
recreate();
return begin_frame();
}

View File

@ -19,6 +19,7 @@ class Swapchain
~Swapchain();
bool create(unsigned int num_frames, int width = -1, int height = -1);
bool recreate(int width = -1, int height = -1);
bool check_and_resize(int width = -1, int height = -1);
bool begin_frame();
void begin_render_pass();
void end_render_pass();