diff options
author | Cameron Cawley | 2019-11-01 11:39:46 +0000 |
---|---|---|
committer | Antoniou Athanasios | 2019-11-01 13:39:46 +0200 |
commit | 177d709909808313eee720ce76465cf99f909c5e (patch) | |
tree | 6d11f166342ddea46deb1634b106d010b4ab5181 /backends/graphics | |
parent | 5d0206b9c297837fddb038601bdfb42b0fcb8016 (diff) | |
download | scummvm-rg350-177d709909808313eee720ce76465cf99f909c5e.tar.gz scummvm-rg350-177d709909808313eee720ce76465cf99f909c5e.tar.bz2 scummvm-rg350-177d709909808313eee720ce76465cf99f909c5e.zip |
OPENGL: Implement high DPI support on Android (#1895)
* OPENGL: Implement high DPI support on Android
* PSP2: Fix build
Diffstat (limited to 'backends/graphics')
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.cpp | 18 | ||||
-rw-r--r-- | backends/graphics/opengl/opengl-graphics.h | 2 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.cpp | 14 | ||||
-rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.h | 2 | ||||
-rw-r--r-- | backends/graphics/psp2sdl/psp2sdl-graphics.cpp | 2 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.cpp | 2 | ||||
-rw-r--r-- | backends/graphics/sdl/sdl-graphics.h | 2 | ||||
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 11 | ||||
-rw-r--r-- | backends/graphics/surfacesdl/surfacesdl-graphics.h | 2 | ||||
-rw-r--r-- | backends/graphics/windowed.h | 15 |
10 files changed, 48 insertions, 22 deletions
diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 06a0109476..9d11925613 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -909,7 +909,7 @@ void OpenGLGraphicsManager::grabPalette(byte *colors, uint start, uint num) cons memcpy(colors, _gamePalette + start * 3, num * 3); } -void OpenGLGraphicsManager::handleResizeImpl(const int width, const int height) { +void OpenGLGraphicsManager::handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) { // Setup backbuffer size. _backBuffer.setDimensions(width, height); @@ -942,6 +942,10 @@ void OpenGLGraphicsManager::handleResizeImpl(const int width, const int height) overlayWidth = MAX<uint>(overlayWidth, 256); overlayHeight = MAX<uint>(overlayHeight, 200); + // HACK: Reduce the size of the overlay on high DPI screens. + overlayWidth = fracToInt(overlayWidth * (intToFrac(90) / xdpi)); + overlayHeight = fracToInt(overlayHeight * (intToFrac(90) / ydpi)); + if (!_overlay || _overlay->getFormat() != _defaultFormatAlpha) { delete _overlay; _overlay = nullptr; @@ -1008,7 +1012,7 @@ void OpenGLGraphicsManager::notifyContextCreate(const Graphics::PixelFormat &def // Refresh the output screen dimensions if some are set up. if (_windowWidth != 0 && _windowHeight != 0) { - handleResize(_windowWidth, _windowHeight); + handleResize(_windowWidth, _windowHeight, _xdpi, _ydpi); } // TODO: Should we try to convert textures into one of those formats if @@ -1275,6 +1279,16 @@ void OpenGLGraphicsManager::recalculateCursorScaling() { _cursorHotspotYScaled = fracToInt(_cursorHotspotYScaled * screenScaleFactorY); _cursorHeightScaled = fracToInt(_cursorHeightScaled * screenScaleFactorY); + } else { + const frac_t screenScaleFactorX = intToFrac(90) / _xdpi; + const frac_t screenScaleFactorY = intToFrac(90) / _ydpi; + + // FIXME: Replace this with integer maths + _cursorHotspotXScaled /= fracToDouble(screenScaleFactorX); + _cursorWidthScaled /= fracToDouble(screenScaleFactorX); + + _cursorHotspotYScaled /= fracToDouble(screenScaleFactorY); + _cursorHeightScaled /= fracToDouble(screenScaleFactorY); } } diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index f88315bf30..322f1d8017 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -309,7 +309,7 @@ protected: virtual bool gameNeedsAspectRatioCorrection() const override; virtual void recalculateDisplayAreas() override; - virtual void handleResizeImpl(const int width, const int height) override; + virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) override; /** * The default pixel format of the backend. diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index 2d2a1bac7b..d959e021e6 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -305,7 +305,8 @@ void OpenGLSdlGraphicsManager::notifyResize(const int width, const int height) { getWindowSizeFromSdl(¤tWidth, ¤tHeight); if (width != currentWidth || height != currentHeight) return; - handleResize(width, height); + // TODO: Implement high DPI support + handleResize(width, height, 90, 90); #else if (!_ignoreResizeEvents && _hwScreen && !(_hwScreen->flags & SDL_FULLSCREEN)) { // We save that we handled a resize event here. We need to know this @@ -357,9 +358,9 @@ void *OpenGLSdlGraphicsManager::getProcAddress(const char *name) const { return SDL_GL_GetProcAddress(name); } -void OpenGLSdlGraphicsManager::handleResizeImpl(const int width, const int height) { - OpenGLGraphicsManager::handleResizeImpl(width, height); - SdlGraphicsManager::handleResizeImpl(width, height); +void OpenGLSdlGraphicsManager::handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) { + OpenGLGraphicsManager::handleResizeImpl(width, height, xdpi, ydpi); + SdlGraphicsManager::handleResizeImpl(width, height, xdpi, ydpi); } bool OpenGLSdlGraphicsManager::saveScreenshot(const Common::String &filename) const { @@ -463,7 +464,8 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { notifyContextCreate(rgba8888, rgba8888); int actualWidth, actualHeight; getWindowSizeFromSdl(&actualWidth, &actualHeight); - handleResize(actualWidth, actualHeight); + // TODO: Implement high DPI support + handleResize(actualWidth, actualHeight, 90, 90); return true; #else // WORKAROUND: Working around infamous SDL bugs when switching @@ -510,7 +512,7 @@ bool OpenGLSdlGraphicsManager::setupMode(uint width, uint height) { if (_hwScreen) { notifyContextCreate(rgba8888, rgba8888); - handleResize(_hwScreen->w, _hwScreen->h); + handleResize(_hwScreen->w, _hwScreen->h, 90, 90); } // Ignore resize events (from SDL) for a few frames, if this isn't diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h index 2729a529fd..929adc9292 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.h +++ b/backends/graphics/openglsdl/openglsdl-graphics.h @@ -60,7 +60,7 @@ protected: virtual void *getProcAddress(const char *name) const override; - virtual void handleResizeImpl(const int width, const int height) override; + virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) override; virtual bool saveScreenshot(const Common::String &filename) const override; diff --git a/backends/graphics/psp2sdl/psp2sdl-graphics.cpp b/backends/graphics/psp2sdl/psp2sdl-graphics.cpp index f6333e2124..2d26727ca6 100644 --- a/backends/graphics/psp2sdl/psp2sdl-graphics.cpp +++ b/backends/graphics/psp2sdl/psp2sdl-graphics.cpp @@ -94,7 +94,7 @@ PSP2SdlGraphicsManager::PSP2SdlGraphicsManager(SdlEventSource *sdlEventSource, S _shaders[0] = NULL; /* Vita display size is always 960x544 (that's just the hardware) */ - handleResize(960, 544); + handleResize(960, 544, 90, 90); } PSP2SdlGraphicsManager::~PSP2SdlGraphicsManager() { diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index 453c60c66f..0d310a4174 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -230,7 +230,7 @@ void SdlGraphicsManager::setSystemMousePosition(const int x, const int y) { } } -void SdlGraphicsManager::handleResizeImpl(const int width, const int height) { +void SdlGraphicsManager::handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) { _eventSource->resetKeyboardEmulation(width - 1, height - 1); _forceRedraw = true; } diff --git a/backends/graphics/sdl/sdl-graphics.h b/backends/graphics/sdl/sdl-graphics.h index 77c8d5d528..d67557be2b 100644 --- a/backends/graphics/sdl/sdl-graphics.h +++ b/backends/graphics/sdl/sdl-graphics.h @@ -163,7 +163,7 @@ protected: virtual void setSystemMousePosition(const int x, const int y) override; - virtual void handleResizeImpl(const int width, const int height) override; + virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) override; #if SDL_VERSION_ATLEAST(2, 0, 0) public: diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 052ae37b9a..3b2e3eaf6f 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -1021,7 +1021,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() { } #if !SDL_VERSION_ATLEAST(2, 0, 0) - handleResize(_videoMode.hardwareWidth, _videoMode.hardwareHeight); + handleResize(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 90, 90); #endif // @@ -2507,8 +2507,8 @@ void SurfaceSdlGraphicsManager::drawOSD() { #endif -void SurfaceSdlGraphicsManager::handleResizeImpl(const int width, const int height) { - SdlGraphicsManager::handleResizeImpl(width, height); +void SurfaceSdlGraphicsManager::handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) { + SdlGraphicsManager::handleResizeImpl(width, height, xdpi, ydpi); recalculateDisplayAreas(); } @@ -2715,7 +2715,7 @@ void SurfaceSdlGraphicsManager::notifyVideoExpose() { void SurfaceSdlGraphicsManager::notifyResize(const int width, const int height) { #if SDL_VERSION_ATLEAST(2, 0, 0) - handleResize(width, height); + handleResize(width, height, _xdpi, _ydpi); #endif } @@ -2762,8 +2762,9 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, return nullptr; } + // TODO: Implement high DPI support getWindowSizeFromSdl(&_windowWidth, &_windowHeight); - handleResize(_windowWidth, _windowHeight); + handleResize(_windowWidth, _windowHeight, 90, 90); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, _videoMode.filtering ? "linear" : "nearest"); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index f5edd160f9..a51aa22e9b 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -185,7 +185,7 @@ protected: return _videoMode.scaleFactor; } - virtual void handleResizeImpl(const int width, const int height) override; + virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) override; virtual int getGraphicsModeScale(int mode) const override; virtual ScalerProc *getGraphicsScalerProc(int mode) const; diff --git a/backends/graphics/windowed.h b/backends/graphics/windowed.h index 74933a1727..549739d987 100644 --- a/backends/graphics/windowed.h +++ b/backends/graphics/windowed.h @@ -49,6 +49,8 @@ public: _cursorVisible(false), _cursorX(0), _cursorY(0), + _xdpi(90), + _ydpi(90), _cursorNeedsRedraw(false), _cursorLastInActiveArea(true) {} @@ -93,7 +95,7 @@ protected: * Backend-specific implementation for updating internal surfaces that need * to reflect the new window size. */ - virtual void handleResizeImpl(const int width, const int height) = 0; + virtual void handleResizeImpl(const int width, const int height, const int xdpi, const int ydpi) = 0; /** * Converts the given point from the active virtual screen's coordinate @@ -172,10 +174,12 @@ protected: * @param width The new width of the window, excluding window decoration. * @param height The new height of the window, excluding window decoration. */ - void handleResize(const int width, const int height) { + void handleResize(const int width, const int height, const int xdpi, const int ydpi) { _windowWidth = width; _windowHeight = height; - handleResizeImpl(width, height); + _xdpi = xdpi; + _ydpi = ydpi; + handleResizeImpl(width, height, xdpi, ydpi); } /** @@ -276,6 +280,11 @@ protected: int _windowHeight; /** + * The DPI of the window. + */ + int _xdpi, _ydpi; + + /** * Whether the overlay (i.e. launcher, including the out-of-game launcher) * is visible or not. */ |