mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-21 21:52:04 +02:00
Make Graphics thread-safety optional
This commit is contained in:
parent
b0e08f60bb
commit
dba559aafb
4 changed files with 33 additions and 15 deletions
|
@ -356,6 +356,7 @@ DEF_GRA_PROP_B(FixedAspectRatio)
|
|||
DEF_GRA_PROP_B(SmoothScaling)
|
||||
DEF_GRA_PROP_B(IntegerScaling)
|
||||
DEF_GRA_PROP_B(LastMileScaling)
|
||||
DEF_GRA_PROP_B(Threadsafe)
|
||||
|
||||
#define INIT_GRA_PROP_BIND(PropName, prop_name_s) \
|
||||
{ \
|
||||
|
@ -407,4 +408,5 @@ void graphicsBindingInit()
|
|||
INIT_GRA_PROP_BIND( SmoothScaling, "smooth_scaling" );
|
||||
INIT_GRA_PROP_BIND( IntegerScaling, "integer_scaling" );
|
||||
INIT_GRA_PROP_BIND( LastMileScaling, "last_mile_scaling" );
|
||||
INIT_GRA_PROP_BIND( Threadsafe, "thread_safe" );
|
||||
}
|
||||
|
|
|
@ -2955,7 +2955,7 @@
|
|||
"$(DEPENDENCY_SEARCH_PATH)/include/SDL2",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/pixman-1",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/arm64-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/AL",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/openssl",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/uchardet",
|
||||
|
@ -3042,7 +3042,7 @@
|
|||
"$(DEPENDENCY_SEARCH_PATH)/include/SDL2",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/pixman-1",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/arm64-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/AL",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/openssl",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/uchardet",
|
||||
|
@ -3128,7 +3128,7 @@
|
|||
"$(DEPENDENCY_SEARCH_PATH)/include/SDL2",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/pixman-1",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/arm64-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/AL",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/uchardet",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/openssl",
|
||||
|
@ -3209,7 +3209,7 @@
|
|||
"$(DEPENDENCY_SEARCH_PATH)/include/SDL2",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/pixman-1",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/arm64-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/ruby-$(MRI_VERSION)/-darwin",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/AL",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/uchardet",
|
||||
"$(DEPENDENCY_SEARCH_PATH)/include/openssl",
|
||||
|
|
|
@ -760,6 +760,7 @@ struct GraphicsPrivate {
|
|||
SDL_mutex *avgFPSLock;
|
||||
|
||||
SDL_mutex *glResourceLock;
|
||||
bool multithreadedMode;
|
||||
|
||||
/* Global list of all live Disposables
|
||||
* (disposed on reset) */
|
||||
|
@ -769,9 +770,9 @@ struct GraphicsPrivate {
|
|||
: scRes(DEF_SCREEN_W, DEF_SCREEN_H), scSize(scRes),
|
||||
winSize(rtData->config.defScreenW, rtData->config.defScreenH),
|
||||
screen(scRes.x, scRes.y), threadData(rtData),
|
||||
glCtx(SDL_GL_GetCurrentContext()), frameRate(DEF_FRAMERATE),
|
||||
frameCount(0), brightness(255), fpsLimiter(frameRate),
|
||||
useFrameSkip(rtData->config.frameSkip), frozen(false),
|
||||
glCtx(SDL_GL_GetCurrentContext()), multithreadedMode(true),
|
||||
frameRate(DEF_FRAMERATE), frameCount(0), brightness(255),
|
||||
fpsLimiter(frameRate), useFrameSkip(rtData->config.frameSkip), frozen(false),
|
||||
last_update(0), last_avg_update(0), backingScaleFactor(1), integerScaleFactor(0, 0),
|
||||
integerScaleActive(rtData->config.integerScaling.active),
|
||||
integerLastMileScaling(rtData->config.integerScaling.lastMileScaling) {
|
||||
|
@ -1048,12 +1049,16 @@ struct GraphicsPrivate {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void setLock() {
|
||||
void setLock(bool force = false) {
|
||||
if (!(force || multithreadedMode)) return;
|
||||
|
||||
SDL_LockMutex(glResourceLock);
|
||||
SDL_GL_MakeCurrent(threadData->window, threadData->glContext);
|
||||
}
|
||||
|
||||
void releaseLock() {
|
||||
void releaseLock(bool force = false) {
|
||||
if (!(force || multithreadedMode)) return;
|
||||
|
||||
SDL_UnlockMutex(glResourceLock);
|
||||
}
|
||||
};
|
||||
|
@ -1532,6 +1537,16 @@ void Graphics::setLastMileScaling(bool value)
|
|||
p->updateScreenResoRatio(p->threadData);
|
||||
}
|
||||
|
||||
bool Graphics::getThreadsafe() const
|
||||
{
|
||||
return p->multithreadedMode;
|
||||
}
|
||||
|
||||
void Graphics::setThreadsafe(bool value)
|
||||
{
|
||||
p->multithreadedMode = value;
|
||||
}
|
||||
|
||||
double Graphics::getScale() const {
|
||||
p->checkResize();
|
||||
return (double)(p->winSize.y / p->backingScaleFactor) / p->scRes.y;
|
||||
|
@ -1583,12 +1598,12 @@ void Graphics::repaintWait(const AtomicFlag &exitCond, bool checkReset) {
|
|||
GLMeta::blitEnd();
|
||||
}
|
||||
|
||||
void Graphics::lock() {
|
||||
p->setLock();
|
||||
void Graphics::lock(bool force) {
|
||||
p->setLock(force);
|
||||
}
|
||||
|
||||
void Graphics::unlock() {
|
||||
p->releaseLock();
|
||||
void Graphics::unlock(bool force) {
|
||||
p->releaseLock(force);
|
||||
}
|
||||
|
||||
void Graphics::addDisposable(Disposable *d) { p->dispList.append(d->link); }
|
||||
|
|
|
@ -77,6 +77,7 @@ public:
|
|||
DECL_ATTR( SmoothScaling, bool )
|
||||
DECL_ATTR( IntegerScaling, bool )
|
||||
DECL_ATTR( LastMileScaling, bool )
|
||||
DECL_ATTR( Threadsafe, bool )
|
||||
double averageFrameRate();
|
||||
|
||||
/* <internal> */
|
||||
|
@ -87,8 +88,8 @@ public:
|
|||
void repaintWait(const AtomicFlag &exitCond,
|
||||
bool checkReset = true);
|
||||
|
||||
void lock();
|
||||
void unlock();
|
||||
void lock(bool force = false);
|
||||
void unlock(bool force = false);
|
||||
|
||||
private:
|
||||
Graphics(RGSSThreadData *data);
|
||||
|
|
Loading…
Add table
Reference in a new issue