Browse Source

Add optional debug logging for hwcursor

To help debug hardware cursor issues
pull/6123/head
Gleb Mazovetskiy 3 years ago
parent
commit
2cf15cebc8
  1. 31
      Source/hwcursor.cpp
  2. 18
      Source/hwcursor.hpp

31
Source/hwcursor.cpp

@ -69,13 +69,16 @@ bool ShouldUseBilinearScaling()
return *sgOptions.Graphics.scaleQuality != ScalingQuality::NearestPixel;
}
bool SetHardwareCursor(SDL_Surface *surface, HotpointPosition hotpointPosition)
bool SetHardwareCursorFromSurface(SDL_Surface *surface, HotpointPosition hotpointPosition)
{
SDLCursorUniquePtr newCursor;
const Size size { surface->w, surface->h };
const Size scaledSize = ScaledSize(size);
if (size == scaledSize) {
#if LOG_HWCURSOR
Log("hwcursor: SetHardwareCursorFromSurface {}x{}", size.width, size.height);
#endif
const Point hotpoint = GetHotpointPosition(*surface, hotpointPosition);
newCursor = SDLCursorUniquePtr { SDL_CreateColorCursor(surface, hotpoint.x, hotpoint.y) };
} else {
@ -84,8 +87,16 @@ bool SetHardwareCursor(SDL_Surface *surface, HotpointPosition hotpointPosition)
SDLSurfaceUniquePtr scaledSurface = SDLWrap::CreateRGBSurfaceWithFormat(0, scaledSize.width, scaledSize.height, 32, SDL_PIXELFORMAT_ARGB8888);
if (ShouldUseBilinearScaling()) {
#if LOG_HWCURSOR
Log("hwcursor: SetHardwareCursorFromSurface {}x{} scaled to {}x{} using bilinear scaling",
size.width, size.height, scaledSize.width, scaledSize.height);
#endif
BilinearScale32(converted.get(), scaledSurface.get());
} else {
#if LOG_HWCURSOR
Log("hwcursor: SetHardwareCursorFromSurface {}x{} scaled to {}x{} using nearest neighbour scaling",
size.width, size.height, scaledSize.width, scaledSize.height);
#endif
SDL_BlitScaled(converted.get(), nullptr, scaledSurface.get(), nullptr);
}
const Point hotpoint = GetHotpointPosition(*scaledSurface, hotpointPosition);
@ -98,13 +109,13 @@ bool SetHardwareCursor(SDL_Surface *surface, HotpointPosition hotpointPosition)
return true;
}
bool SetHardwareCursor(ClxSprite sprite, HotpointPosition hotpointPosition)
bool SetHardwareCursorFromClxSprite(ClxSprite sprite, HotpointPosition hotpointPosition)
{
OwnedSurface surface { sprite.width(), sprite.height() };
SDL_SetSurfacePalette(surface.surface, Palette.get());
SDL_SetColorKey(surface.surface, SDL_TRUE, 0);
RenderClxSprite(surface, sprite, { 0, 0 });
return SetHardwareCursor(surface.surface, hotpointPosition);
return SetHardwareCursorFromSurface(surface.surface, hotpointPosition);
}
bool SetHardwareCursorFromSprite(int pcurs)
@ -132,7 +143,8 @@ bool SetHardwareCursorFromSprite(int pcurs)
SDL_SetColorKey(out.surface, 1, TransparentColor);
DrawSoftwareCursor(out, { outlineWidth, size.height - outlineWidth }, pcurs);
const bool result = SetHardwareCursor(out.surface, isItem ? HotpointPosition::Center : HotpointPosition::TopLeft);
const bool result = SetHardwareCursorFromSurface(
out.surface, isItem ? HotpointPosition::Center : HotpointPosition::TopLeft);
return result;
}
#endif
@ -150,16 +162,25 @@ void SetHardwareCursor(CursorInfo cursorInfo)
CurrentCursorInfo = cursorInfo;
switch (cursorInfo.type()) {
case CursorType::Game:
#if LOG_HWCURSOR
Log("hwcursor: SetHardwareCursor Game");
#endif
CurrentCursorInfo.SetEnabled(SetHardwareCursorFromSprite(cursorInfo.id()));
break;
case CursorType::UserInterface:
#if LOG_HWCURSOR
Log("hwcursor: SetHardwareCursor UserInterface");
#endif
// ArtCursor is null while loading the game on the progress screen,
// called via palette fade from ShowProgress.
CurrentCursorInfo.SetEnabled(
ArtCursor && IsCursorSizeAllowed(Size { (*ArtCursor)[0].width(), (*ArtCursor)[0].height() })
&& SetHardwareCursor((*ArtCursor)[0], HotpointPosition::TopLeft));
&& SetHardwareCursorFromClxSprite((*ArtCursor)[0], HotpointPosition::TopLeft));
break;
case CursorType::Unknown:
#if LOG_HWCURSOR
Log("hwcursor: SetHardwareCursor Unknown");
#endif
CurrentCursorInfo.SetEnabled(false);
break;
}

18
Source/hwcursor.hpp

@ -11,6 +11,12 @@
#include "options.h"
// Set this to 1 to log the hardware cursor state changes.
#define LOG_HWCURSOR 0
#if LOG_HWCURSOR
#include "utils/log.hpp"
#endif
namespace devilution {
// Whether the hardware cursor is enabled in settings.
@ -29,6 +35,12 @@ inline bool IsHardwareCursorEnabled()
inline bool SetHardwareCursorVisible(bool visible)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
#if LOG_HWCURSOR
const bool isVisible = SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE;
if (isVisible != visible) {
Log("hwcursor: SetHardwareCursorVisible {}", visible);
}
#endif
return SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE) == 1;
#else
return false;
@ -77,6 +89,9 @@ public:
void SetEnabled(bool value)
{
#if LOG_HWCURSOR
Log("hwcursor: SetEnabled {}", value);
#endif
enabled_ = value;
}
@ -117,6 +132,9 @@ void SetHardwareCursor(CursorInfo cursorInfo);
inline void ReinitializeHardwareCursor()
{
#if LOG_HWCURSOR
Log("hwcursor: ReinitializeHardwareCursor");
#endif
SetHardwareCursor(GetCurrentCursorInfo());
}

Loading…
Cancel
Save