Gtk: Clean up and modernize a bit.

This commit is contained in:
BearOso 2022-06-06 17:52:04 -05:00
parent 2e39f2f477
commit 6433b8f689
14 changed files with 344 additions and 793 deletions

View File

@ -392,7 +392,7 @@ static inline bool Diff (int c1, int c2)
return (false);
}
void HQ2X_16 (uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)
void HQ2X_16 (uint8 *srcPtr, int srcPitch, uint8 *dstPtr, int dstPitch, int width, int height)
{
int w1, w2, w3, w4, w5, w6, w7, w8, w9;
uint32 src1line = srcPitch >> 1;
@ -3091,7 +3091,7 @@ void HQ2X_16 (uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, in
}
}
void HQ3X_16 (uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)
void HQ3X_16 (uint8 *srcPtr, int srcPitch, uint8 *dstPtr, int dstPitch, int width, int height)
{
int w1, w2, w3, w4, w5, w6, w7, w8, w9;
uint32 src1line = srcPitch >> 1;
@ -6763,7 +6763,7 @@ void HQ3X_16 (uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, in
}
}
void HQ4X_16 (uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)
void HQ4X_16 (uint8 *srcPtr, int srcPitch, uint8 *dstPtr, int dstPitch, int width, int height)
{
int w1, w2, w3, w4, w5, w6, w7, w8, w9;
uint32 src1line = srcPitch >> 1;

View File

@ -9,8 +9,8 @@
bool8 S9xBlitHQ2xFilterInit (void);
void S9xBlitHQ2xFilterDeinit (void);
void HQ2X_16 (uint8 *, uint32, uint8 *, uint32, int, int);
void HQ3X_16 (uint8 *, uint32, uint8 *, uint32, int, int);
void HQ4X_16 (uint8 *, uint32, uint8 *, uint32, int, int);
void HQ2X_16 (uint8 *, int, uint8 *, int, int, int);
void HQ3X_16 (uint8 *, int, uint8 *, int, int, int);
void HQ4X_16 (uint8 *, int, uint8 *, int, int, int);
#endif

View File

@ -192,6 +192,8 @@ list(APPEND SOURCES
src/gtk_display_driver_gtk.h
src/gtk_display_driver.h
src/gtk_display.h
src/threadpool.cpp
src/threadpool.h
src/gtk_file.cpp
src/gtk_file.h
src/gtk_builder_window.cpp

View File

@ -24,9 +24,9 @@
/* Allows vertical overlap. We need this to avoid seams when threading */
void EPX_16_unsafe (uint8 *srcPtr,
uint32 srcPitch,
int srcPitch,
uint8 *dstPtr,
uint32 dstPitch,
int dstPitch,
int width,
int height)
{
@ -120,9 +120,9 @@ void EPX_16_unsafe (uint8 *srcPtr,
/* Blends with edge pixel instead of just using it directly. */
void EPX_16_smooth_unsafe (uint8 *srcPtr,
uint32 srcPitch,
int srcPitch,
uint8 *dstPtr,
uint32 dstPitch,
int dstPitch,
int width,
int height)
{

View File

@ -7,7 +7,7 @@
#ifndef __FILTER_EPX_UNSAFE_H
#define __FILTER_EPX_UNSAFE_H
void EPX_16_unsafe (uint8 *, uint32, uint8 *, uint32, int, int);
void EPX_16_smooth_unsafe (uint8 *, uint32, uint8 *, uint32, int, int);
void EPX_16_unsafe (uint8 *, int, uint8 *, int, int, int);
void EPX_16_smooth_unsafe (uint8 *, int, uint8 *, int, int, int);
#endif /* __FILTER_EPX_UNSAFE_H */

View File

@ -103,17 +103,17 @@ void xBRZ(uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int wi
}
}
void filter_2xBRZ(uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)
void filter_2xBRZ(uint8 *srcPtr, int srcPitch, uint8 *dstPtr, int dstPitch, int width, int height)
{
xBRZ(srcPtr, srcPitch, dstPtr, dstPitch, width, height, 2);
}
void filter_3xBRZ(uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)
void filter_3xBRZ(uint8 *srcPtr, int srcPitch, uint8 *dstPtr, int dstPitch, int width, int height)
{
xBRZ(srcPtr, srcPitch, dstPtr, dstPitch, width, height, 3);
}
void filter_4xBRZ(uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)
void filter_4xBRZ(uint8 *srcPtr, int srcPitch, uint8 *dstPtr, int dstPitch, int width, int height)
{
xBRZ(srcPtr, srcPitch, dstPtr, dstPitch, width, height, 4);
}

View File

@ -7,8 +7,8 @@
#ifndef _filter_xbrz_h_
#define _filter_xbrz_h_
void filter_2xBRZ (uint8 *, uint32, uint8 *, uint32, int, int);
void filter_3xBRZ (uint8 *, uint32, uint8 *, uint32, int, int);
void filter_4xBRZ (uint8 *, uint32, uint8 *, uint32, int, int);
void filter_2xBRZ (uint8 *, int, uint8 *, int, int, int);
void filter_3xBRZ (uint8 *, int, uint8 *, int, int, int);
void filter_4xBRZ (uint8 *, int, uint8 *, int, int, int);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -47,36 +47,6 @@ enum {
NTSC_RGB = 2
};
enum {
ENDIAN_NORMAL = 0,
ENDIAN_SWAPPED = 1
};
enum {
JOB_FILTER = 0,
JOB_CONVERT = 1,
JOB_SCALE_AND_CONVERT = 2,
JOB_CONVERT_YUV = 3,
JOB_CONVERT_MASK = 4
};
typedef struct thread_job_t
{
int operation_type;
uint8 *src_buffer;
int src_pitch;
uint8 *dst_buffer;
int dst_pitch;
int width;
int height;
int bpp;
int inv_rmask;
int inv_gmask;
int inv_bmask;
volatile bool complete;
} thread_job_t;
struct S9xRect
{
int x;
@ -86,7 +56,6 @@ struct S9xRect
};
void S9xRegisterYUVTables(uint8 *y, uint8 *u, uint8 *v);
void S9xSetEndianess(int type);
double S9xGetAspect();
S9xRect S9xApplyAspect(int, int, int, int);
void S9xConvertYUV(void *src_buffer,
@ -118,7 +87,7 @@ void S9xFilter(uint8 *src_buffer,
int dst_pitch,
int &width,
int &height);
void get_filter_scale(int &width, int &height);
void apply_filter_scale(int &width, int &height);
void S9xDisplayRefresh(int width, int height);
void S9xReinitDisplay();
void S9xDisplayReconfigure();

View File

@ -107,7 +107,7 @@ void S9xGTKDisplayDriver::clear()
S9xRect dst;
dst.w = window->last_width;
dst.h = window->last_height;
get_filter_scale(dst.w, dst.h);
apply_filter_scale(dst.w, dst.h);
dst = S9xApplyAspect(dst.w, dst.h, width, height);
if (dst.x > 0)

View File

@ -161,7 +161,6 @@ void S9xOpenGLDisplayDriver::update(uint16_t *buffer, int width, int height, int
pbo_memory = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
/* Pixel swizzling in software */
S9xSetEndianess(ENDIAN_NORMAL);
S9xConvert(buffer, pbo_memory, stride_in_pixels * 2, width * 4, width, height, 32);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);

View File

@ -294,12 +294,6 @@ int S9xXVDisplayDriver::init()
this->rshift = this->bshift;
this->bshift = copy;
}
/* on big-endian Xv still seems to like LSB order */
if (config->force_inverted_byte_order)
S9xSetEndianess(ENDIAN_SWAPPED);
else
S9xSetEndianess(ENDIAN_NORMAL);
}
}
}
@ -313,21 +307,6 @@ int S9xXVDisplayDriver::init()
format = formats[i].id;
depth = formats[i].depth;
if (formats[i].byte_order == LSBFirst)
{
if (config->force_inverted_byte_order)
S9xSetEndianess(ENDIAN_SWAPPED);
else
S9xSetEndianess(ENDIAN_NORMAL);
}
else
{
if (config->force_inverted_byte_order)
S9xSetEndianess(ENDIAN_NORMAL);
else
S9xSetEndianess(ENDIAN_SWAPPED);
}
break;
}
}
@ -454,7 +433,7 @@ void S9xXVDisplayDriver::clear()
S9xRect dst;
dst.w = window->last_width;
dst.h = window->last_height;
get_filter_scale(dst.w, dst.h);
apply_filter_scale(dst.w, dst.h);
dst = S9xApplyAspect(dst.w, dst.h, width, height);
if (dst.x > 0)

85
gtk/src/threadpool.cpp Normal file
View File

@ -0,0 +1,85 @@
#include "threadpool.h"
#include <chrono>
void threadpool::thread_func()
{
while (1)
{
std::unique_lock<std::mutex> lock(mutex);
cond.wait_for(lock, std::chrono::microseconds(100), [this] {
return (die || !jobs.empty());
});
if (die)
return;
if (jobs.empty())
continue;
auto job = std::move(jobs.front());
jobs.pop();
lock.unlock();
job();
}
}
void threadpool::start(int num_threads)
{
die = false;
while (!jobs.empty())
jobs.pop();
threads.resize(num_threads);
for (int i = 0; i < num_threads; i++)
threads.at(i) = std::thread(&threadpool::thread_func, this);
started = true;
}
void threadpool::wait_idle()
{
while (!futures.empty())
{
futures.front().wait();
std::unique_lock<std::mutex> lock(mutex);
futures.pop();
}
}
void threadpool::stop()
{
if (!started)
return;
std::unique_lock<std::mutex> lock(mutex);
die = true;
lock.unlock();
cond.notify_all();
for (auto &t : threads)
t.join();
threads.clear();
while (!jobs.empty())
jobs.pop();
started = false;
}
void threadpool::queue(std::function<void()> func)
{
std::unique_lock<std::mutex> lock(mutex);
std::packaged_task<void()> job(func);
futures.push(job.get_future().share());
jobs.push(std::move(job));
lock.unlock();
cond.notify_all();
return;
}

29
gtk/src/threadpool.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include <vector>
#include <queue>
#include <thread>
#include <functional>
#include <mutex>
#include <future>
#include <condition_variable>
class threadpool
{
public:
void start(int num_threads);
void stop();
void queue(std::function<void()> func);
void wait_idle();
private:
void thread_func();
std::vector<std::thread> threads;
std::queue<std::packaged_task<void()>> jobs;
std::queue<std::shared_future<void>> futures;
std::mutex mutex;
std::condition_variable cond;
bool die = false;
bool started = false;
};