mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-13 19:49:36 +00:00
Fix display resolution desynchronizing with auto-position
This commit is contained in:
@@ -731,7 +731,7 @@ public:
|
||||
|
||||
void Run() override;
|
||||
void Shutdown() override;
|
||||
void GetDisplayResolution(unsigned int *width, unsigned int *height) override;
|
||||
void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) override;
|
||||
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) override;
|
||||
void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override;
|
||||
IGpCursor *CreateBWCursor(size_t width, size_t height, const void *pixelData, const void *maskData, size_t hotSpotX, size_t hotSpotY) override;
|
||||
@@ -886,6 +886,8 @@ private:
|
||||
uint32_t m_windowHeightPhysical;
|
||||
uint32_t m_windowWidthVirtual; // Virtual resolution is the resolution reported to the game
|
||||
uint32_t m_windowHeightVirtual;
|
||||
uint32_t m_initialWidthVirtual; // Virtual resolution is the resolution reported to the game
|
||||
uint32_t m_initialHeightVirtual;
|
||||
float m_pixelScaleX;
|
||||
float m_pixelScaleY;
|
||||
bool m_useUpscaleFilter;
|
||||
@@ -1178,6 +1180,8 @@ GpDisplayDriver_SDL_GL2::GpDisplayDriver_SDL_GL2(const GpDisplayDriverProperties
|
||||
, m_windowHeightPhysical(480)
|
||||
, m_windowWidthVirtual(640)
|
||||
, m_windowHeightVirtual(480)
|
||||
, m_initialWidthVirtual(640)
|
||||
, m_initialHeightVirtual(480)
|
||||
, m_pixelScaleX(1.0f)
|
||||
, m_pixelScaleY(1.0f)
|
||||
, m_useUpscaleFilter(false)
|
||||
@@ -1897,6 +1901,9 @@ void GpDisplayDriver_SDL_GL2::Run()
|
||||
if (!m_gl.LookUpFunctions())
|
||||
return;
|
||||
|
||||
m_initialWidthVirtual = m_windowWidthVirtual;
|
||||
m_initialHeightVirtual = m_windowHeightVirtual;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
SDL_Event msg;
|
||||
@@ -2052,13 +2059,13 @@ void GpDisplayDriver_SDL_GL2::Shutdown()
|
||||
free(this);
|
||||
}
|
||||
|
||||
void GpDisplayDriver_SDL_GL2::GetDisplayResolution(unsigned int *width, unsigned int *height)
|
||||
void GpDisplayDriver_SDL_GL2::GetInitialDisplayResolution(unsigned int *width, unsigned int *height)
|
||||
{
|
||||
if (width)
|
||||
*width = m_windowWidthVirtual;
|
||||
*width = m_initialWidthVirtual;
|
||||
|
||||
if (height)
|
||||
*height = m_windowHeightVirtual;
|
||||
*height = m_initialHeightVirtual;
|
||||
}
|
||||
|
||||
IGpDisplayDriverSurface *GpDisplayDriver_SDL_GL2::CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "MenuManager.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpSystemServices.h"
|
||||
#include "Vec2i.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
#include "PLDrivers.h"
|
||||
@@ -420,11 +421,9 @@ void HandleDepthSwitching (void)
|
||||
|
||||
void GetDeviceRect(Rect *rect)
|
||||
{
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&width, &height);
|
||||
PortabilityLayer::Vec2i displayResolution = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution();
|
||||
|
||||
SetRect(rect, 0, 0, static_cast<short>(width), static_cast<short>(height));
|
||||
SetRect(rect, 0, 0, static_cast<short>(displayResolution.m_x), static_cast<short>(displayResolution.m_y));
|
||||
}
|
||||
|
||||
Boolean AreWeColorOrGrayscale()
|
||||
|
||||
@@ -508,8 +508,7 @@ void MoveDialogToTopOfScreen(Dialog *dial)
|
||||
Window *window = dial->GetWindow();
|
||||
PortabilityLayer::Vec2i pos = window->GetPosition();
|
||||
|
||||
unsigned int height = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &height);
|
||||
unsigned int height = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
|
||||
pos.m_y = (height - window->GetDrawSurface()->m_port.GetRect().Height()) / 8;
|
||||
|
||||
|
||||
@@ -169,8 +169,7 @@ static void DrawMainMenuControl(DrawSurface *surface, MainMenuUIState::ControlID
|
||||
|
||||
void StartScrollForPage()
|
||||
{
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
|
||||
DismissMainMenuUI();
|
||||
|
||||
@@ -263,8 +262,7 @@ void StartMainMenuUI()
|
||||
|
||||
static void DismissMainMenuUIPage()
|
||||
{
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
|
||||
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
|
||||
|
||||
@@ -293,8 +291,7 @@ void TickMainMenuUI()
|
||||
{
|
||||
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
|
||||
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
|
||||
mainMenu.m_scrollInStep -= MainMenuUIState::kControlScrollInDecay;
|
||||
mainMenu.m_scrollInOffset -= (mainMenu.m_scrollInStep >> MainMenuUIState::kControlScrollInDecayFalloffBits);
|
||||
@@ -328,8 +325,7 @@ void HandleMainMenuUIResolutionChange()
|
||||
{
|
||||
PortabilityLayer::WindowManager *wm = PortabilityLayer::WindowManager::GetInstance();
|
||||
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
|
||||
for (int i = 0; i < MainMenuUIState::Control_Count; i++)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "CombinedTimestamp.h"
|
||||
#include "DeflateCodec.h"
|
||||
#include "Environ.h"
|
||||
#include "FontFamily.h"
|
||||
#include "GpBuildVersion.h"
|
||||
#include "GpIOStream.h"
|
||||
#include "GpFileCreationDisposition.h"
|
||||
@@ -12,10 +13,10 @@
|
||||
#include "GpApplicationName.h"
|
||||
#include "GpRenderedFontMetrics.h"
|
||||
#include "ResolveCachingColor.h"
|
||||
#include "ZipFile.h"
|
||||
#include "Vec2i.h"
|
||||
#include "WindowDef.h"
|
||||
#include "WindowManager.h"
|
||||
#include "FontFamily.h"
|
||||
#include "ZipFile.h"
|
||||
|
||||
#include "PLCore.h"
|
||||
#include "PLDrivers.h"
|
||||
@@ -140,9 +141,9 @@ static void InitSourceExportWindow(SourceExportState *state)
|
||||
|
||||
// We have to use this instead of thisMac.fullScreen because the resolution may change during the sleep call, especially on Android displays where
|
||||
// the status bar dismissal causes a major change in the virtual resolution.
|
||||
unsigned int displayWidth = 0;
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&displayWidth, &displayHeight);
|
||||
PortabilityLayer::Vec2i displaySize = PortabilityLayer::WindowManager::GetInstance()->GetDisplayResolution();
|
||||
unsigned int displayWidth = displaySize.m_x;
|
||||
unsigned int displayHeight = displaySize.m_y;
|
||||
|
||||
int32_t lsX = (static_cast<int32_t>(displayWidth) - kLoadScreenWidth) / 2;
|
||||
int32_t lsY = (static_cast<int32_t>(displayHeight) - kLoadScreenHeight) / 2;
|
||||
|
||||
@@ -31,7 +31,8 @@ struct IGpDisplayDriver
|
||||
virtual void Run() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual void GetDisplayResolution(unsigned int *width, unsigned int *height) = 0;
|
||||
// Returns the initial resolution before any display resolution events are posted
|
||||
virtual void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) = 0;
|
||||
|
||||
virtual IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) = 0;
|
||||
virtual void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) = 0;
|
||||
|
||||
@@ -1143,6 +1143,9 @@ void GpDisplayDriverD3D11::Run()
|
||||
LARGE_INTEGER lastTimestamp;
|
||||
memset(&lastTimestamp, 0, sizeof(lastTimestamp));
|
||||
|
||||
m_initialWidth = m_windowWidthVirtual;
|
||||
m_initialHeight = m_windowHeightVirtual;
|
||||
|
||||
MSG msg;
|
||||
for (;;)
|
||||
{
|
||||
@@ -1242,12 +1245,12 @@ void GpDisplayDriverD3D11::Shutdown()
|
||||
free(this);
|
||||
}
|
||||
|
||||
void GpDisplayDriverD3D11::GetDisplayResolution(unsigned int *width, unsigned int *height)
|
||||
void GpDisplayDriverD3D11::GetInitialDisplayResolution(unsigned int *width, unsigned int *height)
|
||||
{
|
||||
if (width)
|
||||
*width = m_windowWidthVirtual;
|
||||
*width = m_initialWidth;
|
||||
if (height)
|
||||
*height = m_windowHeightVirtual;
|
||||
*height = m_initialHeight;
|
||||
}
|
||||
|
||||
IGpDisplayDriverSurface *GpDisplayDriverD3D11::CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, IGpDisplayDriver::SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext)
|
||||
@@ -1516,6 +1519,8 @@ GpDisplayDriverD3D11::GpDisplayDriverD3D11(const GpDisplayDriverProperties &prop
|
||||
, m_windowHeightPhysical(480)
|
||||
, m_windowWidthVirtual(640)
|
||||
, m_windowHeightVirtual(480)
|
||||
, m_initialWidth(640)
|
||||
, m_initialHeight(480)
|
||||
, m_pixelScaleX(1.0f)
|
||||
, m_pixelScaleY(1.0f)
|
||||
, m_vosFiber(nullptr)
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
void Run() override;
|
||||
void Shutdown() override;
|
||||
|
||||
void GetDisplayResolution(unsigned int *width, unsigned int *height) override;
|
||||
void GetInitialDisplayResolution(unsigned int *width, unsigned int *height) override;
|
||||
|
||||
IGpDisplayDriverSurface *CreateSurface(size_t width, size_t height, size_t pitch, GpPixelFormat_t pixelFormat, IGpDisplayDriver::SurfaceInvalidateCallback_t invalidateCallback, void *invalidateContext) override;
|
||||
void DrawSurface(IGpDisplayDriverSurface *surface, int32_t x, int32_t y, size_t width, size_t height, const GpDisplayDriverSurfaceEffects *effects) override;
|
||||
@@ -178,6 +178,9 @@ private:
|
||||
float m_pixelScaleX;
|
||||
float m_pixelScaleY;
|
||||
|
||||
unsigned int m_initialWidth;
|
||||
unsigned int m_initialHeight;
|
||||
|
||||
IGpCursor_Win32 *m_activeCursor;
|
||||
IGpCursor_Win32 *m_pendingCursor;
|
||||
EGpStandardCursor_t m_currentStandardCursor;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "DialogManager.h"
|
||||
#include "IconLoader.h"
|
||||
#include "IGpDisplayDriver.h"
|
||||
#include "IGpLogDriver.h"
|
||||
#include "IGpSystemServices.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "QDPixMap.h"
|
||||
@@ -830,8 +831,11 @@ namespace PortabilityLayer
|
||||
|
||||
void DialogManagerImpl::PositionWindow(Window *window, const Rect &rect) const
|
||||
{
|
||||
unsigned int displayWidth, displayHeight;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&displayWidth, &displayHeight);
|
||||
IGpLogDriver *logger = PLDrivers::GetLogDriver();
|
||||
|
||||
Vec2i displayResolution = WindowManager::GetInstance()->GetDisplayResolution();
|
||||
unsigned int displayWidth = displayResolution.m_x;
|
||||
unsigned int displayHeight = displayResolution.m_y;
|
||||
|
||||
const unsigned int halfDisplayHeight = displayHeight / 2;
|
||||
const unsigned int quarterDisplayWidth = displayHeight / 4;
|
||||
@@ -840,6 +844,9 @@ namespace PortabilityLayer
|
||||
const uint16_t dialogWidth = rect.Width();
|
||||
const uint16_t dialogHeight = rect.Height();
|
||||
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Auto positioning window size %ix%i on display size %ix%i", static_cast<int>(dialogWidth), static_cast<int>(dialogHeight), static_cast<int>(displayWidth), static_cast<int>(displayHeight));
|
||||
|
||||
Vec2i newPosition;
|
||||
|
||||
newPosition.m_x = (static_cast<int32_t>(displayWidth) - static_cast<int32_t>(dialogWidth)) / 2;
|
||||
@@ -860,6 +867,9 @@ namespace PortabilityLayer
|
||||
else
|
||||
newPosition.m_y = (static_cast<int32_t>(displayHeight) - static_cast<int32_t>(dialogHeight)) / 2;
|
||||
|
||||
if (logger)
|
||||
logger->Printf(IGpLogDriver::Category_Information, "Positioned at %i,%i", static_cast<int>(newPosition.m_x), static_cast<int>(newPosition.m_y));
|
||||
|
||||
window->SetPosition(newPosition);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "RGBAColor.h"
|
||||
#include "ResolveCachingColor.h"
|
||||
#include "Vec2i.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
#include "PLBigEndian.h"
|
||||
#include "PLCore.h"
|
||||
@@ -840,8 +841,7 @@ namespace PortabilityLayer
|
||||
m_haveIcon = true;
|
||||
}
|
||||
|
||||
unsigned int width;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(&width, nullptr);
|
||||
unsigned int width = WindowManager::GetInstance()->GetDisplayResolution().m_x;
|
||||
|
||||
GpPixelFormat_t pixelFormat = DisplayDeviceManager::GetInstance()->GetPixelFormat();
|
||||
|
||||
@@ -1036,8 +1036,7 @@ namespace PortabilityLayer
|
||||
|
||||
if (m_isTouchScreen)
|
||||
{
|
||||
unsigned int displayHeight = 0;
|
||||
displayDriver->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
y = static_cast<int32_t>(displayHeight) - kTouchscreenMenuBarHeight;
|
||||
}
|
||||
|
||||
@@ -1307,8 +1306,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
if (m_isTouchScreen)
|
||||
{
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
return y >= (static_cast<int32_t>(displayHeight - kTouchscreenMenuBarHeight)) && y < static_cast<int32_t>(displayHeight);
|
||||
}
|
||||
else
|
||||
@@ -1388,8 +1386,7 @@ namespace PortabilityLayer
|
||||
{
|
||||
int32_t popupBottom = static_cast<int32_t>(m_popupPosition.m_y + menu->layoutFinalHeight);
|
||||
|
||||
unsigned int displayHeight = 0;
|
||||
PLDrivers::GetDisplayDriver()->GetDisplayResolution(nullptr, &displayHeight);
|
||||
unsigned int displayHeight = WindowManager::GetInstance()->GetDisplayResolution().m_y;
|
||||
if (popupBottom > static_cast<int32_t>(displayHeight))
|
||||
m_popupPosition.m_y -= popupBottom - static_cast<int32_t>(displayHeight);
|
||||
}
|
||||
|
||||
@@ -677,6 +677,7 @@ void PL_Init()
|
||||
PortabilityLayer::DisplayDeviceManager::GetInstance()->Init();
|
||||
PortabilityLayer::QDManager::GetInstance()->Init();
|
||||
PortabilityLayer::MenuManager::GetInstance()->Init();
|
||||
PortabilityLayer::WindowManager::GetInstance()->Init();
|
||||
|
||||
PLDrivers::GetFileSystem()->SetMainThreadRelay(PLMainThreadRelay::GetInstance());
|
||||
PLDrivers::GetFileSystem()->SetDelayCallback(PLSysCalls::Sleep);
|
||||
|
||||
@@ -171,6 +171,8 @@ namespace PortabilityLayer
|
||||
WindowManagerImpl();
|
||||
~WindowManagerImpl();
|
||||
|
||||
void Init() override;
|
||||
|
||||
Window *CreateWindow(const WindowDef &windowDef) override;
|
||||
void ResizeWindow(Window *window, int width, int height) override;
|
||||
void MoveWindow(Window *window, int x, int y) override;
|
||||
@@ -198,6 +200,8 @@ namespace PortabilityLayer
|
||||
|
||||
void HandleScreenResolutionChange(uint32_t prevWidth, uint32_t prevHeight, uint32_t newWidth, uint32_t newHeight) override;
|
||||
|
||||
Vec2i GetDisplayResolution() const override;
|
||||
|
||||
void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
|
||||
Window *GetPutInFrontSentinel() const override;
|
||||
@@ -229,6 +233,8 @@ namespace PortabilityLayer
|
||||
DrawSurface m_resizeInProgressVerticalBar;
|
||||
bool m_isResizeInProgress;
|
||||
|
||||
Vec2i m_displayResolution;
|
||||
|
||||
static WindowManagerImpl ms_instance;
|
||||
|
||||
static uint8_t ms_putInFrontSentinel;
|
||||
@@ -1011,8 +1017,6 @@ namespace PortabilityLayer
|
||||
return m_effects;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WindowManagerImpl::WindowManagerImpl()
|
||||
: m_windowStackTop(nullptr)
|
||||
, m_windowStackBottom(nullptr)
|
||||
@@ -1025,6 +1029,7 @@ namespace PortabilityLayer
|
||||
, m_flickerZoneSize(0)
|
||||
, m_flickerBasisCoordinateDistance(0)
|
||||
, m_flickerChromeDistanceOffset(0)
|
||||
, m_displayResolution(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1032,6 +1037,14 @@ namespace PortabilityLayer
|
||||
{
|
||||
}
|
||||
|
||||
void WindowManagerImpl::Init()
|
||||
{
|
||||
unsigned int displayWidth, displayHeight;
|
||||
PLDrivers::GetDisplayDriver()->GetInitialDisplayResolution(&displayWidth, &displayHeight);
|
||||
|
||||
m_displayResolution = Vec2i(displayWidth, displayHeight);
|
||||
}
|
||||
|
||||
Window *WindowManagerImpl::CreateWindow(const WindowDef &windowDef)
|
||||
{
|
||||
void *windowMem = MemoryManager::GetInstance()->Alloc(sizeof(WindowImpl));
|
||||
@@ -1528,6 +1541,11 @@ namespace PortabilityLayer
|
||||
}
|
||||
}
|
||||
|
||||
Vec2i WindowManagerImpl::GetDisplayResolution() const
|
||||
{
|
||||
return m_displayResolution;
|
||||
}
|
||||
|
||||
void WindowManagerImpl::SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
PLDrivers::GetDisplayDriver()->SetBackgroundColor(r, g, b, 255);
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace PortabilityLayer
|
||||
class WindowManager
|
||||
{
|
||||
public:
|
||||
virtual void Init() = 0;
|
||||
virtual Window *GetPutInFrontSentinel() const = 0;
|
||||
virtual Window *CreateWindow(const WindowDef &windowDef) = 0;
|
||||
virtual void ResizeWindow(Window *window, int width, int height) = 0;
|
||||
@@ -52,6 +53,8 @@ namespace PortabilityLayer
|
||||
|
||||
virtual void SetBackgroundColor(uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
|
||||
virtual Vec2i GetDisplayResolution() const = 0;
|
||||
|
||||
static WindowManager *GetInstance();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user