Browse Source

Remove `(un)lock_buf`

We do not seem to render from multiple threads, so these calls are
unnecessary.
pull/4238/head
Gleb Mazovetskiy 4 years ago
parent
commit
7de6a25b41
  1. 2
      Source/capture.cpp
  2. 53
      Source/dx.cpp
  3. 2
      Source/dx.h
  4. 3
      Source/interfac.cpp
  5. 11
      Source/scrollrt.cpp

2
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) {

53
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;

2
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();

3
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();
}

11
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();

Loading…
Cancel
Save