Merge remote-tracking branch 'winqt/qt' into winqt5

This commit is contained in:
Cacodemon345
2021-12-17 12:17:56 +06:00
17 changed files with 162 additions and 217 deletions

View File

@@ -34,7 +34,7 @@ endif()
# WIN32 marks us as a GUI app on Windows
# MACOSX_BUNDLE prepares a macOS application bundle including with the app icon
add_executable(86Box WIN32 MACOSX_BUNDLE 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c
add_executable(86Box WIN32 MACOSX_BUNDLE 86box.c config.c cpp11_thread.cpp log.c random.c timer.c io.c acpi.c apm.c
dma.c ddma.c nmi.c pic.c pit.c port_6x.c port_92.c ppi.c pci.c mca.c usb.c
device.c nvr.c nvr_at.c nvr_ps2.c rtmidi_midi.cpp ${APP_ICON_MACOSX})

133
src/cpp11_thread.cpp Normal file
View File

@@ -0,0 +1,133 @@
#include <mutex>
#include <thread>
#include <condition_variable>
#include <86box/plat.h>
struct event_cpp11_t
{
std::condition_variable cond;
std::mutex mutex;
bool state = false;
};
extern "C" {
thread_t *
thread_create(void (*thread_rout)(void *param), void *param)
{
auto thread = new std::thread([thread_rout, param] {
thread_rout(param);
});
return thread;
}
mutex_t *
thread_create_mutex_with_spin_count(unsigned int spin_count)
{
/* Setting spin count of a mutex is not possible with pthreads. */
return thread_create_mutex();
}
int
thread_wait(thread_t *arg, int timeout)
{
(void) timeout;
auto thread = reinterpret_cast<std::thread*>(arg);
thread->join();
return 0;
}
mutex_t *
thread_create_mutex(void)
{
auto mutex = new std::mutex;
return mutex;
}
int
thread_wait_mutex(mutex_t *_mutex)
{
if (_mutex == nullptr)
return(0);
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
mutex->lock();
return 1;
}
int
thread_release_mutex(mutex_t *_mutex)
{
if (_mutex == nullptr)
return(0);
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
mutex->unlock();
return 1;
}
void
thread_close_mutex(mutex_t *_mutex)
{
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
delete mutex;
}
event_t *
thread_create_event()
{
auto ev = new event_cpp11_t;
return ev;
}
int
thread_wait_event(event_t *handle, int timeout)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
auto lock = std::unique_lock<std::mutex>(event->mutex);
if (timeout < 0) {
event->cond.wait(lock, [event] { return event->state; });
} else {
auto to = std::chrono::system_clock::now() + std::chrono::milliseconds(timeout);
std::cv_status status;
do {
status = event->cond.wait_until(lock, to);
} while ((status != std::cv_status::timeout) && !event->state);
if (status == std::cv_status::timeout) {
return 1;
}
}
return 0;
}
void
thread_set_event(event_t *handle)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
{
auto lock = std::unique_lock<std::mutex>(event->mutex);
event->state = true;
}
event->cond.notify_all();
}
void
thread_reset_event(event_t *handle)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
auto lock = std::unique_lock<std::mutex>(event->mutex);
event->state = false;
}
void
thread_destroy_event(event_t *handle)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
delete event;
}
}

View File

@@ -133,8 +133,6 @@ target_link_libraries(
# needed for static builds
if (WIN32)
qt_import_plugins(plat INCLUDE Qt5::QWindowsIntegrationPlugin Qt5::QICOPlugin QWindowsVistaStylePlugin)
else()
qt_import_plugins(plat INCLUDE Qt5::QICOPlugin)
endif()
if (UNIX AND NOT APPLE)

View File

@@ -17,12 +17,6 @@ void HardwareRenderer::initializeGL()
}
void HardwareRenderer::paintGL() {
//onPaint(this);
}
void HardwareRenderer::paintUnderGL() {
glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
onPaint(this);
}

View File

@@ -27,9 +27,8 @@ public:
void resizeGL(int w, int h) override;
void initializeGL() override;
void paintGL() override;
void paintUnderGL() override;
HardwareRenderer(QWindow* parent = nullptr)
: QOpenGLWindow(QOpenGLWindow::PartialUpdateBlend, parent), QOpenGLFunctions()
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent), QOpenGLFunctions()
{
setMinimumSize(QSize(16, 16));
setFlags(Qt::FramelessWindowHint);

View File

@@ -5,6 +5,8 @@
#include <QLabel>
#include <QMouseEvent>
#include <memory>
class QStatusBar;
class ClickableLabel : public QLabel {

View File

@@ -15,6 +15,8 @@ RendererCommon::RendererCommon() = default;
void RendererCommon::onPaint(QPaintDevice* device) {
QPainter painter(device);
painter.setRenderHint(QPainter::SmoothPixmapTransform, video_filter_method > 0 ? true : false);
painter.fillRect(0, 0, device->width(), device->height(), QColorConstants::Black);
painter.setCompositionMode(QPainter::CompositionMode_Plus);
painter.drawImage(destination, image, source);
// "release" image, reducing it's refcount, so renderstack::blit()
// won't have to reallocate

View File

@@ -25,8 +25,8 @@ RendererStack::RendererStack(QWidget *parent) :
{
ui->setupUi(this);
imagebufs = QVector<QImage>(2);
imagebufs[0] = QImage{QSize(2048 + 64, 2048 + 64), QImage::Format_RGB32};
imagebufs[1] = QImage{QSize(2048 + 64, 2048 + 64), QImage::Format_RGB32};
imagebufs[0] = QImage{QSize(2048, 2048), QImage::Format_RGB32};
imagebufs[1] = QImage{QSize(2048, 2048), QImage::Format_RGB32};
buffers_in_use = std::vector<std::atomic_flag>(2);
buffers_in_use[0].clear();
@@ -222,11 +222,11 @@ void RendererStack::blit(int x, int y, int w, int h)
sw = this->w = w;
sh = this->h = h;
auto imagebits = imagebufs[currentBuf].bits();
video_copy(imagebits + y * ((2048 + 64) * 4) + x * 4, &(buffer32->line[y][x]), h * (2048 + 64) * sizeof(uint32_t));
video_copy(imagebits + y * ((2048) * 4) + x * 4, &(buffer32->line[y][x]), h * (2048) * sizeof(uint32_t));
if (screenshots)
{
video_screenshot((uint32_t *)imagebits, 0, 0, 2048 + 64);
video_screenshot((uint32_t *)imagebits, 0, 0, 2048);
}
video_blit_complete();
blitToRenderer(imagebufs[currentBuf], sx, sy, sw, sh, &buffers_in_use[currentBuf]);

View File

@@ -313,10 +313,10 @@ sdl_blit(int x, int y, int w, int h)
SDL_LockMutex(sdl_mutex);
SDL_LockTexture(sdl_tex, 0, &pixeldata, &pitch);
video_copy(pixeldata, &(buffer32->line[y][x]), h * (2048 + 64) * sizeof(uint32_t));
video_copy(pixeldata, &(buffer32->line[y][x]), h * (2048) * sizeof(uint32_t));
if (screenshots)
video_screenshot((uint32_t *) pixeldata, 0, 0, (2048 + 64));
video_screenshot((uint32_t *) pixeldata, 0, 0, (2048));
SDL_UnlockTexture(sdl_tex);
@@ -414,7 +414,7 @@ sdl_init_texture(void)
}
sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, (2048 + 64), (2048 + 64));
SDL_TEXTUREACCESS_STREAMING, (2048), (2048));
if (sdl_render == NULL) {
sdl_log("SDL: unable to SDL_CreateRenderer (%s)\n", SDL_GetError());

View File

@@ -22,9 +22,9 @@ SpecifyDimensions::SpecifyDimensions(QWidget *parent) :
{
ui->setupUi(this);
ui->checkBox->setChecked(vid_resize == 2);
ui->spinBoxWidth->setRange(16, 2048 + 64);
ui->spinBoxWidth->setRange(16, 2048);
ui->spinBoxWidth->setValue(main_window->getRenderWidgetSize().width());
ui->spinBoxHeight->setRange(16, 2048 + 64);
ui->spinBoxHeight->setRange(16, 2048);
ui->spinBoxHeight->setValue(main_window->getRenderWidgetSize().height());
}

View File

@@ -134,9 +134,9 @@ sdl_blit_shim(int x, int y, int w, int h)
params.w = w;
params.h = h;
if (!(!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)))
video_copy(interpixels, &(buffer32->line[y][x]), h * (2048 + 64) * sizeof(uint32_t));
video_copy(interpixels, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t));
if (screenshots)
video_screenshot(interpixels, 0, 0, (2048 + 64));
video_screenshot(interpixels, 0, 0, 2048);
blitreq = 1;
video_blit_complete();
}
@@ -198,7 +198,7 @@ sdl_blit(int x, int y, int w, int h)
r_src.y = y;
r_src.w = w;
r_src.h = h;
SDL_UpdateTexture(sdl_tex, &r_src, interpixels, (2048 + 64) * 4);
SDL_UpdateTexture(sdl_tex, &r_src, interpixels, 2048 * 4);
blitreq = 0;
sdl_real_blit(&r_src);

View File

@@ -831,7 +831,7 @@ video_init(void)
}
/* Account for overscan. */
buffer32 = create_bitmap(2048 + 64, 2048 + 64);
buffer32 = create_bitmap(2048, 2048);
for (c = 0; c < 64; c++) {
cgapal[c + 64].r = (((c & 4) ? 2 : 0) | ((c & 0x10) ? 1 : 0)) * 21;

View File

@@ -15,8 +15,8 @@
enable_language(RC)
add_library(plat OBJECT win.c win_dynld.c win_cdrom.c win_thread.c
win_keyboard.c win_crashdump.c win_mouse.c)
add_library(plat OBJECT win.c win_dynld.c win_cdrom.c win_keyboard.c
win_crashdump.c win_mouse.c)
add_library(ui OBJECT win_ui.c win_icon.c win_stbar.c win_sdl.c win_dialog.c win_about.c
win_settings.c win_devconf.c win_snd_gain.c win_specify_dim.c win_new_floppy.c

View File

@@ -464,7 +464,7 @@ CXXFLAGS := $(CFLAGS)
#########################################################################
# Create the (final) list of objects to build. #
#########################################################################
MAINOBJ := 86box.o config.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \
MAINOBJ := 86box.o config.o cpp11_thread.o log.o random.o timer.o io.o acpi.o apm.o dma.o ddma.o \
nmi.o pic.o pit.o port_6x.o port_92.o ppi.o pci.o mca.o \
usb.o device.o nvr.o nvr_at.o nvr_ps2.o rtmidi_midi.o \
$(VNCOBJ)
@@ -672,7 +672,7 @@ VOODOOOBJ := vid_voodoo.o vid_voodoo_banshee.o \
vid_voodoo_texture.o
PLATOBJ := win.o \
win_dynld.o win_thread.o \
win_dynld.o \
win_cdrom.o win_keyboard.o \
win_crashdump.o \
win_mouse.o

View File

@@ -62,10 +62,10 @@ typedef LONG atomic_flag;
static const int INIT_WIDTH = 640;
static const int INIT_HEIGHT = 400;
static const int BUFFERPIXELS = 4460544; /* Same size as render_buffer, pow(2048+64,2). */
static const int BUFFERBYTES = 17842176; /* Pixel is 4 bytes. */
static const int BUFFERPIXELS = 4194304; /* Same size as render_buffer, pow(2048+64,2). */
static const int BUFFERBYTES = 16777216; /* Pixel is 4 bytes. */
static const int BUFFERCOUNT = 3; /* How many buffers to use for pixel transfer (2-3 is commonly recommended). */
static const int ROW_LENGTH = 2112; /* Source buffer row lenght (including padding) */
static const int ROW_LENGTH = 2048; /* Source buffer row lenght (including padding) */
/**
* @brief A dedicated OpenGL thread.

View File

@@ -244,10 +244,10 @@ sdl_blit(int x, int y, int w, int h)
SDL_LockTexture(sdl_tex, 0, &pixeldata, &pitch);
video_copy(pixeldata, &(buffer32->line[y][x]), h * (2048 + 64) * sizeof(uint32_t));
video_copy(pixeldata, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t));
if (screenshots)
video_screenshot((uint32_t *) pixeldata, 0, 0, (2048 + 64));
video_screenshot((uint32_t *) pixeldata, 0, 0, 2048);
SDL_UnlockTexture(sdl_tex);
@@ -358,7 +358,7 @@ sdl_init_texture(void)
sdl_render = SDL_CreateRenderer(sdl_win, -1, SDL_RENDERER_SOFTWARE);
sdl_tex = SDL_CreateTexture(sdl_render, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, (2048 + 64), (2048 + 64));
SDL_TEXTUREACCESS_STREAMING, 2048, 2048);
}

View File

@@ -1,183 +0,0 @@
/*
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
*
* This file is part of the 86Box distribution.
*
* Implement threads and mutexes for the Win32 platform.
*
*
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Fred N. van Kempen, <decwiz@yahoo.com>
*
* Copyright 2008-2018 Sarah Walker.
* Copyright 2017,2018 Fred N. van Kempen.
*/
#define UNICODE
#define BITMAP WINDOWS_BITMAP
#include <windows.h>
#include <windowsx.h>
#include <process.h>
#undef BITMAP
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <wchar.h>
#include <86box/86box.h>
#include <86box/plat.h>
typedef struct {
HANDLE handle;
} win_event_t;
thread_t *
thread_create(void (*func)(void *param), void *param)
{
uintptr_t bt = _beginthread(func, 0, param);
return((thread_t *)bt);
}
int
thread_wait(thread_t *arg, int timeout)
{
if (arg == NULL) return(0);
if (timeout == -1)
timeout = INFINITE;
if (WaitForSingleObject(arg, timeout)) return(1);
return(0);
}
event_t *
thread_create_event(void)
{
win_event_t *ev = malloc(sizeof(win_event_t));
ev->handle = CreateEvent(NULL, FALSE, FALSE, NULL);
return((event_t *)ev);
}
void
thread_set_event(event_t *arg)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return;
SetEvent(ev->handle);
}
void
thread_reset_event(event_t *arg)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return;
ResetEvent(ev->handle);
}
int
thread_wait_event(event_t *arg, int timeout)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return(0);
if (ev->handle == NULL) return(0);
if (timeout == -1)
timeout = INFINITE;
if (WaitForSingleObject(ev->handle, timeout)) return(1);
return(0);
}
void
thread_destroy_event(event_t *arg)
{
win_event_t *ev = (win_event_t *)arg;
if (arg == NULL) return;
CloseHandle(ev->handle);
free(ev);
}
mutex_t *
thread_create_mutex(void)
{
mutex_t *mutex = malloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSection(mutex);
return mutex;
}
mutex_t *
thread_create_mutex_with_spin_count(unsigned int spin_count)
{
mutex_t *mutex = malloc(sizeof(CRITICAL_SECTION));
InitializeCriticalSectionAndSpinCount(mutex, spin_count);
return mutex;
}
int
thread_wait_mutex(mutex_t *mutex)
{
if (mutex == NULL) return(0);
LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION)mutex;
EnterCriticalSection(critsec);
return 1;
}
int
thread_release_mutex(mutex_t *mutex)
{
if (mutex == NULL) return(0);
LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION)mutex;
LeaveCriticalSection(critsec);
return 1;
}
void
thread_close_mutex(mutex_t *mutex)
{
if (mutex == NULL) return;
LPCRITICAL_SECTION critsec = (LPCRITICAL_SECTION)mutex;
DeleteCriticalSection(critsec);
free(critsec);
}