Skip to content

Commit

Permalink
Merge pull request #246 from lordhoto/osystem-void-buffers
Browse files Browse the repository at this point in the history
OSYSTEM: Use void buffers for screen/overlay/mouse buffers and proper pitch values for overlay code
  • Loading branch information
lordhoto committed Jun 20, 2012
2 parents 5a2e654 + aec9b9e commit 4fb9bce
Show file tree
Hide file tree
Showing 73 changed files with 306 additions and 291 deletions.
8 changes: 4 additions & 4 deletions backends/graphics/graphics.h
Expand Up @@ -60,7 +60,7 @@ class GraphicsManager : public PaletteManager {
virtual int16 getWidth() = 0;
virtual void setPalette(const byte *colors, uint start, uint num) = 0;
virtual void grabPalette(byte *colors, uint start, uint num) = 0;
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) = 0;
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) = 0;
virtual Graphics::Surface *lockScreen() = 0;
virtual void unlockScreen() = 0;
virtual void fillScreen(uint32 col) = 0;
Expand All @@ -73,14 +73,14 @@ class GraphicsManager : public PaletteManager {
virtual void hideOverlay() = 0;
virtual Graphics::PixelFormat getOverlayFormat() const = 0;
virtual void clearOverlay() = 0;
virtual void grabOverlay(OverlayColor *buf, int pitch) = 0;
virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h)= 0;
virtual void grabOverlay(void *buf, int pitch) = 0;
virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h)= 0;
virtual int16 getOverlayHeight() = 0;
virtual int16 getOverlayWidth() = 0;

virtual bool showMouse(bool visible) = 0;
virtual void warpMouse(int x, int y) = 0;
virtual void setMouseCursor(const byte *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 = false, const Graphics::PixelFormat *format = NULL) = 0;
virtual void setCursorPalette(const byte *colors, uint start, uint num) = 0;

virtual void displayMessageOnOSD(const char *msg) {}
Expand Down
8 changes: 4 additions & 4 deletions backends/graphics/null/null-graphics.h
Expand Up @@ -58,7 +58,7 @@ class NullGraphicsManager : public GraphicsManager {
int16 getWidth() { return 0; }
void setPalette(const byte *colors, uint start, uint num) {}
void grabPalette(byte *colors, uint start, uint num) {}
void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {}
void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {}
Graphics::Surface *lockScreen() { return NULL; }
void unlockScreen() {}
void fillScreen(uint32 col) {}
Expand All @@ -71,14 +71,14 @@ class NullGraphicsManager : public GraphicsManager {
void hideOverlay() {}
Graphics::PixelFormat getOverlayFormat() const { return Graphics::PixelFormat(); }
void clearOverlay() {}
void grabOverlay(OverlayColor *buf, int pitch) {}
void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {}
void grabOverlay(void *buf, int pitch) {}
void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {}
int16 getOverlayHeight() { return 0; }
int16 getOverlayWidth() { return 0; }

bool showMouse(bool visible) { return !visible; }
void warpMouse(int x, int y) {}
void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) {}
void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale = false, const Graphics::PixelFormat *format = NULL) {}
void setCursorPalette(const byte *colors, uint start, uint num) {}
};

Expand Down
25 changes: 13 additions & 12 deletions backends/graphics/opengl/opengl-graphics.cpp
Expand Up @@ -349,14 +349,14 @@ void OpenGLGraphicsManager::grabPalette(byte *colors, uint start, uint num) {
memcpy(colors, _gamePalette + start * 3, num * 3);
}

void OpenGLGraphicsManager::copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) {
void OpenGLGraphicsManager::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
assert(x >= 0 && x < _screenData.w);
assert(y >= 0 && y < _screenData.h);
assert(h > 0 && y + h <= _screenData.h);
assert(w > 0 && x + w <= _screenData.w);

// Copy buffer data to game screen internal buffer
const byte *src = buf;
const byte *src = (const byte *)buf;
byte *dst = (byte *)_screenData.pixels + y * _screenData.pitch + x * _screenData.format.bytesPerPixel;
for (int i = 0; i < h; i++) {
memcpy(dst, src, w * _screenData.format.bytesPerPixel);
Expand Down Expand Up @@ -467,33 +467,35 @@ void OpenGLGraphicsManager::clearOverlay() {
_overlayNeedsRedraw = true;
}

void OpenGLGraphicsManager::grabOverlay(OverlayColor *buf, int pitch) {
assert(_overlayData.format.bytesPerPixel == sizeof(buf[0]));
void OpenGLGraphicsManager::grabOverlay(void *buf, int pitch) {
const byte *src = (byte *)_overlayData.pixels;
byte *dst = (byte *)buf;
for (int i = 0; i < _overlayData.h; i++) {
// Copy overlay data to buffer
memcpy(buf, src, _overlayData.pitch);
buf += pitch;
memcpy(dst, src, _overlayData.pitch);
dst += pitch;
src += _overlayData.pitch;
}
}

void OpenGLGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
void OpenGLGraphicsManager::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
assert(_transactionMode == kTransactionNone);

if (_overlayTexture == NULL)
return;

const byte *src = (const byte *)buf;

// Clip the coordinates
if (x < 0) {
w += x;
buf -= x;
src -= x * 2;
x = 0;
}

if (y < 0) {
h += y;
buf -= y * pitch;
src -= y * pitch;
y = 0;
}

Expand All @@ -507,11 +509,10 @@ void OpenGLGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch
return;

// Copy buffer data to internal overlay surface
const byte *src = (const byte *)buf;
byte *dst = (byte *)_overlayData.pixels + y * _overlayData.pitch;
for (int i = 0; i < h; i++) {
memcpy(dst + x * _overlayData.format.bytesPerPixel, src, w * _overlayData.format.bytesPerPixel);
src += pitch * sizeof(buf[0]);
src += pitch;
dst += _overlayData.pitch;
}

Expand Down Expand Up @@ -591,7 +592,7 @@ void OpenGLGraphicsManager::warpMouse(int x, int y) {
setInternalMousePosition(scaledX, scaledY);
}

void OpenGLGraphicsManager::setMouseCursor(const byte *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) {
#ifdef USE_RGB_COLOR
if (format)
_cursorFormat = *format;
Expand Down
8 changes: 4 additions & 4 deletions backends/graphics/opengl/opengl-graphics.h
Expand Up @@ -84,7 +84,7 @@ class OpenGLGraphicsManager : public GraphicsManager {
virtual void grabPalette(byte *colors, uint start, uint num);

public:
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();
virtual void fillScreen(uint32 col);
Expand All @@ -97,14 +97,14 @@ class OpenGLGraphicsManager : public GraphicsManager {
virtual void hideOverlay();
virtual Graphics::PixelFormat getOverlayFormat() const;
virtual void clearOverlay();
virtual void grabOverlay(OverlayColor *buf, int pitch);
virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
virtual void grabOverlay(void *buf, int pitch);
virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
virtual int16 getOverlayHeight();
virtual int16 getOverlayWidth();

virtual bool showMouse(bool visible);
virtual void warpMouse(int x, int y);
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, 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 = false, const Graphics::PixelFormat *format = NULL);
virtual void setCursorPalette(const byte *colors, uint start, uint num);

virtual void displayMessageOnOSD(const char *msg);
Expand Down
32 changes: 19 additions & 13 deletions backends/graphics/surfacesdl/surfacesdl-graphics.cpp
Expand Up @@ -1227,9 +1227,9 @@ void SurfaceSdlGraphicsManager::setAspectRatioCorrection(bool enable) {
}
}

void SurfaceSdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) {
void SurfaceSdlGraphicsManager::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
assert(_transactionMode == kTransactionNone);
assert(src);
assert(buf);

if (_screen == NULL) {
warning("SurfaceSdlGraphicsManager::copyRectToScreen: _screen == NULL");
Expand All @@ -1252,8 +1252,9 @@ void SurfaceSdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int
#ifdef USE_RGB_COLOR
byte *dst = (byte *)_screen->pixels + y * _screen->pitch + x * _screenFormat.bytesPerPixel;
if (_videoMode.screenWidth == w && pitch == _screen->pitch) {
memcpy(dst, src, h*pitch);
memcpy(dst, buf, h*pitch);
} else {
const byte *src = (const byte *)buf;
do {
memcpy(dst, src, w * _screenFormat.bytesPerPixel);
src += pitch;
Expand All @@ -1263,8 +1264,9 @@ void SurfaceSdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int
#else
byte *dst = (byte *)_screen->pixels + y * _screen->pitch + x;
if (_screen->pitch == pitch && pitch == w) {
memcpy(dst, src, h*w);
memcpy(dst, buf, h*w);
} else {
const byte *src = (const byte *)buf;
do {
memcpy(dst, src, w);
src += pitch;
Expand Down Expand Up @@ -1595,7 +1597,7 @@ void SurfaceSdlGraphicsManager::clearOverlay() {
_forceFull = true;
}

void SurfaceSdlGraphicsManager::grabOverlay(OverlayColor *buf, int pitch) {
void SurfaceSdlGraphicsManager::grabOverlay(void *buf, int pitch) {
assert(_transactionMode == kTransactionNone);

if (_overlayscreen == NULL)
Expand All @@ -1605,31 +1607,35 @@ void SurfaceSdlGraphicsManager::grabOverlay(OverlayColor *buf, int pitch) {
error("SDL_LockSurface failed: %s", SDL_GetError());

byte *src = (byte *)_overlayscreen->pixels;
byte *dst = (byte *)buf;
int h = _videoMode.overlayHeight;
do {
memcpy(buf, src, _videoMode.overlayWidth * 2);
memcpy(dst, src, _videoMode.overlayWidth * 2);
src += _overlayscreen->pitch;
buf += pitch;
dst += pitch;
} while (--h);

SDL_UnlockSurface(_overlayscreen);
}

void SurfaceSdlGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
void SurfaceSdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
assert(_transactionMode == kTransactionNone);

if (_overlayscreen == NULL)
return;

const byte *src = (const byte *)buf;

// Clip the coordinates
if (x < 0) {
w += x;
buf -= x;
src -= x * 2;
x = 0;
}

if (y < 0) {
h += y; buf -= y * pitch;
h += y;
src -= y * pitch;
y = 0;
}

Expand All @@ -1652,9 +1658,9 @@ void SurfaceSdlGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int p

byte *dst = (byte *)_overlayscreen->pixels + y * _overlayscreen->pitch + x * 2;
do {
memcpy(dst, buf, w * 2);
memcpy(dst, src, w * 2);
dst += _overlayscreen->pitch;
buf += pitch;
src += pitch;
} while (--h);

SDL_UnlockSurface(_overlayscreen);
Expand Down Expand Up @@ -1713,7 +1719,7 @@ void SurfaceSdlGraphicsManager::warpMouse(int x, int y) {
}
}

void SurfaceSdlGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
#ifdef USE_RGB_COLOR
if (!format)
_cursorFormat = Graphics::PixelFormat::createFormatCLUT8();
Expand Down
8 changes: 4 additions & 4 deletions backends/graphics/surfacesdl/surfacesdl-graphics.h
Expand Up @@ -111,7 +111,7 @@ class SurfaceSdlGraphicsManager : public GraphicsManager, public SdlGraphicsMana
virtual void grabPalette(byte *colors, uint start, uint num);

public:
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h);
virtual Graphics::Surface *lockScreen();
virtual void unlockScreen();
virtual void fillScreen(uint32 col);
Expand All @@ -124,14 +124,14 @@ class SurfaceSdlGraphicsManager : public GraphicsManager, public SdlGraphicsMana
virtual void hideOverlay();
virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; }
virtual void clearOverlay();
virtual void grabOverlay(OverlayColor *buf, int pitch);
virtual void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
virtual void grabOverlay(void *buf, int pitch);
virtual void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
virtual int16 getOverlayHeight() { return _videoMode.overlayHeight; }
virtual int16 getOverlayWidth() { return _videoMode.overlayWidth; }

virtual bool showMouse(bool visible);
virtual void warpMouse(int x, int y);
virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, 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 = false, const Graphics::PixelFormat *format = NULL);
virtual void setCursorPalette(const byte *colors, uint start, uint num);

#ifdef USE_OSD
Expand Down
19 changes: 11 additions & 8 deletions backends/graphics/wincesdl/wincesdl-graphics.cpp
Expand Up @@ -1023,22 +1023,24 @@ bool WINCESdlGraphicsManager::saveScreenshot(const char *filename) {
return true;
}

void WINCESdlGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h) {
void WINCESdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
assert(_transactionMode == kTransactionNone);

if (_overlayscreen == NULL)
return;

const byte *src = (const byte *)buf;

// Clip the coordinates
if (x < 0) {
w += x;
buf -= x;
src -= x * 2;
x = 0;
}

if (y < 0) {
h += y;
buf -= y * pitch;
src -= y * pitch;
y = 0;
}

Expand All @@ -1063,23 +1065,24 @@ void WINCESdlGraphicsManager::copyRectToOverlay(const OverlayColor *buf, int pit

byte *dst = (byte *)_overlayscreen->pixels + y * _overlayscreen->pitch + x * 2;
do {
memcpy(dst, buf, w * 2);
memcpy(dst, src, w * 2);
dst += _overlayscreen->pitch;
buf += pitch;
src += pitch;
} while (--h);

SDL_UnlockSurface(_overlayscreen);
}

void WINCESdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) {
void WINCESdlGraphicsManager::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
assert(_transactionMode == kTransactionNone);
assert(src);
assert(buf);

if (_screen == NULL)
return;

Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends

const byte *src = (const byte *)buf;
/* Clip the coordinates */
if (x < 0) {
w += x;
Expand Down Expand Up @@ -1128,7 +1131,7 @@ void WINCESdlGraphicsManager::copyRectToScreen(const byte *src, int pitch, int x
SDL_UnlockSurface(_screen);
}

void WINCESdlGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
void WINCESdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {

undrawMouse();
if (w == 0 || h == 0)
Expand Down
6 changes: 3 additions & 3 deletions backends/graphics/wincesdl/wincesdl-graphics.h
Expand Up @@ -73,9 +73,9 @@ class WINCESdlGraphicsManager : public SurfaceSdlGraphicsManager {
void internDrawMouse();
void undrawMouse();
bool showMouse(bool visible);
void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format); // overloaded by CE backend
void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h); // overloaded by CE backend (FIXME)
void setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format); // overloaded by CE backend
void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h);
void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h); // overloaded by CE backend (FIXME)
Graphics::Surface *lockScreen();
void unlockScreen();
void blitCursor();
Expand Down

0 comments on commit 4fb9bce

Please sign in to comment.