diff --git a/backends/graphics/gph/gph-graphics.cpp b/backends/graphics/gph/gph-graphics.cpp index 8c13b4211d34..90c9c92bdc6a 100644 --- a/backends/graphics/gph/gph-graphics.cpp +++ b/backends/graphics/gph/gph-graphics.cpp @@ -29,7 +29,7 @@ GPHGraphicsManager::GPHGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow : SurfaceSdlGraphicsManager(sdlEventSource, window) { } -void GPHGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) { +void GPHGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat &format) { SurfaceSdlGraphicsManager::initSize(w, h, format); _videoMode.overlayWidth = 320; diff --git a/backends/graphics/gph/gph-graphics.h b/backends/graphics/gph/gph-graphics.h index 3b6c94fc5a82..e3e0be3a0544 100644 --- a/backends/graphics/gph/gph-graphics.h +++ b/backends/graphics/gph/gph-graphics.h @@ -28,7 +28,7 @@ class GPHGraphicsManager : public SurfaceSdlGraphicsManager { public: GPHGraphicsManager(SdlEventSource *boss, SdlWindow *window); - void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL) override; + void initSize(uint w, uint h, const Graphics::PixelFormat &format) override; bool loadGFXMode() override; protected: diff --git a/backends/graphics/graphics.h b/backends/graphics/graphics.h index fffcd0f11a52..5d8667c1e0ee 100644 --- a/backends/graphics/graphics.h +++ b/backends/graphics/graphics.h @@ -72,7 +72,7 @@ class GraphicsManager : public PaletteManager { virtual Graphics::PixelFormat getScreenFormat() const = 0; virtual Common::List getSupportedFormats() const = 0; #endif - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) = 0; + virtual void initSize(uint width, uint height, const Graphics::PixelFormat &format) = 0; virtual void initSizeHint(const Graphics::ModeList &modes) {} virtual int getScreenChangeID() const = 0; @@ -105,7 +105,7 @@ class GraphicsManager : public PaletteManager { virtual bool showMouse(bool visible) = 0; virtual void warpMouse(int x, int y) = 0; - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) = 0; + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) = 0; virtual void setCursorPalette(const byte *colors, uint start, uint num) = 0; virtual void displayMessageOnOSD(const Common::U32String &msg) {} diff --git a/backends/graphics/null/null-graphics.h b/backends/graphics/null/null-graphics.h index 1fcdeec066a4..8477c09570fb 100644 --- a/backends/graphics/null/null-graphics.h +++ b/backends/graphics/null/null-graphics.h @@ -47,10 +47,10 @@ class NullGraphicsManager : public GraphicsManager { return list; } - void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) override { + void initSize(uint width, uint height, const Graphics::PixelFormat &format) override { _width = width; _height = height; - _format = format ? *format : Graphics::PixelFormat::createFormatCLUT8(); + _format = format; } int getScreenChangeID() const override { return 0; } @@ -83,7 +83,7 @@ class NullGraphicsManager : public GraphicsManager { bool showMouse(bool visible) override { return !visible; } void warpMouse(int x, int y) override {} - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override {} + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) override {} void setCursorPalette(const byte *colors, uint start, uint num) override {} private: diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index 1e8aae836556..1157b02497fc 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -500,15 +500,9 @@ int OpenGLGraphicsManager::getScreenChangeID() const { return _screenChangeID; } -void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::PixelFormat *format) { - Graphics::PixelFormat requestedFormat; +void OpenGLGraphicsManager::initSize(uint width, uint height, const Graphics::PixelFormat &format) { #ifdef USE_RGB_COLOR - if (!format) { - requestedFormat = Graphics::PixelFormat::createFormatCLUT8(); - } else { - requestedFormat = *format; - } - _currentState.gameFormat = requestedFormat; + _currentState.gameFormat = format; #endif _currentState.gameWidth = width; @@ -756,7 +750,7 @@ void multiplyColorWithAlpha(const byte *src, byte *dst, const uint w, const uint } } // End of anonymous namespace -void OpenGLGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void OpenGLGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { _cursorKeyColor = keycolor; _cursorHotspotX = hotspotX; @@ -769,16 +763,7 @@ void OpenGLGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int return; } - Graphics::PixelFormat inputFormat; -#ifdef USE_RGB_COLOR - if (format) { - inputFormat = *format; - } else { - inputFormat = Graphics::PixelFormat::createFormatCLUT8(); - } -#else - inputFormat = Graphics::PixelFormat::createFormatCLUT8(); -#endif + Graphics::PixelFormat inputFormat = format; // In case the color format has changed we will need to create the texture. if (!_cursor || _cursor->getFormat() != inputFormat) { diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 5ff7ebbbaaa8..4eadfe8f233a 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -91,7 +91,7 @@ class OpenGLGraphicsManager : virtual public WindowedGraphicsManager { int getScreenChangeID() const override; - void initSize(uint width, uint height, const Graphics::PixelFormat *format) override; + void initSize(uint width, uint height, const Graphics::PixelFormat &format) override; int16 getWidth() const override; int16 getHeight() const override; @@ -116,7 +116,7 @@ class OpenGLGraphicsManager : virtual public WindowedGraphicsManager { void clearOverlay() override; void grabOverlay(Graphics::Surface &surface) const override; - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) override; + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) override; void setCursorPalette(const byte *colors, uint start, uint num) override; void displayMessageOnOSD(const Common::U32String &msg) override; diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp index 3dc643d388dc..82495c2d2306 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.cpp +++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp @@ -257,7 +257,7 @@ float OpenGLSdlGraphicsManager::getHiDPIScreenFactor() const { return _window->getDpiScalingFactor(); } -void OpenGLSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) { +void OpenGLSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat &format) { // HACK: This is stupid but the SurfaceSDL backend defaults to 2x. This // assures that the launcher (which requests 320x200) has a reasonable // size. It also makes small games have a reasonable size (i.e. at least diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h index d12ad4719092..963962b5d6a4 100644 --- a/backends/graphics/openglsdl/openglsdl-graphics.h +++ b/backends/graphics/openglsdl/openglsdl-graphics.h @@ -38,7 +38,7 @@ class OpenGLSdlGraphicsManager : public OpenGL::OpenGLGraphicsManager, public Sd void setFeatureState(OSystem::Feature f, bool enable) override; bool getFeatureState(OSystem::Feature f) const override; - void initSize(uint w, uint h, const Graphics::PixelFormat *format) override; + void initSize(uint w, uint h, const Graphics::PixelFormat &format) override; void updateScreen() override; float getHiDPIScreenFactor() const override; diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp index ec8ea78dbb19..bea208d15204 100644 --- a/backends/graphics/sdl/sdl-graphics.cpp +++ b/backends/graphics/sdl/sdl-graphics.cpp @@ -86,9 +86,9 @@ bool SdlGraphicsManager::setState(const State &state) { Common::List supportedFormats = getSupportedFormats(); if (!supportedFormats.empty() && Common::find(supportedFormats.begin(), supportedFormats.end(), format) == supportedFormats.end()) format = supportedFormats.front(); - initSize(state.screenWidth, state.screenHeight, &format); + initSize(state.screenWidth, state.screenHeight, format); #else - initSize(state.screenWidth, state.screenHeight, nullptr); + initSize(state.screenWidth, state.screenHeight, Graphics::PixelFormat::createFormatCLUT8()); #endif setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio); setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 119b83e29e51..3dd3b915caf4 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -692,7 +692,7 @@ int SurfaceSdlGraphicsManager::getStretchMode() const { } #endif -void SurfaceSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) { +void SurfaceSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat &format) { assert(_transactionMode == kTransactionActive); _gameScreenShakeXOffset = 0; @@ -700,11 +700,7 @@ void SurfaceSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFo #ifdef USE_RGB_COLOR //avoid redundant format changes - Graphics::PixelFormat newFormat; - if (!format) - newFormat = Graphics::PixelFormat::createFormatCLUT8(); - else - newFormat = *format; + Graphics::PixelFormat newFormat = format; assert(newFormat.bytesPerPixel > 0); @@ -1791,23 +1787,16 @@ void SurfaceSdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, in #pragma mark --- Mouse --- #pragma mark - -void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keyColor, bool dontScale, const Graphics::PixelFormat *format) { +void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keyColor, bool dontScale, const Graphics::PixelFormat &format) { bool formatChanged = false; - if (format) { #ifndef USE_RGB_COLOR - assert(format->bytesPerPixel == 1); + assert(format.bytesPerPixel == 1); #endif - if (format->bytesPerPixel != _cursorFormat.bytesPerPixel) { - formatChanged = true; - } - _cursorFormat = *format; - } else { - if (_cursorFormat.bytesPerPixel != 1) { - formatChanged = true; - } - _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); + if (format.bytesPerPixel != _cursorFormat.bytesPerPixel) { + formatChanged = true; } + _cursorFormat = format; if (_cursorFormat.bytesPerPixel < 4) { assert(keyColor < 1U << (_cursorFormat.bytesPerPixel * 8)); @@ -1847,11 +1836,11 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, assert(!_mouseSurface); assert(!_mouseOrigSurface); - const Uint32 rMask = ((0xFF >> format->rLoss) << format->rShift); - const Uint32 gMask = ((0xFF >> format->gLoss) << format->gShift); - const Uint32 bMask = ((0xFF >> format->bLoss) << format->bShift); - const Uint32 aMask = ((0xFF >> format->aLoss) << format->aShift); - _mouseSurface = _mouseOrigSurface = SDL_CreateRGBSurfaceFrom(const_cast(buf), w, h, format->bytesPerPixel * 8, w * format->bytesPerPixel, rMask, gMask, bMask, aMask); + const Uint32 rMask = ((0xFF >> format.rLoss) << format.rShift); + const Uint32 gMask = ((0xFF >> format.gLoss) << format.gShift); + const Uint32 bMask = ((0xFF >> format.bLoss) << format.bShift); + const Uint32 aMask = ((0xFF >> format.aLoss) << format.aShift); + _mouseSurface = _mouseOrigSurface = SDL_CreateRGBSurfaceFrom(const_cast(buf), w, h, format.bytesPerPixel * 8, w * format.bytesPerPixel, rMask, gMask, bMask, aMask); } else { assert(!_mouseOrigSurface); diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h index ec39a7da306a..c6075a4a8ace 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.h +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h @@ -87,7 +87,7 @@ class SurfaceSdlGraphicsManager : public SdlGraphicsManager { bool setStretchMode(int mode) override; int getStretchMode() const override; #endif - void initSize(uint w, uint h, const Graphics::PixelFormat *format = NULL) override; + void initSize(uint w, uint h, const Graphics::PixelFormat &format) override; int getScreenChangeID() const override { return _screenChangeCount; } void beginGFXTransaction() override; @@ -123,7 +123,7 @@ class SurfaceSdlGraphicsManager : public SdlGraphicsManager { int16 getOverlayHeight() const override { return _videoMode.overlayHeight; } int16 getOverlayWidth() const override { return _videoMode.overlayWidth; } - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override; + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) override; void setCursorPalette(const byte *colors, uint start, uint num) override; #ifdef USE_OSD diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp index ea78e61b755f..87e1ac476ae1 100644 --- a/backends/graphics3d/android/android-graphics3d.cpp +++ b/backends/graphics3d/android/android-graphics3d.cpp @@ -600,12 +600,9 @@ void AndroidGraphics3dManager::copyRectToScreen(const void *buf, int pitch, } void AndroidGraphics3dManager::initSize(uint width, uint height, - const Graphics::PixelFormat *format) { + const Graphics::PixelFormat &format) { // resize game texture - ENTER("%d, %d, %p", width, height, format); - - // We do only 3D with this manager and in 3D there is no format - assert(format == nullptr); + ENTER("%d, %d, %s", width, height, format.toString().c_str()); bool engineSupportsArbitraryResolutions = !g_engine || g_engine->hasFeature(Engine::kSupportsArbitraryResolutions); @@ -692,14 +689,14 @@ void AndroidGraphics3dManager::updateCursorScaling() { void AndroidGraphics3dManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, - const Graphics::PixelFormat *format) { - ENTER("%p, %u, %u, %d, %d, %u, %d, %p", buf, w, h, hotspotX, hotspotY, - keycolor, dontScale, format); + const Graphics::PixelFormat &format) { + ENTER("%p, %u, %u, %d, %d, %u, %d, %s", buf, w, h, hotspotX, hotspotY, + keycolor, dontScale, format.toString().c_str()); GLTHREADCHECK; #ifdef USE_RGB_COLOR - if (format && format->bytesPerPixel > 1) { + if (format.bytesPerPixel > 1) { if (_mouse_texture != _mouse_texture_rgb) { LOGD("switching to rgb mouse cursor"); @@ -745,9 +742,9 @@ void AndroidGraphics3dManager::setMouseCursor(const void *buf, uint w, uint h, byte *tmp = new byte[pitch * h]; // meh, a n-bit cursor without alpha bits... this is so silly - if (!crossBlit(tmp, (const byte *)buf, pitch, w * format->bytesPerPixel, w, h, + if (!crossBlit(tmp, (const byte *)buf, pitch, w * format.bytesPerPixel, w, h, _mouse_texture->getPixelFormat(), - *format)) { + format)) { LOGE("crossblit failed"); delete[] tmp; @@ -757,7 +754,7 @@ void AndroidGraphics3dManager::setMouseCursor(const void *buf, uint w, uint h, return; } - if (format->bytesPerPixel == 2) { + if (format.bytesPerPixel == 2) { const uint16 *s = (const uint16 *)buf; byte *d = tmp; for (uint16 y = 0; y < h; ++y, d += pitch / 2 - w) @@ -765,7 +762,7 @@ void AndroidGraphics3dManager::setMouseCursor(const void *buf, uint w, uint h, if (*s++ == (keycolor & 0xffff)) { memset(d, 0, bpp); } - } else if (format->bytesPerPixel == 4) { + } else if (format.bytesPerPixel == 4) { const uint32 *s = (const uint32 *)buf; byte *d = tmp; for (uint16 y = 0; y < h; ++y, d += pitch / 2 - w) @@ -774,7 +771,7 @@ void AndroidGraphics3dManager::setMouseCursor(const void *buf, uint w, uint h, memset(d, 0, bpp); } } else { - error("AndroidGraphics3dManager::setMouseCursor: invalid bytesPerPixel %d", format->bytesPerPixel); + error("AndroidGraphics3dManager::setMouseCursor: invalid bytesPerPixel %d", format.bytesPerPixel); } _mouse_texture->updateBuffer(0, 0, w, h, tmp, pitch); diff --git a/backends/graphics3d/android/android-graphics3d.h b/backends/graphics3d/android/android-graphics3d.h index 0e1d3b942f14..a882bf15241d 100644 --- a/backends/graphics3d/android/android-graphics3d.h +++ b/backends/graphics3d/android/android-graphics3d.h @@ -100,7 +100,7 @@ class AndroidGraphics3dManager : virtual void clearFocusRectangle() {} virtual void initSize(uint width, uint height, - const Graphics::PixelFormat *format) override; + const Graphics::PixelFormat &format) override; virtual int getScreenChangeID() const override; virtual bool showMouse(bool visible) override; @@ -109,7 +109,7 @@ class AndroidGraphics3dManager : virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, - const Graphics::PixelFormat *format) override; + const Graphics::PixelFormat &format) override; virtual void setCursorPalette(const byte *colors, uint start, uint num) override; float getHiDPIScreenFactor() const override; diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp index fa827e0d709d..9a9f29d51ba2 100644 --- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp +++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp @@ -230,7 +230,7 @@ int OpenGLSdlGraphics3dManager::getGraphicsMode() const { return 0; } -void OpenGLSdlGraphics3dManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) { +void OpenGLSdlGraphics3dManager::initSize(uint w, uint h, const Graphics::PixelFormat &format) { _engineRequestedWidth = w; _engineRequestedHeight = h; if (_transactionMode == kTransactionNone) diff --git a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h index 35a7a79204d8..ad1711c65fd5 100644 --- a/backends/graphics3d/openglsdl/openglsdl-graphics3d.h +++ b/backends/graphics3d/openglsdl/openglsdl-graphics3d.h @@ -69,7 +69,7 @@ class OpenGLSdlGraphics3dManager : public SdlGraphicsManager { } #endif int getScreenChangeID() const override { return _screenChangeCount; } - void initSize(uint w, uint h, const Graphics::PixelFormat *format) override; + void initSize(uint w, uint h, const Graphics::PixelFormat &format) override; int16 getHeight() const override; int16 getWidth() const override; @@ -100,7 +100,7 @@ class OpenGLSdlGraphics3dManager : public SdlGraphicsManager { // GraphicsManager API - Mouse bool showMouse(bool visible) override; void warpMouse(int x, int y) override; - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override {} + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) override {} void setCursorPalette(const byte *colors, uint start, uint num) override {} // SdlGraphicsManager API diff --git a/backends/modular-backend.cpp b/backends/modular-backend.cpp index f2dcf7067529..1550a5e666ff 100644 --- a/backends/modular-backend.cpp +++ b/backends/modular-backend.cpp @@ -137,7 +137,7 @@ Common::List ModularGraphicsBackend::getSupportedFormats( #endif -void ModularGraphicsBackend::initSize(uint w, uint h, const Graphics::PixelFormat *format) { +void ModularGraphicsBackend::initSize(uint w, uint h, const Graphics::PixelFormat &format) { _graphicsManager->initSize(w, h, format); } @@ -272,7 +272,7 @@ void ModularGraphicsBackend::warpMouse(int x, int y) { _graphicsManager->warpMouse(x, y); } -void ModularGraphicsBackend::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void ModularGraphicsBackend::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { _graphicsManager->setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format); } diff --git a/backends/modular-backend.h b/backends/modular-backend.h index 40b9a06c37c7..611c11b14e4f 100644 --- a/backends/modular-backend.h +++ b/backends/modular-backend.h @@ -85,7 +85,7 @@ class ModularGraphicsBackend : virtual public BaseBackend { Graphics::PixelFormat getScreenFormat() const override final; Common::List getSupportedFormats() const override final; #endif - void initSize(uint width, uint height, const Graphics::PixelFormat *format = NULL) override final; + void initSize(uint width, uint height, const Graphics::PixelFormat &format) override final; void initSizeHint(const Graphics::ModeList &modes) override final; int getScreenChangeID() const override final; @@ -118,7 +118,7 @@ class ModularGraphicsBackend : virtual public BaseBackend { bool showMouse(bool visible) override final; void warpMouse(int x, int y) override final; - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override final; + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) override final; void setCursorPalette(const byte *colors, uint start, uint num) override final; bool lockMouse(bool lock) override final; diff --git a/backends/platform/3ds/osystem-graphics.cpp b/backends/platform/3ds/osystem-graphics.cpp index a023f7b2c60f..413325d325cc 100644 --- a/backends/platform/3ds/osystem-graphics.cpp +++ b/backends/platform/3ds/osystem-graphics.cpp @@ -158,13 +158,13 @@ bool OSystem_3DS::getFeatureState(OSystem::Feature f) { } } -GraphicsModeID OSystem_3DS::chooseMode(Graphics::PixelFormat *format) { - if (format->bytesPerPixel > 2) { +GraphicsModeID OSystem_3DS::chooseMode(const Graphics::PixelFormat &format) { + if (format.bytesPerPixel > 2) { return RGBA8; - } else if (format->bytesPerPixel > 1) { - if (format->gBits() > 5) { + } else if (format.bytesPerPixel > 1) { + if (format.gBits() > 5) { return RGB565; - } else if (format->aBits() == 0) { + } else if (format.aBits() == 0) { return RGB555; } else { return RGB5A1; @@ -188,8 +188,8 @@ bool OSystem_3DS::setGraphicsMode(GraphicsModeID modeID) { } void OSystem_3DS::initSize(uint width, uint height, - const Graphics::PixelFormat *format) { - debug("3ds initsize w:%d h:%d", width, height); + const Graphics::PixelFormat &format) { + debug("3ds initsize w:%d h:%d f:%s", width, height, format.toString().c_str()); int oldScreen = config.screen; loadConfig(); if (config.screen != oldScreen) { @@ -202,19 +202,14 @@ void OSystem_3DS::initSize(uint width, uint height, _magCenterY = _magHeight / 2; _oldPfGame = _pfGame; - if (!format) { - _pfGame = Graphics::PixelFormat::createFormatCLUT8(); - } else { - debug("pixelformat: %d %d %d %d %d", format->bytesPerPixel, format->rBits(), format->gBits(), format->bBits(), format->aBits()); - _pfGame = *format; - } + _pfGame = format; /* If the current graphics mode does not fit with the pixel * format being requested, choose one that does and switch to it */ assert(_pfGame.bytesPerPixel > 0); if (_pfGame != _oldPfGame) { assert(_transactionState == kTransactionActive); - _gfxState.gfxModeID = chooseMode(&_pfGame); + _gfxState.gfxModeID = chooseMode(_pfGame); _transactionDetails.formatChanged = true; } @@ -765,12 +760,12 @@ void OSystem_3DS::setCursorDelta(float deltaX, float deltaY) { void OSystem_3DS::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, - const Graphics::PixelFormat *format) { + const Graphics::PixelFormat &format) { _cursorScalable = !dontScale; _cursorHotspotX = hotspotX; _cursorHotspotY = hotspotY; _cursorKeyColor = keycolor; - _pfCursor = !format ? Graphics::PixelFormat::createFormatCLUT8() : *format; + _pfCursor = format; if (w != (uint)_cursor.w || h != (uint)_cursor.h || _cursor.format != _pfCursor) { _cursor.create(w, h, _pfCursor); diff --git a/backends/platform/3ds/osystem.h b/backends/platform/3ds/osystem.h index 0cd1a1156632..eb74dc798093 100644 --- a/backends/platform/3ds/osystem.h +++ b/backends/platform/3ds/osystem.h @@ -133,9 +133,9 @@ class OSystem_3DS : public EventsBaseBackend, public PaletteManager, public Comm inline Graphics::PixelFormat getScreenFormat() const { return _pfGame; } virtual Common::List getSupportedFormats() const; void initSize(uint width, uint height, - const Graphics::PixelFormat *format = NULL); + const Graphics::PixelFormat &format); virtual int getScreenChangeID() const { return _screenChangeId; }; - GraphicsModeID chooseMode(Graphics::PixelFormat *format); + GraphicsModeID chooseMode(const Graphics::PixelFormat &format); bool setGraphicsMode(GraphicsModeID modeID); void beginGFXTransaction(); @@ -169,8 +169,8 @@ class OSystem_3DS : public EventsBaseBackend, public PaletteManager, public Comm bool showMouse(bool visible); void warpMouse(int x, int y); void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, - int hotspotY, uint32 keycolor, bool dontScale = false, - const Graphics::PixelFormat *format = NULL); + int hotspotY, uint32 keycolor, bool dontScale, + const Graphics::PixelFormat &format); void setCursorPalette(const byte *colors, uint start, uint num); // Transform point from touchscreen coords into gamescreen coords diff --git a/backends/platform/dc/dc.h b/backends/platform/dc/dc.h index 5042fb5ddc42..84b8a8b7590b 100644 --- a/backends/platform/dc/dc.h +++ b/backends/platform/dc/dc.h @@ -105,7 +105,7 @@ class OSystem_Dreamcast : private DCHardware, public EventsBaseBackend, public P // Set the size of the video bitmap. // Typically, 320x200 - void initSize(uint w, uint h, const Graphics::PixelFormat *format); + void initSize(uint w, uint h, const Graphics::PixelFormat &format); int16 getHeight() { return _screen_h; } int16 getWidth() { return _screen_w; } @@ -126,7 +126,7 @@ class OSystem_Dreamcast : private DCHardware, public EventsBaseBackend, public P void warpMouse(int x, int y); // Set the bitmap that's used when drawing the cursor. - void setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format); + void setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); // Replace the specified range of cursor the palette with new colors. void setCursorPalette(const byte *colors, uint start, uint num); diff --git a/backends/platform/dc/display.cpp b/backends/platform/dc/display.cpp index b19c10778ea6..b42106f395f4 100644 --- a/backends/platform/dc/display.cpp +++ b/backends/platform/dc/display.cpp @@ -214,14 +214,13 @@ void OSystem_Dreamcast::setScaling() } } -void OSystem_Dreamcast::initSize(uint w, uint h, const Graphics::PixelFormat *format) +void OSystem_Dreamcast::initSize(uint w, uint h, const Graphics::PixelFormat &format) { assert(w <= SCREEN_W && h <= SCREEN_H); int i = 0; - if (format != NULL) - for (i=NUM_FORMATS-1; i>0; --i) - if (*format == screenFormats[i]) + for (i=NUM_FORMATS-1; i>0; --i) + if (format == screenFormats[i]) break; _screenFormat = i; @@ -295,7 +294,7 @@ void OSystem_Dreamcast::warpMouse(int x, int y) void OSystem_Dreamcast::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, - uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) + uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { _ms_cur_w = w; _ms_cur_h = h; @@ -306,9 +305,8 @@ void OSystem_Dreamcast::setMouseCursor(const void *buf, uint w, uint h, _ms_keycolor = keycolor; int i = 0; - if (format != NULL) - for (i=NUM_FORMATS-1; i>0; --i) - if (*format == screenFormats[i]) + for (i=NUM_FORMATS-1; i>0; --i) + if (format == screenFormats[i]) break; _mouseFormat = i; diff --git a/backends/platform/ds/ds-graphics.cpp b/backends/platform/ds/ds-graphics.cpp index edf1b9fd9c86..ccb9545b760f 100644 --- a/backends/platform/ds/ds-graphics.cpp +++ b/backends/platform/ds/ds-graphics.cpp @@ -320,8 +320,8 @@ Common::List OSystem_DS::getSupportedFormats() const { return res; } -void OSystem_DS::initSize(uint width, uint height, const Graphics::PixelFormat *format) { - Graphics::PixelFormat actualFormat = format ? *format : _pfCLUT8; +void OSystem_DS::initSize(uint width, uint height, const Graphics::PixelFormat &format) { + Graphics::PixelFormat actualFormat = format; bool isRGB = (actualFormat != _pfCLUT8), swScale = ((_graphicsMode == GFX_SWSCALE) && (width == 320)); // For Lost in Time, the title screen is displayed in 640x400. @@ -493,11 +493,11 @@ void OSystem_DS::warpMouse(int x, int y) { _cursorPos = _framebuffer.scaledToReal(x, y); } -void OSystem_DS::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, u32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void OSystem_DS::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, u32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { if (!buf || w == 0 || h == 0) return; - Graphics::PixelFormat actualFormat = format ? *format : _pfCLUT8; + Graphics::PixelFormat actualFormat = format; if (_cursor.w != (int16)w || _cursor.h != (int16)h || _cursor.format != actualFormat) _cursor.create(w, h, actualFormat); _cursor.copyRectToSurface(buf, w * actualFormat.bytesPerPixel, 0, 0, w, h); diff --git a/backends/platform/ds/osystem_ds.h b/backends/platform/ds/osystem_ds.h index f2bd0305a9f1..309172ee8984 100644 --- a/backends/platform/ds/osystem_ds.h +++ b/backends/platform/ds/osystem_ds.h @@ -92,7 +92,7 @@ class OSystem_DS : public ModularMixerBackend, public PaletteManager { virtual Graphics::PixelFormat getScreenFormat() const; virtual Common::List getSupportedFormats() const; - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format); + virtual void initSize(uint width, uint height, const Graphics::PixelFormat &format); virtual int16 getHeight(); virtual int16 getWidth(); @@ -121,7 +121,7 @@ class OSystem_DS : public ModularMixerBackend, public PaletteManager { virtual bool showMouse(bool visible); virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, u32 keycolor, bool dontScale, const Graphics::PixelFormat *format); + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, u32 keycolor, bool dontScale, const Graphics::PixelFormat &format); virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority); diff --git a/backends/platform/ios7/ios7_osys_main.h b/backends/platform/ios7/ios7_osys_main.h index 1b90de28fa9c..22532b73bd41 100644 --- a/backends/platform/ios7/ios7_osys_main.h +++ b/backends/platform/ios7/ios7_osys_main.h @@ -129,7 +129,7 @@ class OSystem_iOS7 : public EventsBaseBackend, public PaletteManager { bool hasFeature(Feature f) override; void setFeatureState(Feature f, bool enable) override; bool getFeatureState(Feature f) override; - void initSize(uint width, uint height, const Graphics::PixelFormat *format) override; + void initSize(uint width, uint height, const Graphics::PixelFormat &format) override; void beginGFXTransaction() override; TransactionError endGFXTransaction() override; @@ -173,7 +173,7 @@ class OSystem_iOS7 : public EventsBaseBackend, public PaletteManager { bool showMouse(bool visible) override; void warpMouse(int x, int y) override; - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, bool dontScale = false, const Graphics::PixelFormat *format = NULL) override; + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) override; void setCursorPalette(const byte *colors, uint start, uint num) override; bool pollEvent(Common::Event &event) override; diff --git a/backends/platform/ios7/ios7_osys_video.mm b/backends/platform/ios7/ios7_osys_video.mm index 7171fc4bd3da..5adf6e331baf 100644 --- a/backends/platform/ios7/ios7_osys_video.mm +++ b/backends/platform/ios7/ios7_osys_video.mm @@ -122,8 +122,8 @@ static inline void execute_on_main_thread(void (^block)(void)) { return [UIScreen mainScreen].scale; } -void OSystem_iOS7::initSize(uint width, uint height, const Graphics::PixelFormat *format) { - //printf("initSize(%u, %u, %p)\n", width, height, (const void *)format); +void OSystem_iOS7::initSize(uint width, uint height, const Graphics::PixelFormat &format) { + //printf("initSize(%u, %u, %s)\n", width, height, format.toString().c_str()); _videoContext->screenWidth = width; _videoContext->screenHeight = height; @@ -144,19 +144,13 @@ static inline void execute_on_main_thread(void (^block)(void)) { // In case the client code tries to set up a non supported mode, we will // fall back to CLUT8 and set the transaction error accordingly. - if (format && format->bytesPerPixel != 1 && *format != _videoContext->screenTexture.format) { - format = 0; + if (format.bytesPerPixel != 1 && format != _videoContext->screenTexture.format) { _gfxTransactionError = kTransactionFormatNotSupported; } - if (!format || format->bytesPerPixel == 1) { + if (format.bytesPerPixel == 1) { _framebuffer.create(width, height, Graphics::PixelFormat::createFormatCLUT8()); } else { -#if 0 - printf("bytesPerPixel: %u RGBAlosses: %u,%u,%u,%u RGBAshifts: %u,%u,%u,%u\n", format->bytesPerPixel, - format->rLoss, format->gLoss, format->bLoss, format->aLoss, - format->rShift, format->gShift, format->bShift, format->aShift); -#endif // We directly draw on the screen texture in hi-color mode. Thus // we copy over its settings here and just replace the width and // height to avoid any problems. @@ -480,15 +474,11 @@ static inline void execute_on_main_thread(void (^block)(void)) { } } -void OSystem_iOS7::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { - //printf("setMouseCursor(%p, %u, %u, %i, %i, %u, %d, %p)\n", (const void *)buf, w, h, hotspotX, hotspotY, keycolor, dontScale, (const void *)format); +void OSystem_iOS7::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { + //printf("setMouseCursor(%p, %u, %u, %i, %i, %u, %d, %s)\n", (const void *)buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format.toString().c_str()); + + const Graphics::PixelFormat pixelFormat = format; - const Graphics::PixelFormat pixelFormat = format ? *format : Graphics::PixelFormat::createFormatCLUT8(); -#if 0 - printf("bytesPerPixel: %u RGBAlosses: %u,%u,%u,%u RGBAshifts: %u,%u,%u,%u\n", pixelFormat.bytesPerPixel, - pixelFormat.rLoss, pixelFormat.gLoss, pixelFormat.bLoss, pixelFormat.aLoss, - pixelFormat.rShift, pixelFormat.gShift, pixelFormat.bShift, pixelFormat.aShift); -#endif assert(pixelFormat.bytesPerPixel == 1 || pixelFormat.bytesPerPixel == 2 || pixelFormat.bytesPerPixel == 4); if (_mouseBuffer.w != (int16)w || _mouseBuffer.h != (int16)h || _mouseBuffer.format != pixelFormat || !_mouseBuffer.getPixels()) diff --git a/backends/platform/iphone/osys_main.h b/backends/platform/iphone/osys_main.h index 67c7e111c0ca..ba5836d00de9 100644 --- a/backends/platform/iphone/osys_main.h +++ b/backends/platform/iphone/osys_main.h @@ -119,7 +119,7 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager { virtual bool hasFeature(Feature f); virtual void setFeatureState(Feature f, bool enable); virtual bool getFeatureState(Feature f); - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format); + virtual void initSize(uint width, uint height, const Graphics::PixelFormat &format); virtual void beginGFXTransaction(); virtual TransactionError endGFXTransaction(); @@ -158,7 +158,7 @@ class OSystem_IPHONE : public EventsBaseBackend, public PaletteManager { virtual bool showMouse(bool visible); virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, bool dontScale = false, const Graphics::PixelFormat *format = NULL); + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); virtual void setCursorPalette(const byte *colors, uint start, uint num); virtual bool pollEvent(Common::Event &event); diff --git a/backends/platform/iphone/osys_video.mm b/backends/platform/iphone/osys_video.mm index baf7d4d7eddb..fa172742a168 100644 --- a/backends/platform/iphone/osys_video.mm +++ b/backends/platform/iphone/osys_video.mm @@ -54,8 +54,8 @@ } #endif -void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat *format) { - //printf("initSize(%u, %u, %p)\n", width, height, (const void *)format); +void OSystem_IPHONE::initSize(uint width, uint height, const Graphics::PixelFormat &format) { + //printf("initSize(%u, %u, %s)\n", width, height, format.toString().c_str()); _videoContext->screenWidth = width; _videoContext->screenHeight = height; @@ -74,19 +74,13 @@ // In case the client code tries to set up a non supported mode, we will // fall back to CLUT8 and set the transaction error accordingly. - if (format && format->bytesPerPixel != 1 && *format != _videoContext->screenTexture.format) { - format = 0; + if (format.bytesPerPixel != 1 && format != _videoContext->screenTexture.format) { _gfxTransactionError = kTransactionFormatNotSupported; } - if (!format || format->bytesPerPixel == 1) { + if (format.bytesPerPixel == 1) { _framebuffer.create(width, height, Graphics::PixelFormat::createFormatCLUT8()); } else { -#if 0 - printf("bytesPerPixel: %u RGBAlosses: %u,%u,%u,%u RGBAshifts: %u,%u,%u,%u\n", format->bytesPerPixel, - format->rLoss, format->gLoss, format->bLoss, format->aLoss, - format->rShift, format->gShift, format->bShift, format->aShift); -#endif // We directly draw on the screen texture in hi-color mode. Thus // we copy over its settings here and just replace the width and // height to avoid any problems. @@ -398,15 +392,10 @@ } } -void OSystem_IPHONE::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { - //printf("setMouseCursor(%p, %u, %u, %i, %i, %u, %d, %p)\n", (const void *)buf, w, h, hotspotX, hotspotY, keycolor, dontScale, (const void *)format); +void OSystem_IPHONE::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { + //printf("setMouseCursor(%p, %u, %u, %i, %i, %u, %d, %s)\n", (const void *)buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format.toString().c_str()); - const Graphics::PixelFormat pixelFormat = format ? *format : Graphics::PixelFormat::createFormatCLUT8(); -#if 0 - printf("bytesPerPixel: %u RGBAlosses: %u,%u,%u,%u RGBAshifts: %u,%u,%u,%u\n", pixelFormat.bytesPerPixel, - pixelFormat.rLoss, pixelFormat.gLoss, pixelFormat.bLoss, pixelFormat.aLoss, - pixelFormat.rShift, pixelFormat.gShift, pixelFormat.bShift, pixelFormat.aShift); -#endif + const Graphics::PixelFormat pixelFormat = format; assert(pixelFormat.bytesPerPixel == 1 || pixelFormat.bytesPerPixel == 2); if (_mouseBuffer.w != w || _mouseBuffer.h != h || _mouseBuffer.format != pixelFormat || !_mouseBuffer.getPixels()) diff --git a/backends/platform/n64/osys_n64.h b/backends/platform/n64/osys_n64.h index 048c603a052c..3a45b125990b 100644 --- a/backends/platform/n64/osys_n64.h +++ b/backends/platform/n64/osys_n64.h @@ -147,7 +147,7 @@ class OSystem_N64 : public EventsBaseBackend, public PaletteManager { virtual int getDefaultGraphicsMode() const; virtual bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags); virtual int getGraphicsMode() const; - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format); + virtual void initSize(uint width, uint height, const Graphics::PixelFormat &format); virtual int16 getHeight(); virtual int16 getWidth(); @@ -179,7 +179,7 @@ class OSystem_N64 : public EventsBaseBackend, public PaletteManager { virtual bool showMouse(bool visible); virtual void warpMouse(int x, int y); - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format); + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); virtual void setCursorPalette(const byte *colors, uint start, uint num); virtual bool pollEvent(Common::Event &event); diff --git a/backends/platform/n64/osys_n64_base.cpp b/backends/platform/n64/osys_n64_base.cpp index 0749656e696d..683589f0824f 100644 --- a/backends/platform/n64/osys_n64_base.cpp +++ b/backends/platform/n64/osys_n64_base.cpp @@ -319,7 +319,7 @@ int OSystem_N64::getGraphicsMode() const { return _graphicMode; } -void OSystem_N64::initSize(uint width, uint height, const Graphics::PixelFormat *format) { +void OSystem_N64::initSize(uint width, uint height, const Graphics::PixelFormat &format) { _gameWidth = width; _gameHeight = height; @@ -758,7 +758,7 @@ void OSystem_N64::warpMouse(int x, int y) { _dirtyOffscreen = true; } -void OSystem_N64::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void OSystem_N64::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { if (!w || !h) return; _mouseHotspotX = hotspotX; diff --git a/backends/platform/psp/cursor.cpp b/backends/platform/psp/cursor.cpp index 8cc4104d1e3a..6d60abcd737a 100644 --- a/backends/platform/psp/cursor.cpp +++ b/backends/platform/psp/cursor.cpp @@ -216,7 +216,7 @@ inline void Cursor::adjustXYForScreenSize(int32 &x, int32 &y) { } // This is only called when we have a new screen -void Cursor::setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat *format) { +void Cursor::setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat &format) { DEBUG_ENTER_FUNC(); PSPPixelFormat::Type bufferType = PSPPixelFormat::Type_Unknown; @@ -237,7 +237,7 @@ void Cursor::setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat *for } // This is called many many times -void Cursor::setSizeAndScummvmPixelFormat(uint32 width, uint32 height, const Graphics::PixelFormat *format) { +void Cursor::setSizeAndScummvmPixelFormat(uint32 width, uint32 height, const Graphics::PixelFormat &format) { DEBUG_ENTER_FUNC(); PSP_DEBUG_PRINT("useCursorPalette[%s]\n", _useCursorPalette ? "true" : "false"); @@ -272,12 +272,10 @@ void Cursor::setSizeAndScummvmPixelFormat(uint32 width, uint32 height, const Gra if (paletteType == PSPPixelFormat::Type_None) { setRendererModePalettized(false); // use non-palettized mechanism - if (format) { - if (format->aBits() == 0) - _fakeAlpha = true; // we are treating e.g. 555 as 5551 - else - _fakeAlpha = false; // we have a genuine alpha channel - } + if (format.aBits() == 0) + _fakeAlpha = true; // we are treating e.g. 555 as 5551 + else + _fakeAlpha = false; // we have a genuine alpha channel } else { // We have a palette _palette.setPixelFormats(paletteType, bufferType); setRendererModePalettized(true); // use palettized mechanism diff --git a/backends/platform/psp/cursor.h b/backends/platform/psp/cursor.h index 85d1814b07fa..342eaeef65c6 100644 --- a/backends/platform/psp/cursor.h +++ b/backends/platform/psp/cursor.h @@ -62,8 +62,8 @@ class Cursor : public DefaultDisplayClient { void adjustXYForScreenSize(int32 &x, int32 &y); void init(); void setHotspot(int32 x, int32 y); - void setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat *format); - void setSizeAndScummvmPixelFormat(uint32 widht, uint32 height, const Graphics::PixelFormat *format); + void setScreenPaletteScummvmPixelFormat(const Graphics::PixelFormat &format); + void setSizeAndScummvmPixelFormat(uint32 widht, uint32 height, const Graphics::PixelFormat &format); void clearKeyColor(); void useGlobalScaler(bool val) { _renderer.setUseGlobalScaler(val); } bool allocate(); @@ -71,10 +71,6 @@ class Cursor : public DefaultDisplayClient { private: void setSize(uint32 width, uint32 height); - void getPixelFormatsFromScummvmPixelFormat(const Graphics::PixelFormat *format, - PSPPixelFormat::Type &bufferFormat, - PSPPixelFormat::Type &paletteFormat, - uint32 &numOfEntries); void setRendererModePalettized(bool palettized); }; diff --git a/backends/platform/psp/default_display_client.cpp b/backends/platform/psp/default_display_client.cpp index 81b058043140..0f355ebb938e 100644 --- a/backends/platform/psp/default_display_client.cpp +++ b/backends/platform/psp/default_display_client.cpp @@ -170,16 +170,11 @@ void Screen::setSize(uint32 width, uint32 height) { _renderer.setDrawWholeBuffer(); // We need to let the renderer know how much to draw } -void Screen::setScummvmPixelFormat(const Graphics::PixelFormat *format) { +void Screen::setScummvmPixelFormat(const Graphics::PixelFormat &format) { DEBUG_ENTER_FUNC(); - PSP_DEBUG_PRINT("format[%p], _buffer[%p], _palette[%p]\n", format, &_buffer, &_palette); + PSP_DEBUG_PRINT("format[%s], _buffer[%p], _palette[%p]\n", format.toString().c_str(), &_buffer, &_palette); - if (!format) { - memset(&_pixelFormat, 0, sizeof(_pixelFormat)); - _pixelFormat.bytesPerPixel = 1; // default - } else { - _pixelFormat = *format; - } + _pixelFormat = format; PSPPixelFormat::Type bufferFormat, paletteFormat; bool swapRedBlue = false; diff --git a/backends/platform/psp/default_display_client.h b/backends/platform/psp/default_display_client.h index f4b96156142a..815f2065d1ad 100644 --- a/backends/platform/psp/default_display_client.h +++ b/backends/platform/psp/default_display_client.h @@ -85,7 +85,7 @@ class Screen : public DefaultDisplayClient { void init(); bool allocate(); void setShakePos(int shakeXOffset, int shakeYOffset); - void setScummvmPixelFormat(const Graphics::PixelFormat *format); + void setScummvmPixelFormat(const Graphics::PixelFormat &format); const Graphics::PixelFormat &getScummvmPixelFormat() const { return _pixelFormat; } Graphics::Surface *lockAndGetForEditing(); void unlock() { setDirty(); } // set dirty here because of changes diff --git a/backends/platform/psp/display_manager.cpp b/backends/platform/psp/display_manager.cpp index d6f94932e9eb..848dc6e837a3 100644 --- a/backends/platform/psp/display_manager.cpp +++ b/backends/platform/psp/display_manager.cpp @@ -308,9 +308,9 @@ void DisplayManager::init() { _overlay->allocate(); } -void DisplayManager::setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format) { +void DisplayManager::setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat &format) { DEBUG_ENTER_FUNC(); - PSP_DEBUG_PRINT("w[%u], h[%u], pformat[%p]\n", width, height, format); + PSP_DEBUG_PRINT("w[%u], h[%u], format[%s]\n", width, height, format.toString().c_str()); _screen->deallocate(); diff --git a/backends/platform/psp/display_manager.h b/backends/platform/psp/display_manager.h index d9249efc8a68..ca3da54c3dc5 100644 --- a/backends/platform/psp/display_manager.h +++ b/backends/platform/psp/display_manager.h @@ -126,7 +126,7 @@ class DisplayManager { void setKeyboard(PSPKeyboard *keyboard) { _keyboard = keyboard; } void setImageViewer(ImageViewer *imageViewer) { _imageViewer = imageViewer; } - void setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat *format); + void setSizeAndPixelFormat(uint width, uint height, const Graphics::PixelFormat &format); // Getters float getScaleX() const { return _displayParams.scaleX; } diff --git a/backends/platform/psp/osys_psp.cpp b/backends/platform/psp/osys_psp.cpp index cc0ec4189f77..ef9c67ab3ebf 100644 --- a/backends/platform/psp/osys_psp.cpp +++ b/backends/platform/psp/osys_psp.cpp @@ -158,7 +158,7 @@ Common::List OSystem_PSP::getSupportedFormats() const { #endif -void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat *format) { +void OSystem_PSP::initSize(uint width, uint height, const Graphics::PixelFormat &format) { DEBUG_ENTER_FUNC(); _displayManager.waitUntilRenderFinished(); _pendingUpdate = false; @@ -303,15 +303,12 @@ void OSystem_PSP::warpMouse(int x, int y) { _cursor.setXY(x, y); } -void OSystem_PSP::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void OSystem_PSP::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { DEBUG_ENTER_FUNC(); _displayManager.waitUntilRenderFinished(); _pendingUpdate = false; - PSP_DEBUG_PRINT("pbuf[%p], w[%u], h[%u], hotspot:X[%d], Y[%d], keycolor[%d], scale[%d], pformat[%p]\n", buf, w, h, hotspotX, hotspotY, keycolor, !dontScale, format); - if (format) { - PSP_DEBUG_PRINT("format: bpp[%d], rLoss[%d], gLoss[%d], bLoss[%d], aLoss[%d], rShift[%d], gShift[%d], bShift[%d], aShift[%d]\n", format->bytesPerPixel, format->rLoss, format->gLoss, format->bLoss, format->aLoss, format->rShift, format->gShift, format->bShift, format->aShift); - } + PSP_DEBUG_PRINT("pbuf[%p], w[%u], h[%u], hotspot:X[%d], Y[%d], keycolor[%d], scale[%d], pformat[%s]\n", buf, w, h, hotspotX, hotspotY, keycolor, !dontScale, format.toString().c_str()); _cursor.setKeyColor(keycolor); // TODO: The old target scale was saved but never used. Should the new diff --git a/backends/platform/psp/osys_psp.h b/backends/platform/psp/osys_psp.h index 9a2a65be94ee..d350e6a4c22a 100644 --- a/backends/platform/psp/osys_psp.h +++ b/backends/platform/psp/osys_psp.h @@ -80,7 +80,7 @@ class OSystem_PSP : public EventsBaseBackend, public PaletteManager { #endif // Screen size - void initSize(uint width, uint height, const Graphics::PixelFormat *format); + void initSize(uint width, uint height, const Graphics::PixelFormat &format); int16 getWidth(); int16 getHeight(); @@ -114,7 +114,7 @@ class OSystem_PSP : public EventsBaseBackend, public PaletteManager { // Mouse related bool showMouse(bool visible); void warpMouse(int x, int y); - void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format); + void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); // Events and input bool pollEvent(Common::Event &event); diff --git a/backends/platform/psp/psppixelformat.cpp b/backends/platform/psp/psppixelformat.cpp index 531d0fb7f4af..043a0c4a4f46 100644 --- a/backends/platform/psp/psppixelformat.cpp +++ b/backends/platform/psp/psppixelformat.cpp @@ -65,54 +65,49 @@ void PSPPixelFormat::set(Type type, bool swap /* = false */) { // Convert from ScummVM general PixelFormat to our pixel format // For buffer and palette. -void PSPPixelFormat::convertFromScummvmPixelFormat(const Graphics::PixelFormat *pf, +void PSPPixelFormat::convertFromScummvmPixelFormat(const Graphics::PixelFormat &pf, PSPPixelFormat::Type &bufferType, PSPPixelFormat::Type &paletteType, bool &swapRedBlue) { swapRedBlue = false; // no red-blue swap by default PSPPixelFormat::Type *target = nullptr; // which one we'll be filling - if (!pf) { // Default, pf is NULL + if (pf.bytesPerPixel == 1) { bufferType = Type_Palette_8bit; - paletteType = Type_5551; - } else { // We have a pf - if (pf->bytesPerPixel == 1) { - bufferType = Type_Palette_8bit; - target = &paletteType; // The type describes the palette - } else if (pf->bytesPerPixel == 2 || pf->bytesPerPixel == 4) { - paletteType = Type_None; - target = &bufferType; // The type describes the buffer - } else { - PSP_ERROR("Unknown bpp[%u] in pixeltype. Reverting to 8bpp\n", pf->bytesPerPixel); - bufferType = Type_Palette_8bit; - target = &paletteType; // The type describes the palette - } - - // Find out the exact type of the target - if (pf->rLoss == 3 && pf->bLoss == 3) { - if (pf->gLoss == 3) - *target = Type_5551; - else - *target = Type_5650; - } else if (pf->rLoss == 4 && pf->gLoss == 4 && pf->bLoss == 4) { - *target = Type_4444; - } else if (pf->gLoss == 0 && pf->gShift == 8) { - *target = Type_8888; - } else if ((pf->gLoss == 0 && pf->gShift == 0) || - (pf->gLoss == 8 && pf->gShift == 0)) { // Default CLUT8 can have weird values + target = &paletteType; // The type describes the palette + } else if (pf.bytesPerPixel == 2 || pf.bytesPerPixel == 4) { + paletteType = Type_None; + target = &bufferType; // The type describes the buffer + } else { + PSP_ERROR("Unknown bpp[%u] in pixeltype. Reverting to 8bpp\n", pf.bytesPerPixel); + bufferType = Type_Palette_8bit; + target = &paletteType; // The type describes the palette + } + + // Find out the exact type of the target + if (pf.rLoss == 3 && pf.bLoss == 3) { + if (pf.gLoss == 3) *target = Type_5551; - } else { - PSP_ERROR("Unknown Scummvm pixel format.\n"); - PSP_ERROR("\trLoss[%d], gLoss[%d], bLoss[%d], aLoss[%d]\n\trShift[%d], gShift[%d], bShift[%d], aShift[%d]\n", - pf->rLoss, pf->gLoss, pf->bLoss, pf->aLoss, - pf->rShift, pf->gShift, pf->bShift, pf->aShift); - *target = Type_Unknown; - } - - if (pf->rShift != 0) {// We allow backend swap of red and blue - swapRedBlue = true; - PSP_DEBUG_PRINT("detected red/blue swap\n"); - } + else + *target = Type_5650; + } else if (pf.rLoss == 4 && pf.gLoss == 4 && pf.bLoss == 4) { + *target = Type_4444; + } else if (pf.gLoss == 0 && pf.gShift == 8) { + *target = Type_8888; + } else if ((pf.gLoss == 0 && pf.gShift == 0) || + (pf.gLoss == 8 && pf.gShift == 0)) { // Default CLUT8 can have weird values + *target = Type_5551; + } else { + PSP_ERROR("Unknown Scummvm pixel format.\n"); + PSP_ERROR("\trLoss[%d], gLoss[%d], bLoss[%d], aLoss[%d]\n\trShift[%d], gShift[%d], bShift[%d], aShift[%d]\n", + pf.rLoss, pf.gLoss, pf.bLoss, pf.aLoss, + pf.rShift, pf.gShift, pf.bShift, pf.aShift); + *target = Type_Unknown; + } + + if (pf.rShift != 0) {// We allow backend swap of red and blue + swapRedBlue = true; + PSP_DEBUG_PRINT("detected red/blue swap\n"); } } diff --git a/backends/platform/psp/psppixelformat.h b/backends/platform/psp/psppixelformat.h index cd9a6384148b..b18166434253 100644 --- a/backends/platform/psp/psppixelformat.h +++ b/backends/platform/psp/psppixelformat.h @@ -49,7 +49,7 @@ struct PSPPixelFormat { PSPPixelFormat() : format(Type_Unknown), bitsPerPixel(0), swapRB(false) {} void set(Type type, bool swap = false); - static void convertFromScummvmPixelFormat(const Graphics::PixelFormat *pf, + static void convertFromScummvmPixelFormat(const Graphics::PixelFormat &pf, PSPPixelFormat::Type &bufferType, PSPPixelFormat::Type &paletteType, bool &swapRedBlue); diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index 784580cc9e1d..04f7270a9a7c 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -852,7 +852,7 @@ bool OSystem_SDL::setGraphicsMode(int mode, uint flags) { _graphicsManager->beginGFXTransaction(); if (!_graphicsManager->setGraphicsMode(_graphicsModeIds[mode], flags)) return false; - _graphicsManager->initSize(_gfxManagerState.screenWidth, _gfxManagerState.screenHeight); + _graphicsManager->initSize(_gfxManagerState.screenWidth, _gfxManagerState.screenHeight, Graphics::PixelFormat::createFormatCLUT8()); _graphicsManager->endGFXTransaction(); // This failing will probably have bad consequences... diff --git a/backends/platform/wii/osystem.h b/backends/platform/wii/osystem.h index 4662f9026dab..ae232228d3c5 100644 --- a/backends/platform/wii/osystem.h +++ b/backends/platform/wii/osystem.h @@ -156,7 +156,7 @@ class OSystem_Wii final : public EventsBaseBackend, public PaletteManager { #endif int getGraphicsMode() const override; virtual void initSize(uint width, uint height, - const Graphics::PixelFormat *format) override; + const Graphics::PixelFormat &format) override; int16 getWidth() override; int16 getHeight() override; @@ -190,7 +190,7 @@ class OSystem_Wii final : public EventsBaseBackend, public PaletteManager { virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, - const Graphics::PixelFormat *format) override; + const Graphics::PixelFormat &format) override; bool pollEvent(Common::Event &event) override; uint32 getMillis(bool skipRecord = false) override; diff --git a/backends/platform/wii/osystem_gfx.cpp b/backends/platform/wii/osystem_gfx.cpp index 56d223ed9a50..1676aebbec48 100644 --- a/backends/platform/wii/osystem_gfx.cpp +++ b/backends/platform/wii/osystem_gfx.cpp @@ -221,17 +221,12 @@ Common::List OSystem_Wii::getSupportedFormats() const { #endif void OSystem_Wii::initSize(uint width, uint height, - const Graphics::PixelFormat *format) { + const Graphics::PixelFormat &format) { bool update = false; gfx_tex_format_t tex_format; #ifdef USE_RGB_COLOR - Graphics::PixelFormat newFormat; - - if (format) - newFormat = *format; - else - newFormat = Graphics::PixelFormat::createFormatCLUT8(); + Graphics::PixelFormat newFormat = format; if (newFormat.bytesPerPixel > 2) newFormat = Graphics::PixelFormat::createFormatCLUT8(); @@ -651,16 +646,13 @@ void OSystem_Wii::warpMouse(int x, int y) { void OSystem_Wii::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, - const Graphics::PixelFormat *format) { + const Graphics::PixelFormat &format) { gfx_tex_format_t tex_format = GFX_TF_PALETTE_RGB5A3; uint tw, th; uint32 oldKeycolor = _mouseKeyColor; #ifdef USE_RGB_COLOR - if (!format) - _pfCursor = Graphics::PixelFormat::createFormatCLUT8(); - else - _pfCursor = *format; + _pfCursor = format; if (_pfCursor.bytesPerPixel > 1) { tex_format = GFX_TF_RGB5A3; diff --git a/base/main.cpp b/base/main.cpp index a3ee5c6f28dc..9e7f66130298 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -356,7 +356,7 @@ static void setupGraphics(OSystem &system) { system.setShader(ConfMan.get("shader").c_str()); system.setScaler(ConfMan.get("scaler").c_str(), ConfMan.getInt("scale_factor")); - system.initSize(320, 200); + system.initSize(320, 200, Graphics::PixelFormat::createFormatCLUT8()); // Parse graphics configuration, implicit fallback to defaults set with RegisterDefaults() system.setFeatureState(OSystem::kFeatureAspectRatioCorrection, ConfMan.getBool("aspect_ratio")); diff --git a/common/system.h b/common/system.h index 34db3d089cbc..fde201812787 100644 --- a/common/system.h +++ b/common/system.h @@ -959,7 +959,7 @@ class OSystem : Common::NonCopyable { * @param height New virtual screen height. * @param format New virtual screen pixel format. */ - virtual void initSize(uint width, uint height, const Graphics::PixelFormat *format = nullptr) = 0; + virtual void initSize(uint width, uint height, const Graphics::PixelFormat &format) = 0; /** * Send a list of graphics modes to the backend so it can make a decision @@ -1340,9 +1340,9 @@ class OSystem : Common::NonCopyable { * value. (The SDL backend will just assert to prevent abuse of this). * @param dontScale Whether the cursor should never be scaled. An exception is high ppi displays, where the cursor * might be too small to notice otherwise, these are allowed to scale the cursor anyway. - * @param format Pointer to the pixel format that the cursor graphic uses (0 means CLUT8). + * @param format The pixel format that the cursor graphic uses. */ - virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = nullptr) = 0; + virtual void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) = 0; /** * Replace the specified range of cursor palette with new colors. diff --git a/engines/engine.cpp b/engines/engine.cpp index b421f8e0d239..080de921c622 100644 --- a/engines/engine.cpp +++ b/engines/engine.cpp @@ -319,13 +319,13 @@ void initGraphics(int width, int height, const Graphics::PixelFormat *format) { initCommonGFX(); #ifdef USE_RGB_COLOR if (format) - g_system->initSize(width, height, format); + g_system->initSize(width, height, *format); else { Graphics::PixelFormat bestFormat = g_system->getSupportedFormats().front(); - g_system->initSize(width, height, &bestFormat); + g_system->initSize(width, height, bestFormat); } #else - g_system->initSize(width, height); + g_system->initSize(width, height, Graphics::PixelFormat::createFormatCLUT8()); #endif OSystem::TransactionError gfxError = g_system->endGFXTransaction(); @@ -421,7 +421,7 @@ void initGraphics(int width, int height) { void initGraphics3d(int width, int height) { g_system->beginGFXTransaction(); g_system->setGraphicsMode(0, OSystem::kGfxModeRender3d); - g_system->initSize(width, height); + g_system->initSize(width, height, Graphics::PixelFormat::createFormatCLUT8()); g_system->setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen")); // TODO: Replace this with initCommonGFX() g_system->setFeatureState(OSystem::kFeatureAspectRatioCorrection, ConfMan.getBool("aspect_ratio")); // TODO: Replace this with initCommonGFX() g_system->endGFXTransaction(); @@ -443,7 +443,7 @@ void GUIErrorMessage(const Common::U32String &msg, const char *url) { g_system->setWindowCaption(_("Error")); g_system->beginGFXTransaction(); initCommonGFX(); - g_system->initSize(320, 200); + g_system->initSize(320, 200, Graphics::PixelFormat::createFormatCLUT8()); if (g_system->endGFXTransaction() == OSystem::kTransactionSuccess) { if (url) { GUI::MessageDialogWithURL dialog(msg, url); diff --git a/engines/glk/events.cpp b/engines/glk/events.cpp index cf0a3c772b45..77cbf71dbe86 100644 --- a/engines/glk/events.cpp +++ b/engines/glk/events.cpp @@ -410,7 +410,7 @@ void Events::setCursor(CursorId cursorId) { const Surface &s = _cursors[cursorId]; const int TRANSPARENT = s.format.RGBToColor(TRANSPARENT_RGB, TRANSPARENT_RGB, TRANSPARENT_RGB); - CursorMan.replaceCursor(s.getPixels(), s.w, s.h, s._hotspot.x, s._hotspot.y, TRANSPARENT, true, &s.format); + CursorMan.replaceCursor(s.getPixels(), s.w, s.h, s._hotspot.x, s._hotspot.y, TRANSPARENT, true, s.format); } _cursorId = cursorId; diff --git a/engines/gob/draw_v1.cpp b/engines/gob/draw_v1.cpp index a0e6a91b4e9a..37cec9961cf5 100644 --- a/engines/gob/draw_v1.cpp +++ b/engines/gob/draw_v1.cpp @@ -122,7 +122,7 @@ void Draw_v1::animateCursor(int16 cursor) { (cursorIndex + 1) * _cursorWidth - 1, _cursorHeight - 1, 0, 0); CursorMan.replaceCursor(_scummvmCursor->getData(), - _cursorWidth, _cursorHeight, hotspotX, hotspotY, 0, false, &_vm->getPixelFormat()); + _cursorWidth, _cursorHeight, hotspotX, hotspotY, 0, false, _vm->getPixelFormat()); if (_frontSurface != _backSurface) { _showCursor = 3; diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp index 5d15de01cbf9..6d9a703b6928 100644 --- a/engines/gob/draw_v2.cpp +++ b/engines/gob/draw_v2.cpp @@ -163,7 +163,7 @@ void Draw_v2::animateCursor(int16 cursor) { keyColor = _cursorKeyColors[cursorIndex]; CursorMan.replaceCursor(_scummvmCursor->getData(), - _cursorWidth, _cursorHeight, hotspotX, hotspotY, keyColor, false, &_vm->getPixelFormat()); + _cursorWidth, _cursorHeight, hotspotX, hotspotY, keyColor, false, _vm->getPixelFormat()); if (_doCursorPalettes && _doCursorPalettes[cursorIndex]) { CursorMan.replaceCursorPalette(_cursorPalettes + (cursorIndex * 256 * 3), diff --git a/engines/groovie/cursor.cpp b/engines/groovie/cursor.cpp index c2bc06018c65..11a97c3a5c65 100644 --- a/engines/groovie/cursor.cpp +++ b/engines/groovie/cursor.cpp @@ -375,7 +375,7 @@ void Cursor_v2::showFrame(uint16 frame) { int offset = _width * _height * frame * 4; // SDL uses keycolor even though we're using ABGR8888, so just set it to a pink color that isn't used uint32 keycolor = _format.ARGBToColor(0, 255, 128, 255); - CursorMan.replaceCursor((const byte *)(_img + offset), _width, _height, _hotspotX, _hotspotY, keycolor, false, &_format); + CursorMan.replaceCursor((const byte *)(_img + offset), _width, _height, _hotspotX, _hotspotY, keycolor, false, _format); } void blendCursorPixel(uint32 &d, uint32 &s) { @@ -433,7 +433,7 @@ void Cursor_v2::show2Cursors(Cursor_v2 *c1, uint16 frame1, Cursor_v2 *c2, uint16 uint32 keycolor = format.ARGBToColor(0, 255, 128, 255); // replaceCursor copies the buffer, so we're ok to delete it - CursorMan.replaceCursor((const byte *)img, width, height, c1->_hotspotX, c1->_hotspotY, keycolor, false, &c1->_format); + CursorMan.replaceCursor((const byte *)img, width, height, c1->_hotspotX, c1->_hotspotY, keycolor, false, c1->_format); delete[] img; } diff --git a/engines/kyra/graphics/screen_eob.cpp b/engines/kyra/graphics/screen_eob.cpp index 13666ff71cdb..1f098e6de5fc 100644 --- a/engines/kyra/graphics/screen_eob.cpp +++ b/engines/kyra/graphics/screen_eob.cpp @@ -242,7 +242,7 @@ void Screen_EoB::setMouseCursor(int x, int y, const byte *shape, const uint8 *ov colorKey = _16bitConversionPalette ? _16bitConversionPalette[colorKey] : colorKey; Graphics::PixelFormat pixelFormat = _system->getScreenFormat(); - CursorMan.replaceCursor(cursor, mouseW * scaleFactor, mouseH * scaleFactor, x * scaleFactor, y * scaleFactor, colorKey, false, &pixelFormat); + CursorMan.replaceCursor(cursor, mouseW * scaleFactor, mouseH * scaleFactor, x * scaleFactor, y * scaleFactor, colorKey, false, pixelFormat); if (isMouseVisible()) CursorMan.showMouse(true); delete[] cursor; diff --git a/engines/lastexpress/data/cursor.cpp b/engines/lastexpress/data/cursor.cpp index 4a5ad671d6db..145252b629f5 100644 --- a/engines/lastexpress/data/cursor.cpp +++ b/engines/lastexpress/data/cursor.cpp @@ -92,7 +92,7 @@ void Cursor::setStyle(CursorStyle style) { Graphics::PixelFormat pf = g_system->getScreenFormat(); CursorMan.replaceCursor(getCursorImage(style), 32, 32, _cursors[style].hotspotX, _cursors[style].hotspotY, - 0, false, &pf); + 0, false, pf); } const uint16 *Cursor::getCursorImage(CursorStyle style) const { diff --git a/engines/mohawk/cursors.cpp b/engines/mohawk/cursors.cpp index 82898baeab89..905c996dc581 100644 --- a/engines/mohawk/cursors.cpp +++ b/engines/mohawk/cursors.cpp @@ -130,7 +130,7 @@ void MystCursorManager::setCursor(uint16 id) { CursorMan.replaceCursorPalette(mhkSurface->getPalette(), 0, 256); } else { Graphics::PixelFormat pixelFormat = g_system->getScreenFormat(); - CursorMan.replaceCursor(surface->getPixels(), surface->w, surface->h, hotspotX, hotspotY, pixelFormat.RGBToColor(255, 255, 255), false, &pixelFormat); + CursorMan.replaceCursor(surface->getPixels(), surface->w, surface->h, hotspotX, hotspotY, pixelFormat.RGBToColor(255, 255, 255), false, pixelFormat); } } diff --git a/engines/nancy/cursor.cpp b/engines/nancy/cursor.cpp index 38d904b95c2c..7e153446e2c6 100644 --- a/engines/nancy/cursor.cpp +++ b/engines/nancy/cursor.cpp @@ -136,7 +136,7 @@ void CursorManager::setCursor(CursorType type, int16 itemID) { transColor = temp.format.RGBToColor(r, g, b); } - CursorMan.replaceCursor(temp.getPixels(), temp.w, temp.h, hotspot.x, hotspot.y, transColor, false, &temp.format); + CursorMan.replaceCursor(temp.getPixels(), temp.w, temp.h, hotspot.x, hotspot.y, transColor, false, temp.format); } void CursorManager::setCursorType(CursorType type) { diff --git a/engines/pegasus/cursor.cpp b/engines/pegasus/cursor.cpp index 45dc6d8d25f1..e768928a6229 100644 --- a/engines/pegasus/cursor.cpp +++ b/engines/pegasus/cursor.cpp @@ -86,7 +86,7 @@ void Cursor::setCurrentFrameIndex(int32 index) { CursorMan.replaceCursorPalette(_info[index].palette, 0, _info[index].colorCount); CursorMan.replaceCursor(_info[index].surface->getPixels(), _info[index].surface->w, _info[index].surface->h, _info[index].hotspot.x, _info[index].hotspot.y, 0); } else { - CursorMan.replaceCursor(_info[index].surface->getPixels(), _info[index].surface->w, _info[index].surface->h, _info[index].hotspot.x, _info[index].hotspot.y, _info[index].surface->format.RGBToColor(0xFF, 0xFF, 0xFF), false, &_info[index].surface->format); + CursorMan.replaceCursor(_info[index].surface->getPixels(), _info[index].surface->w, _info[index].surface->h, _info[index].hotspot.x, _info[index].hotspot.y, _info[index].surface->format.RGBToColor(0xFF, 0xFF, 0xFF), false, _info[index].surface->format); } } } diff --git a/engines/prince/cursor.cpp b/engines/prince/cursor.cpp index 596b468abb52..d4747f1dcb41 100644 --- a/engines/prince/cursor.cpp +++ b/engines/prince/cursor.cpp @@ -91,7 +91,7 @@ void PrinceEngine::changeCursor(uint16 curId) { curSurface->w, curSurface->h, 0, 0, 255, false, - &curSurface->format + curSurface->format ); CursorMan.showMouse(true); } diff --git a/engines/scumm/cursor.cpp b/engines/scumm/cursor.cpp index d0de41ab8ad6..66d23dc3434a 100644 --- a/engines/scumm/cursor.cpp +++ b/engines/scumm/cursor.cpp @@ -123,12 +123,13 @@ void ScummEngine::updateCursor() { _cursor.hotspotX, _cursor.hotspotY, (_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor), (_game.heversion == 70 ? true : false), - &format); + format); #else CursorMan.replaceCursor(_grabbedCursor, _cursor.width, _cursor.height, _cursor.hotspotX, _cursor.hotspotY, (_game.platform == Common::kPlatformNES ? _grabbedCursor[63] : transColor), - (_game.heversion == 70 ? true : false)); + (_game.heversion == 70 ? true : false), + Graphics::PixelFormat::createFormatCLUT8()); #endif } diff --git a/engines/sherlock/events.cpp b/engines/sherlock/events.cpp index 459dd4a785b9..f8093053764b 100644 --- a/engines/sherlock/events.cpp +++ b/engines/sherlock/events.cpp @@ -98,7 +98,7 @@ void Events::setCursor(const Graphics::Surface &src, int hotspotX, int hotspotY) // PC 8-bit palettized CursorMan.replaceCursor(src.getPixels(), src.w, src.h, hotspotX, hotspotY, 0xff); } else if (!_vm->_isScreenDoubled) { - CursorMan.replaceCursor(src.getPixels(), src.w, src.h, hotspotX, hotspotY, 0x0000, false, &src.format); + CursorMan.replaceCursor(src.getPixels(), src.w, src.h, hotspotX, hotspotY, 0x0000, false, src.format); } else { Graphics::Surface tempSurface; tempSurface.create(2 * src.w, 2 * src.h, src.format); @@ -115,7 +115,7 @@ void Events::setCursor(const Graphics::Surface &src, int hotspotX, int hotspotY) } // 3DO RGB565 - CursorMan.replaceCursor(tempSurface.getPixels(), tempSurface.w, tempSurface.h, 2 * hotspotX, 2 * hotspotY, 0x0000, false, &src.format); + CursorMan.replaceCursor(tempSurface.getPixels(), tempSurface.w, tempSurface.h, 2 * hotspotX, 2 * hotspotY, 0x0000, false, src.format); tempSurface.free(); } diff --git a/engines/sherlock/scalpel/scalpel.cpp b/engines/sherlock/scalpel/scalpel.cpp index cbd63fcc5498..ec2f9dc3504b 100644 --- a/engines/sherlock/scalpel/scalpel.cpp +++ b/engines/sherlock/scalpel/scalpel.cpp @@ -258,7 +258,7 @@ void ScalpelEngine::setupGraphics() { // First try for a 640x400 mode g_system->beginGFXTransaction(); initCommonGFX(); - g_system->initSize(640, 400, &pixelFormatRGB565); + g_system->initSize(640, 400, pixelFormatRGB565); OSystem::TransactionError gfxError = g_system->endGFXTransaction(); if (gfxError == OSystem::kTransactionSuccess) { diff --git a/engines/testbed/graphics.cpp b/engines/testbed/graphics.cpp index 83aa2915cea9..ac5cc03d2e8c 100644 --- a/engines/testbed/graphics.cpp +++ b/engines/testbed/graphics.cpp @@ -914,7 +914,7 @@ TestExitStatus GFXtests::scaledCursors() { g_system->beginGFXTransaction(); bool isGFXModeSet = g_system->setGraphicsMode(gfxMode->id); - g_system->initSize(320, 200); + g_system->initSize(320, 200, Graphics::PixelFormat::createFormatCLUT8()); OSystem::TransactionError gfxError = g_system->endGFXTransaction(); @@ -951,7 +951,7 @@ TestExitStatus GFXtests::scaledCursors() { g_system->beginGFXTransaction(); bool isGFXModeSet = g_system->setGraphicsMode(currGFXMode); - g_system->initSize(320, 200); + g_system->initSize(320, 200, Graphics::PixelFormat::createFormatCLUT8()); if (isAspectRatioCorrected) { g_system->setFeatureState(OSystem::kFeatureAspectRatioCorrection, true); @@ -1335,7 +1335,7 @@ TestExitStatus GFXtests::pixelFormats(Common::List &pfLis // Revert back to 8bpp g_system->beginGFXTransaction(); - g_system->initSize(320, 200); + g_system->initSize(320, 200, Graphics::PixelFormat::createFormatCLUT8()); g_system->endGFXTransaction(); GFXTestSuite::setCustomColor(255, 0, 0); initMousePalette(); @@ -1394,7 +1394,7 @@ void GFXtests::showPixelFormat(const Graphics::PixelFormat &pf, uint aLoss) { // Init screen and working with dstSurface g_system->beginGFXTransaction(); - g_system->initSize(320, 200, &pf); + g_system->initSize(320, 200, pf); OSystem::TransactionError gfxError = g_system->endGFXTransaction(); if (gfxError) { Testsuite::logPrintf("WARNING! Pixel Format %s is unsupported\n", pf.toString().c_str()); diff --git a/engines/titanic/support/mouse_cursor.cpp b/engines/titanic/support/mouse_cursor.cpp index bb88ea279f90..d9e449c9b42b 100644 --- a/engines/titanic/support/mouse_cursor.cpp +++ b/engines/titanic/support/mouse_cursor.cpp @@ -152,7 +152,7 @@ void CMouseCursor::setCursor(CursorId cursorId) { // Set the cursor CursorMan.replaceCursor(ce._surface->getPixels(), CURSOR_SIZE, CURSOR_SIZE, - ce._centroid.x, ce._centroid.y, 0, false, &ce._surface->format); + ce._centroid.x, ce._centroid.y, 0, false, ce._surface->format); } } diff --git a/engines/tony/game.cpp b/engines/tony/game.cpp index 2db4c7d4959a..00e1918cd074 100644 --- a/engines/tony/game.cpp +++ b/engines/tony/game.cpp @@ -1569,7 +1569,7 @@ void RMPointer::updateCursor() { // Get the raw pixel data and set the cursor to it Graphics::PixelFormat pixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0); - CursorMan.replaceCursor(cursorData, 64, 64, _cursorHotspot._x, _cursorHotspot._y, 0, 1, &pixelFormat); + CursorMan.replaceCursor(cursorData, 64, 64, _cursorHotspot._x, _cursorHotspot._y, 0, 1, pixelFormat); } /** diff --git a/engines/trecision/graphics.cpp b/engines/trecision/graphics.cpp index cfc7f5ed0caa..14941cb786b8 100644 --- a/engines/trecision/graphics.cpp +++ b/engines/trecision/graphics.cpp @@ -736,7 +736,7 @@ void GraphicsManager::initCursor() { cursor[cx + cw * i] = cursorColor; // vertical } - CursorMan.pushCursor(cursor, cw, ch, cx, cy, 0, false, &_screenFormat); + CursorMan.pushCursor(cursor, cw, ch, cx, cy, 0, false, _screenFormat); } void GraphicsManager::showCursor() { diff --git a/engines/ultima/ultima4/gfx/screen.cpp b/engines/ultima/ultima4/gfx/screen.cpp index 8d25c4357bc6..38b0dec8b8ac 100644 --- a/engines/ultima/ultima4/gfx/screen.cpp +++ b/engines/ultima/ultima4/gfx/screen.cpp @@ -160,7 +160,7 @@ void Screen::loadMouseCursors() { MouseCursorSurface *c = _mouseCursors[MC_DEFAULT]; CursorMan.pushCursor(c->getPixels(), MOUSE_CURSOR_SIZE, MOUSE_CURSOR_SIZE, - c->_hotspot.x, c->_hotspot.y, TRANSPARENT, false, &format); + c->_hotspot.x, c->_hotspot.y, TRANSPARENT, false, format); CursorMan.showMouse(true); } else { @@ -180,7 +180,7 @@ void Screen::setMouseCursor(MouseCursor cursor) { const uint TRANSPARENT = format.RGBToColor(0x80, 0x80, 0x80); CursorMan.replaceCursor(c->getPixels(), MOUSE_CURSOR_SIZE, MOUSE_CURSOR_SIZE, - c->_hotspot.x, c->_hotspot.y, TRANSPARENT, false, &format); + c->_hotspot.x, c->_hotspot.y, TRANSPARENT, false, format); } } diff --git a/engines/zvision/graphics/cursors/cursor_manager.cpp b/engines/zvision/graphics/cursors/cursor_manager.cpp index 2c662721674a..6ae0fe7f4671 100644 --- a/engines/zvision/graphics/cursors/cursor_manager.cpp +++ b/engines/zvision/graphics/cursors/cursor_manager.cpp @@ -110,7 +110,7 @@ void CursorManager::initialize() { } void CursorManager::changeCursor(const ZorkCursor &cursor) { - CursorMan.replaceCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, &_pixelFormat); + CursorMan.replaceCursor(cursor.getSurface(), cursor.getWidth(), cursor.getHeight(), cursor.getHotspotX(), cursor.getHotspotY(), cursor.getKeyColor(), false, _pixelFormat); } void CursorManager::cursorDown(bool pushed) { diff --git a/graphics/cursorman.cpp b/graphics/cursorman.cpp index d9eff1bf4fc4..23f0d76362e2 100644 --- a/graphics/cursorman.cpp +++ b/graphics/cursorman.cpp @@ -58,7 +58,7 @@ bool CursorManager::showMouse(bool visible) { return g_system->showMouse(visible); } -void CursorManager::pushCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void CursorManager::pushCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { Cursor *cur = new Cursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format); cur->_visible = isVisible(); @@ -76,9 +76,9 @@ void CursorManager::popCursor() { if (!_cursorStack.empty()) { cur = _cursorStack.top(); - g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_dontScale, &cur->_format); + g_system->setMouseCursor(cur->_data, cur->_width, cur->_height, cur->_hotspotX, cur->_hotspotY, cur->_keycolor, cur->_dontScale, cur->_format); } else { - g_system->setMouseCursor(nullptr, 0, 0, 0, 0, 0); + g_system->setMouseCursor(nullptr, 0, 0, 0, 0, 0, false, Graphics::PixelFormat::createFormatCLUT8()); } g_system->showMouse(isVisible()); @@ -98,11 +98,11 @@ void CursorManager::popAllCursors() { } } - g_system->setMouseCursor(nullptr, 0, 0, 0, 0, 0); + g_system->setMouseCursor(nullptr, 0, 0, 0, 0, 0, false, Graphics::PixelFormat::createFormatCLUT8()); g_system->showMouse(isVisible()); } -void CursorManager::replaceCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +void CursorManager::replaceCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { if (_cursorStack.empty()) { pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format); @@ -112,11 +112,7 @@ void CursorManager::replaceCursor(const void *buf, uint w, uint h, int hotspotX, Cursor *cur = _cursorStack.top(); #ifdef USE_RGB_COLOR - uint size; - if (!format) - size = w * h; - else - size = w * h * format->bytesPerPixel; + uint size = w * h * format.bytesPerPixel; #else uint size = w * h; #endif @@ -137,10 +133,7 @@ void CursorManager::replaceCursor(const void *buf, uint w, uint h, int hotspotX, cur->_keycolor = keycolor; cur->_dontScale = dontScale; #ifdef USE_RGB_COLOR - if (format) - cur->_format = *format; - else - cur->_format = Graphics::PixelFormat::createFormatCLUT8(); + cur->_format = format; #endif g_system->setMouseCursor(cur->_data, w, h, hotspotX, hotspotY, keycolor, dontScale, format); @@ -241,12 +234,9 @@ void CursorManager::lock(bool locked) { _locked = locked; } -CursorManager::Cursor::Cursor(const void *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) { +CursorManager::Cursor::Cursor(const void *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format) { #ifdef USE_RGB_COLOR - if (!format) - _format = Graphics::PixelFormat::createFormatCLUT8(); - else - _format = *format; + _format = format; _size = w * h * _format.bytesPerPixel; const uint32 keycolor_mask = (((uint32) -1) >> (sizeof(uint32) * 8 - _format.bytesPerPixel * 8)); _keycolor = keycolor & keycolor_mask; diff --git a/graphics/cursorman.h b/graphics/cursorman.h index de0fe2fbeb87..88090c3476cc 100644 --- a/graphics/cursorman.h +++ b/graphics/cursorman.h @@ -76,14 +76,17 @@ class CursorManager : public Common::Singleton { * the maximum color value as defined by format. * @param dontScale Whether the cursor should never be scaled. An exception are high PPI displays, where the cursor * would be too small to notice otherwise. These are allowed to scale the cursor anyway. - * @param format Pointer to the pixel format that the cursor graphic uses. - * CLUT8 will be used if this is null or not specified. + * @param format The pixel format that the cursor graphic uses. * * @note It is acceptable for the buffer to be a null pointer. It is sometimes * useful to push a "dummy" cursor and modify it later. The * cursor will be added to the stack, but not to the backend. */ - void pushCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL); + void pushCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); + + void pushCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false) { + pushCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, Graphics::PixelFormat::createFormatCLUT8()); + } /** * Pop a cursor from the stack, and restore the previous one to the @@ -108,10 +111,13 @@ class CursorManager : public Common::Singleton { * the maximum color value as defined by format. * @param dontScale Whether the cursor should never be scaled. An exception are high PPI displays, where the cursor * would be too small to notice otherwise. These are allowed to scale the cursor anyway. - * @param format Pointer to the pixel format that the cursor graphic uses, - * CLUT8 will be used if this is null or not specified. + * @param format The pixel format that the cursor graphic uses. */ - void replaceCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL); + void replaceCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); + + void replaceCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false) { + replaceCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, Graphics::PixelFormat::createFormatCLUT8()); + } /** * Replace the current cursor on the stack. @@ -225,7 +231,7 @@ class CursorManager : public Common::Singleton { // _format set to default by Graphics::PixelFormat default constructor Cursor() : _data(0), _visible(false), _width(0), _height(0), _hotspotX(0), _hotspotY(0), _keycolor(0), _dontScale(false), _size(0) {} - Cursor(const void *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL); + Cursor(const void *data, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat &format); ~Cursor(); }; diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 089e3b5edcc8..efe9d8210e14 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -403,7 +403,7 @@ void ThemeEngine::refresh() { #ifndef USE_RGB_COLOR CursorMan.replaceCursorPalette(_cursorPal, 0, _cursorPalSize); #endif - CursorMan.replaceCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, _cursorTransparent, true, &_cursorFormat); + CursorMan.replaceCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, _cursorTransparent, true, _cursorFormat); } } } @@ -2069,7 +2069,7 @@ void ThemeEngine::showCursor() { #ifndef USE_RGB_COLOR CursorMan.pushCursorPalette(_cursorPal, 0, _cursorPalSize); #endif - CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, _cursorTransparent, true, &_cursorFormat); + CursorMan.pushCursor(_cursor, _cursorWidth, _cursorHeight, _cursorHotspotX, _cursorHotspotY, _cursorTransparent, true, _cursorFormat); CursorMan.showMouse(true); } }