aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl
diff options
context:
space:
mode:
authorMax Horn2007-06-19 22:39:59 +0000
committerMax Horn2007-06-19 22:39:59 +0000
commitb51f2f3212ae8a5abbdce4d947ec2d1cad1a0b6f (patch)
tree45a838924ce55038021cd3c3d8760e80ff630f38 /backends/platform/sdl
parentab9b9a1bf362e68f5f6a69462ef2b7c146e6e08f (diff)
downloadscummvm-rg350-b51f2f3212ae8a5abbdce4d947ec2d1cad1a0b6f.tar.gz
scummvm-rg350-b51f2f3212ae8a5abbdce4d947ec2d1cad1a0b6f.tar.bz2
scummvm-rg350-b51f2f3212ae8a5abbdce4d947ec2d1cad1a0b6f.zip
Implemented the OSystem framebuffer API, as discussed on scummvm-devel. All changes are just fine, and won't cause any compile problems or regressions, despite the fact that I can't test most of the non-SDL backend changes, at an improbability level of two to the power of two hundred and seventy-six thousand to one against - possibly much higher. Anything you still can't cope with is therefore your own problem. Please relax.
svn-id: r27548
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r--backends/platform/sdl/graphics.cpp50
-rw-r--r--backends/platform/sdl/sdl-common.h12
-rw-r--r--backends/platform/sdl/sdl.cpp1
3 files changed, 35 insertions, 28 deletions
diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp
index e0b7de28ab..f93c806aa8 100644
--- a/backends/platform/sdl/graphics.cpp
+++ b/backends/platform/sdl/graphics.cpp
@@ -761,22 +761,6 @@ void OSystem_SDL::setAspectRatioCorrection(bool enable) {
}
}
-void OSystem_SDL::clearScreen() {
- assert (_transactionMode == kTransactionNone);
-
- // Try to lock the screen surface
- if (SDL_LockSurface(_screen) == -1)
- error("SDL_LockSurface failed: %s", SDL_GetError());
-
- byte *dst = (byte *)_screen->pixels;
-
- // Clear the screen
- memset(dst, 0, _screenWidth * _screenHeight);
-
- // Unlock the screen surface
- SDL_UnlockSurface(_screen);
-}
-
void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) {
assert (_transactionMode == kTransactionNone);
assert(src);
@@ -848,24 +832,44 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int
SDL_UnlockSurface(_screen);
}
-bool OSystem_SDL::grabRawScreen(Graphics::Surface *surf) {
- assert(_screen);
- assert(surf);
+Graphics::Surface *OSystem_SDL::lockScreen() {
+ assert (_transactionMode == kTransactionNone);
- Common::StackLock lock(_graphicsMutex); // Lock the mutex until this function ends
+ // Lock the graphics mutex
+ lockMutex(_graphicsMutex);
- surf->create(_screenWidth, _screenHeight, _screen->format->BytesPerPixel);
+ // paranoia check
+ assert(!_screenIsLocked);
+ _screenIsLocked = true;
// Try to lock the screen surface
if (SDL_LockSurface(_screen) == -1)
error("SDL_LockSurface failed: %s", SDL_GetError());
- memcpy(surf->pixels, _screen->pixels, _screenWidth * _screenHeight * _screen->format->BytesPerPixel);
+ _framebuffer.pixels = _screen->pixels;
+ _framebuffer.w = _screen->w;
+ _framebuffer.h = _screen->h;
+ _framebuffer.pitch = _screen->pitch;
+ _framebuffer.bytesPerPixel = 1;
+
+ return &_framebuffer;
+}
+
+void OSystem_SDL::unlockScreen() {
+ assert (_transactionMode == kTransactionNone);
+
+ // paranoia check
+ assert(_screenIsLocked);
+ _screenIsLocked = false;
// Unlock the screen surface
SDL_UnlockSurface(_screen);
- return true;
+ // Trigger a full screen update
+ _forceFull = true;
+
+ // Finally unlock the graphics mutex
+ unlockMutex(_graphicsMutex);
}
void OSystem_SDL::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) {
diff --git a/backends/platform/sdl/sdl-common.h b/backends/platform/sdl/sdl-common.h
index e66ca71e7f..4795b22a53 100644
--- a/backends/platform/sdl/sdl-common.h
+++ b/backends/platform/sdl/sdl-common.h
@@ -92,11 +92,8 @@ public:
// The screen will not be updated to reflect the new bitmap
virtual void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h); // overloaded by CE backend (FIXME)
- // Copies the screen to a buffer
- bool grabRawScreen(Graphics::Surface *surf);
-
- // Clear the screen
- void clearScreen();
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
// Update the dirty areas of the screen
void updateScreen();
@@ -218,6 +215,8 @@ protected:
// unseen game screen
SDL_Surface *_screen;
+
+ // TODO: We could get rid of the following two vars and just use _screen instead
int _screenWidth, _screenHeight;
// temporary screen (for scalers)
@@ -274,6 +273,9 @@ protected:
int _mode;
int _transactionMode;
bool _fullscreen;
+
+ bool _screenIsLocked;
+ Graphics::Surface _framebuffer;
/** Current video mode flags (see DF_* constants) */
uint32 _modeFlags;
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 0fe16e0520..fe78bd4236 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -243,6 +243,7 @@ OSystem_SDL::OSystem_SDL()
_savefile(0),
_mixer(0),
_timer(0),
+ _screenIsLocked(false),
_graphicsMutex(0), _transactionMode(kTransactionNone) {
// allocate palette storage