Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMMON: Use a reference to Graphics::PixelFormat in OSystem functions #3879

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/graphics/gph/gph-graphics.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/gph/gph-graphics.h
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/graphics.h
Expand Up @@ -72,7 +72,7 @@ class GraphicsManager : public PaletteManager {
virtual Graphics::PixelFormat getScreenFormat() const = 0;
virtual Common::List<Graphics::PixelFormat> 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;

Expand Down Expand Up @@ -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) {}
Expand Down
6 changes: 3 additions & 3 deletions backends/graphics/null/null-graphics.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 4 additions & 19 deletions backends/graphics/opengl/opengl-graphics.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/opengl/opengl-graphics.h
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/openglsdl/openglsdl-graphics.cpp
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics/openglsdl/openglsdl-graphics.h
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/sdl/sdl-graphics.cpp
Expand Up @@ -86,9 +86,9 @@ bool SdlGraphicsManager::setState(const State &state) {
Common::List<Graphics::PixelFormat> 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);
Expand Down
35 changes: 12 additions & 23 deletions backends/graphics/surfacesdl/surfacesdl-graphics.cpp
Expand Up @@ -692,19 +692,15 @@ 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;
_gameScreenShakeYOffset = 0;

#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);

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<void *>(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<void *>(buf), w, h, format.bytesPerPixel * 8, w * format.bytesPerPixel, rMask, gMask, bMask, aMask);
} else {
assert(!_mouseOrigSurface);

Expand Down
4 changes: 2 additions & 2 deletions backends/graphics/surfacesdl/surfacesdl-graphics.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions backends/graphics3d/android/android-graphics3d.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand All @@ -757,15 +754,15 @@ 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)
for (uint16 x = 0; x < w; ++x, d++)
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)
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics3d/android/android-graphics3d.h
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backends/graphics3d/openglsdl/openglsdl-graphics3d.cpp
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions backends/graphics3d/openglsdl/openglsdl-graphics3d.h
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions backends/modular-backend.cpp
Expand Up @@ -137,7 +137,7 @@ Common::List<Graphics::PixelFormat> 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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions backends/modular-backend.h
Expand Up @@ -85,7 +85,7 @@ class ModularGraphicsBackend : virtual public BaseBackend {
Graphics::PixelFormat getScreenFormat() const override final;
Common::List<Graphics::PixelFormat> 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;

Expand Down Expand Up @@ -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;

Expand Down