Browse Source

Delay reinitializing hwcursor until fade 1

With fade 0 the cursor is never visible because everything is black.

While this is a very minor optimization, it works around
one of the instances of a bug in certain drivers as seen in #5618.
pull/6138/head
Gleb Mazovetskiy 3 years ago
parent
commit
750cebc561
  1. 15
      Source/DiabloUI/diabloui.cpp
  2. 12
      Source/engine/palette.cpp
  3. 2
      Source/engine/palette.h
  4. 7
      Source/interfac.cpp

15
Source/DiabloUI/diabloui.cpp

@ -331,12 +331,12 @@ void UiOnBackgroundChange()
fadeTc = 0;
fadeValue = 0;
BlackPalette();
if (IsHardwareCursorEnabled() && ArtCursor && ControlDevice == ControlTypes::KeyboardAndMouse && GetCurrentCursorInfo().type() != CursorType::UserInterface) {
SetHardwareCursor(CursorInfo::UserInterfaceCursor());
}
BlackPalette();
SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000);
if (DiabloUiSurface() == PalSurface)
BltFast(nullptr, nullptr);
@ -749,8 +749,10 @@ void UiFadeIn()
fadeValue = 256;
fadeTc = 0;
}
if (fadeValue != prevFadeValue)
SetFadeLevel(fadeValue);
if (fadeValue != prevFadeValue) {
// We can skip hardware cursor update for fade level 0 (everything is black).
SetFadeLevel(fadeValue, /*updateHardwareCursor=*/fadeValue != 0);
}
}
if (DiabloUiSurface() == PalSurface)
@ -796,8 +798,9 @@ void UiPollAndRender(std::optional<tl::function_ref<bool(SDL_Event &)>> eventHan
DrawMouse();
UiFadeIn();
// Must happen after the very first UiFadeIn, which sets the cursor.
if (IsHardwareCursor())
// Must happen after at least one call to `UiFadeIn` with non-zero fadeValue.
// `UiFadeIn` calls `SetFadeLevel` which reinitializes the hardware cursor.
if (IsHardwareCursor() && fadeValue != 0)
SetHardwareCursorVisible(ControlDevice == ControlTypes::KeyboardAndMouse);
#ifdef __3DS__

12
Source/engine/palette.cpp

@ -274,7 +274,7 @@ int UpdateGamma(int gamma)
return 130 - *sgOptions.Graphics.gammaCorrection;
}
void SetFadeLevel(int fadeval)
void SetFadeLevel(int fadeval, bool updateHardwareCursor)
{
if (HeadlessMode)
return;
@ -285,14 +285,17 @@ void SetFadeLevel(int fadeval)
system_palette[i].b = (fadeval * logical_palette[i].b) / 256;
}
palette_update();
if (IsHardwareCursor()) {
if (updateHardwareCursor && IsHardwareCursor()) {
ReinitializeHardwareCursor();
}
}
void BlackPalette()
{
SetFadeLevel(0);
// With fade level 0 updating the hardware cursor may be redundant
// since everything is black. The caller should update the cursor
// when needed instead.
SetFadeLevel(0, /*updateHardwareCursor=*/false);
}
void PaletteFadeIn(int fr)
@ -310,7 +313,8 @@ void PaletteFadeIn(int fr)
uint32_t prevFadeValue = 255;
for (uint32_t i = 0; i < 256; i = fr * (SDL_GetTicks() - tc) / 50) {
if (i != prevFadeValue) {
SetFadeLevel(i);
// We can skip hardware cursor update for fade level 0 (everything is black).
SetFadeLevel(i, /*updateHardwareCursor=*/i != 0u);
prevFadeValue = i;
}
BltFast(nullptr, nullptr);

2
Source/engine/palette.h

@ -60,7 +60,7 @@ void ApplyGamma(std::array<SDL_Color, 256> &dst, const std::array<SDL_Color, 256
void DecreaseGamma();
int UpdateGamma(int gamma);
void BlackPalette();
void SetFadeLevel(int fadeval);
void SetFadeLevel(int fadeval, bool updateHardwareCursor = true);
/**
* @brief Fade screen from black
* @param fr Steps per 50ms

7
Source/interfac.cpp

@ -295,6 +295,10 @@ void ShowProgress(interface_mode uMsg)
interface_msg_pump();
ClearScreenBuffer();
scrollrt_draw_game_screen();
if (IsHardwareCursor())
SetHardwareCursorVisible(false);
BlackPalette();
// Blit the background once and then free it.
@ -315,9 +319,6 @@ void ShowProgress(interface_mode uMsg)
}
FreeCutsceneBackground();
if (IsHardwareCursor())
SetHardwareCursorVisible(false);
PaletteFadeIn(8);
IncProgress();
sound_init();

Loading…
Cancel
Save