From 7de6a25b41f2ab08055e87eefab467843e6455a7 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 26 Mar 2022 11:31:14 +0000 Subject: [PATCH] Remove `(un)lock_buf` We do not seem to render from multiple threads, so these calls are unnecessary. --- Source/capture.cpp | 2 -- Source/dx.cpp | 53 --------------------------------------------- Source/dx.h | 2 -- Source/interfac.cpp | 3 --- Source/scrollrt.cpp | 11 ---------- 5 files changed, 71 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 60bef06cc..bcb60d00c 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -169,7 +169,6 @@ void CaptureScreen() PaletteGetEntries(256, palette); RedPalette(); - lock_buf(2); const Surface &buf = GlobalBackBuffer(); success = CaptureHdr(buf.w(), buf.h(), &outStream); if (success) { @@ -178,7 +177,6 @@ void CaptureScreen() if (success) { success = CapturePal(palette, &outStream); } - unlock_buf(2); outStream.close(); if (!success) { diff --git a/Source/dx.cpp b/Source/dx.cpp index 51854dca5..ba45975c1 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -13,7 +13,6 @@ #include "options.h" #include "utils/display.h" #include "utils/log.hpp" -#include "utils/sdl_mutex.h" #include "utils/sdl_wrap.h" #ifdef __3DS__ @@ -46,12 +45,6 @@ bool RenderDirectlyToOutputSurface; namespace { -int sgdwLockCount; -#ifdef _DEBUG -int locktbl[256]; -#endif -SdlMutex MemCrit; - bool CanRenderDirectlyToOutputSurface() { #ifdef USE_SDL1 @@ -68,26 +61,6 @@ bool CanRenderDirectlyToOutputSurface() #endif } -void LockBufPriv() -{ - MemCrit.lock(); - if (sgdwLockCount != 0) { - sgdwLockCount++; - return; - } - - sgdwLockCount++; -} - -void UnlockBufPriv() -{ - if (sgdwLockCount == 0) - app_fatal("draw main unlock error"); - - sgdwLockCount--; - MemCrit.unlock(); -} - /** * @brief Limit FPS to avoid high CPU load, use when v-sync isn't available */ @@ -119,31 +92,8 @@ void dx_init() pal_surface_palette_version = 1; } -void lock_buf(int idx) // NOLINT(misc-unused-parameters) -{ -#ifdef _DEBUG - ++locktbl[idx]; -#endif - LockBufPriv(); -} - -void unlock_buf(int idx) // NOLINT(misc-unused-parameters) -{ -#ifdef _DEBUG - if (locktbl[idx] == 0) - app_fatal("Draw lock underflow: 0x%x", idx); - --locktbl[idx]; -#endif - UnlockBufPriv(); -} - Surface GlobalBackBuffer() { - if (sgdwLockCount == 0) { - Log("WARNING: Trying to obtain GlobalBackBuffer() without holding a lock"); - return Surface(); - } - return Surface(PalSurface, SDL_Rect { 0, 0, gnScreenWidth, gnScreenHeight }); } @@ -153,9 +103,6 @@ void dx_cleanup() if (ghMainWnd != nullptr) SDL_HideWindow(ghMainWnd); #endif - MemCrit.lock(); - sgdwLockCount = 0; - MemCrit.unlock(); PalSurface = nullptr; PinnedPalSurface = nullptr; diff --git a/Source/dx.h b/Source/dx.h index 0973d9c48..edca17ad1 100644 --- a/Source/dx.h +++ b/Source/dx.h @@ -15,8 +15,6 @@ extern bool RenderDirectlyToOutputSurface; Surface GlobalBackBuffer(); void dx_init(); -void lock_buf(int idx); -void unlock_buf(int idx); void dx_cleanup(); void CreateBackBuffer(); void InitPalette(); diff --git a/Source/interfac.cpp b/Source/interfac.cpp index 1324d3928..a168a4433 100644 --- a/Source/interfac.cpp +++ b/Source/interfac.cpp @@ -170,7 +170,6 @@ void InitCutscene(interface_mode uMsg) void DrawCutscene() { - lock_buf(1); const Surface &out = GlobalBackBuffer(); DrawArt(out, { PANEL_X - (ArtCutsceneWidescreen.w() - PANEL_WIDTH) / 2, UI_OFFSET_Y }, &ArtCutsceneWidescreen); CelDrawTo(out, { PANEL_X, 480 - 1 + UI_OFFSET_Y }, *sgpBackCel, 1); @@ -183,8 +182,6 @@ void DrawCutscene() ProgressHeight); SDL_FillRect(out.surface, &rect, BarColor[progress_id]); - unlock_buf(1); - BltFast(&rect, &rect); RenderPresent(); } diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 38b3fb306..be152b625 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1564,12 +1564,8 @@ extern SDL_Surface *PalSurface; void ClearScreenBuffer() { - lock_buf(3); - assert(PalSurface != nullptr); SDL_FillRect(PalSurface, nullptr, 0); - - unlock_buf(3); } #ifdef _DEBUG @@ -1670,9 +1666,7 @@ void scrollrt_draw_game_screen() if (IsHardwareCursor()) { SetHardwareCursorVisible(ShouldShowCursor()); } else { - lock_buf(0); DrawCursor(GlobalBackBuffer()); - unlock_buf(0); } DrawMain(hgt, false, false, false, false, false); @@ -1680,9 +1674,7 @@ void scrollrt_draw_game_screen() RenderPresent(); if (!IsHardwareCursor()) { - lock_buf(0); UndrawCursor(GlobalBackBuffer()); - unlock_buf(0); } } @@ -1712,7 +1704,6 @@ void DrawAndBlit() force_redraw = 0; - lock_buf(0); const Surface &out = GlobalBackBuffer(); UndrawCursor(out); @@ -1754,8 +1745,6 @@ void DrawAndBlit() DrawFPS(out); - unlock_buf(0); - DrawMain(hgt, ddsdesc, drawhpflag, drawmanaflag, drawsbarflag, drawbtnflag); RenderPresent();