[Scummvm-cvs-logs] SF.net SVN: scummvm: [27548] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Jun 20 00:40:00 CEST 2007
Revision: 27548
http://scummvm.svn.sourceforge.net/scummvm/?rev=27548&view=rev
Author: fingolfin
Date: 2007-06-19 15:39:59 -0700 (Tue, 19 Jun 2007)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/trunk/backends/platform/PalmOS/Src/be_os5.h
scummvm/trunk/backends/platform/PalmOS/Src/os5_gfx.cpp
scummvm/trunk/backends/platform/dc/dc.h
scummvm/trunk/backends/platform/dc/display.cpp
scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp
scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.h
scummvm/trunk/backends/platform/gp2x/gp2x-common.h
scummvm/trunk/backends/platform/gp2x/graphics.cpp
scummvm/trunk/backends/platform/gp32/gp32_osys.cpp
scummvm/trunk/backends/platform/gp32/gp32_osys.h
scummvm/trunk/backends/platform/null/null.cpp
scummvm/trunk/backends/platform/ps2/Gs2dScreen.cpp
scummvm/trunk/backends/platform/ps2/Gs2dScreen.h
scummvm/trunk/backends/platform/ps2/systemps2.cpp
scummvm/trunk/backends/platform/ps2/systemps2.h
scummvm/trunk/backends/platform/psp/osys_psp.cpp
scummvm/trunk/backends/platform/psp/osys_psp.h
scummvm/trunk/backends/platform/sdl/graphics.cpp
scummvm/trunk/backends/platform/sdl/sdl-common.h
scummvm/trunk/backends/platform/sdl/sdl.cpp
scummvm/trunk/backends/platform/wince/wince-sdl.cpp
scummvm/trunk/backends/platform/wince/wince-sdl.h
scummvm/trunk/common/system.cpp
scummvm/trunk/common/system.h
scummvm/trunk/engines/scumm/gfx.cpp
scummvm/trunk/graphics/scaler/thumbnail.cpp
Modified: scummvm/trunk/backends/platform/PalmOS/Src/be_os5.h
===================================================================
--- scummvm/trunk/backends/platform/PalmOS/Src/be_os5.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/PalmOS/Src/be_os5.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -110,6 +110,8 @@
typedef void (OSystem_PalmOS5::*RendererProc)(RectangleType &r, PointType &p);
RendererProc _render;
+ Graphics::Surface _framebuffer;
+
OverlayColor *_overlayP;
WinHandle _overlayH, _workScreenH;
int16 *_workScreenP;
@@ -168,7 +170,8 @@
void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
void clearScreen();
- bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
void setCursorPalette(const byte *colors, uint start, uint num);
void disableCursorPalette(bool disable);
Modified: scummvm/trunk/backends/platform/PalmOS/Src/os5_gfx.cpp
===================================================================
--- scummvm/trunk/backends/platform/PalmOS/Src/os5_gfx.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/PalmOS/Src/os5_gfx.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -219,15 +219,20 @@
}
}
-bool OSystem_PalmOS5::grabRawScreen(Graphics::Surface *surf) {
- assert(surf);
+Graphics::Surface *OSystem_PalmOS5::lockScreen() {
+ _framebuffer.pixels = _offScreenP;
+ _framebuffer.w = _screenWidth;
+ _framebuffer.h = _screenHeight;
+ _framebuffer.pitch = _screenWidth;
+ _framebuffer.bytesPerPixel = 1;
- surf->create(_screenWidth, _screenHeight, 1);
- MemMove(surf->pixels, _offScreenP, _screenWidth * _screenHeight);
-
- return true;
+ return &_framebuffer;
}
+void OSystem_PalmOS5::unlockScreen() {
+ // The screen is always completely update anyway, so we don't have to force a full update here.
+}
+
void OSystem_PalmOS5::int_updateScreen() {
RectangleType r;
PointType p;
Modified: scummvm/trunk/backends/platform/dc/dc.h
===================================================================
--- scummvm/trunk/backends/platform/dc/dc.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/dc/dc.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -81,8 +81,8 @@
// The screen will not be updated to reflect the new bitmap
void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
- // Copies the current screen contents to a new surface.
- bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
// Clear the screen to black.
void clearScreen();
@@ -213,6 +213,8 @@
void *ovl_tx[NUM_BUFFERS];
unsigned short palette[256], cursor_palette[256];
+ Graphics::Surface _framebuffer;
+
int temp_sound_buffer[RING_BUFFER_SAMPLES>>SOUND_BUFFER_SHIFT];
void checkSound();
Modified: scummvm/trunk/backends/platform/dc/display.cpp
===================================================================
--- scummvm/trunk/backends/platform/dc/display.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/dc/display.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -609,21 +609,26 @@
return 0;
}
-bool OSystem_Dreamcast::grabRawScreen(Graphics::Surface *surf)
+Graphics::Surface *OSystem_Dreamcast::lockScreen()
{
- if(!screen || !surf)
- return false;
+ if (!screen)
+ return 0;
- surf->create(_screen_w, _screen_h, 1);
- unsigned char *src = screen, *dst = (unsigned char *)surf->pixels;
- for(int h = _screen_h; h>0; --h) {
- memcpy(dst, src, _screen_w);
- src += SCREEN_W;
- dst += _screen_w;
- }
- return true;
+ _framebuffer.pixels = screen;
+ _framebuffer.w = _screen_w;
+ _framebuffer.h = _screen_h;
+ _framebuffer.pitch = SCREEN_W;
+ _framebuffer.bytesPerPixel = 1;
+
+ return &_framebuffer;
}
+void OSystem_Dreamcast::unlockScreen()
+{
+ // Force screen update
+ _screen_dirty = true;
+}
+
void OSystem_Dreamcast::clearScreen()
{
memset(screen, 0, SCREEN_W*SCREEN_H);
Modified: scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -474,8 +474,13 @@
}
}
-bool OSystem_DS::grabRawScreen(Graphics::Surface* surf) {
- surf->create(DS::getGameWidth(), DS::getGameHeight(), 1);
+Graphics::Surface *OSystem_DS::lockScreen() {
+ // For now, we create a full temporary screen surface, to which we copy the
+ // the screen content. Later unlockScreen will copy everything back.
+ // Not very nice nor efficient, but at least works, and is not worse
+ // than in the bad old times where we used grabRawScreen + copyRectToScreen.
+
+ _framebuffer.create(DS::getGameWidth(), DS::getGameHeight(), 1);
// Ensure we copy using 16 bit quantities due to limitation of VRAM addressing
@@ -486,13 +491,21 @@
DC_FlushRange(image + (y << 8), DS::getGameWidth());
for (int x = 0; x < DS::getGameWidth() >> 1; x++)
{
- *(((u16 *) (surf->pixels)) + y * (DS::getGameWidth() >> 1) + x) = image[y << 8 + x];
+ *(((u16 *) (_framebuffer.pixels)) + y * (DS::getGameWidth() >> 1) + x) = image[y << 8 + x];
}
}
- return true;
+ return &_framebuffer;
}
+void OSystem_DS::unlockScreen() {
+ // Copy temp framebuffer back to screen
+ copyRectToScreen((byte *)_framebuffer.pixels, _framebuffer.pitch, 0, 0, _framebuffer.w, _framebuffer.h);
+
+ // Free memory
+ _framebuffer.free();
+}
+
void OSystem_DS::setFocusRectangle(const Common::Rect& rect) {
DS::setTalkPos(rect.left + rect.width() / 2, rect.top + rect.height() / 2);
}
Modified: scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.h
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/ds/arm9/source/osystem_ds.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -53,6 +53,8 @@
DSAudioMixer* _mixer;
DSTimerManager* _timer;
+ Graphics::Surface _framebuffer;
+
static OSystem_DS* _instance;
typedef void (*SoundProc)(void *param, byte *buf, int len);
@@ -127,7 +129,8 @@
void addEvent(Common::Event& e);
bool isEventQueueEmpty() { return queuePos == 0; }
- virtual bool grabRawScreen(Graphics::Surface* surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
virtual void setFocusRectangle(const Common::Rect& rect);
Modified: scummvm/trunk/backends/platform/gp2x/gp2x-common.h
===================================================================
--- scummvm/trunk/backends/platform/gp2x/gp2x-common.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/gp2x/gp2x-common.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -90,12 +90,9 @@
// The screen will not be updated to reflect the new bitmap
void copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h);
- // Copies the screen to a buffer
- bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
- // Clear the screen
- void clearScreen();
-
// Update the dirty areas of the screen
void updateScreen();
Modified: scummvm/trunk/backends/platform/gp2x/graphics.cpp
===================================================================
--- scummvm/trunk/backends/platform/gp2x/graphics.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/gp2x/graphics.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -687,22 +687,6 @@
}
}
-void OSystem_GP2X::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_GP2X::copyRectToScreen(const byte *src, int pitch, int x, int y, int w, int h) {
assert (_transactionMode == kTransactionNone);
assert(src);
@@ -772,15 +756,19 @@
SDL_UnlockSurface(_screen);
}
-// TIDY: DIRTY HACK: Try a REALLY simple version of grabRawScreen to
-// debug why it will not work on the GP2X.
-bool OSystem_GP2X::grabRawScreen(Graphics::Surface *surf) {
- assert(surf);
+Graphics::Surface *OSystem_GP2X::lockScreen() {
+ _framebuffer.pixels = _screen->pixels;
+ _framebuffer.w = _screen->w;
+ _framebuffer.h = _screen->h;
+ _framebuffer.pitch = _screen->pitch;
+ _framebuffer.bytesPerPixel = 1;
- surf->create(_screenWidth, _screenHeight, 1);
- memcpy(surf->pixels, _screen->pixels, _screenWidth * _screenHeight);
+ return &_framebuffer;
+}
- return true;
+void OSystem_GP2X::unlockScreen() {
+ // Force screen update
+ _forceFull = true;
}
void OSystem_GP2X::addDirtyRect(int x, int y, int w, int h, bool realCoordinates) {
Modified: scummvm/trunk/backends/platform/gp32/gp32_osys.cpp
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32_osys.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/gp32/gp32_osys.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -209,14 +209,18 @@
}
}
-bool OSystem_GP32::grabRawScreen(Graphics::Surface *surf) {
- assert(surf);
+Graphics::Surface *OSystem_GP32::lockScreen() {
+ _framebuffer.pixels = _gameScreen;
+ _framebuffer.w = _screenWidth;
+ _framebuffer.h = _screenHeight;
+ _framebuffer.pitch = _screenWidth;
+ _framebuffer.bytesPerPixel = 1;
- surf->create(_screenWidth, _screenHeight, 1);
+ return &_framebuffer;
+}
- memcpy(surf->pixels, _gameScreen, _screenWidth * _screenHeight);
-
- return true;
+void OSystem_GP32::unlockScreen() {
+ // The screen is always completely update anyway, so we don't have to force a full update here.
}
//TODO: Implement Dirty rect?
Modified: scummvm/trunk/backends/platform/gp32/gp32_osys.h
===================================================================
--- scummvm/trunk/backends/platform/gp32/gp32_osys.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/gp32/gp32_osys.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -49,6 +49,8 @@
uint16 *_tmpScreen, *_hwScreen;
OverlayColor *_overlayBuffer;
+ Graphics::Surface _framebuffer;
+
int _overlayWidth, _overlayHeight;
bool _overlayVisible;
uint32 _shakePos;
@@ -111,7 +113,8 @@
void grabOverlay(OverlayColor *buf, int pitch);
void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
- bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
int16 getOverlayHeight();
int16 getOverlayWidth();
Modified: scummvm/trunk/backends/platform/null/null.cpp
===================================================================
--- scummvm/trunk/backends/platform/null/null.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/null/null.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -63,7 +63,8 @@
virtual void grabPalette(byte *colors, uint start, uint num);
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
virtual void updateScreen();
- virtual bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
virtual void setShakePos(int shakeOffset);
virtual void showOverlay();
@@ -189,10 +190,13 @@
void OSystem_NULL::updateScreen() {
}
-bool OSystem_NULL::grabRawScreen(Graphics::Surface *surf) {
- return false;
+Graphics::Surface *OSystem_NULL::lockScreen() {
+ return 0;
}
+void OSystem_NULL::unlockScreen() {
+}
+
void OSystem_NULL::setShakePos(int shakeOffset) {
}
Modified: scummvm/trunk/backends/platform/ps2/Gs2dScreen.cpp
===================================================================
--- scummvm/trunk/backends/platform/ps2/Gs2dScreen.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/ps2/Gs2dScreen.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -364,13 +364,6 @@
}
}
-void Gs2dScreen::clearScreen(void) {
- WaitSema(g_DmacSema);
- memset(_screenBuf, 0, _width * _height);
- _screenChanged = true;
- SignalSema(g_DmacSema);
-}
-
void Gs2dScreen::setPalette(const uint32 *pal, uint8 start, uint16 num) {
assert(start + num <= 256);
@@ -393,11 +386,20 @@
}
}
-void Gs2dScreen::grabScreen(Graphics::Surface *surf) {
- assert(surf);
+Graphics::Surface *Gs2dScreen::lockScreen() {
WaitSema(g_DmacSema);
- surf->create(_width, _height, 1);
- memcpy(surf->pixels, _screenBuf, _width * _height);
+
+ _framebuffer.pixels = _screen->pixels;
+ _framebuffer.w = _screen->w;
+ _framebuffer.h = _screen->h;
+ _framebuffer.pitch = _screen->pitch;
+ _framebuffer.bytesPerPixel = 1;
+
+ return &_framebuffer;
+}
+
+void Gs2dScreen::unlockScreen() {
+ _screenChanged = true;
SignalSema(g_DmacSema);
}
Modified: scummvm/trunk/backends/platform/ps2/Gs2dScreen.h
===================================================================
--- scummvm/trunk/backends/platform/ps2/Gs2dScreen.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/ps2/Gs2dScreen.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -56,13 +56,13 @@
void copyPrintfOverlay(const uint8* buf);
void clearPrintfOverlay(void);
- void clearScreen(void);
void copyScreenRect(const uint8 *buf, int pitch, int x, int y, int w, int h);
void setPalette(const uint32 *pal, uint8 start, uint16 num);
void updateScreen(void);
void grabPalette(uint32 *pal, uint8 start, uint16 num);
- void grabScreen(Graphics::Surface *surf);
+ Graphics::Surface *lockScreen();
+ void unlockScreen();
//- overlay routines
void copyOverlayRect(const uint16 *buf, uint16 pitch, uint16 x, uint16 y, uint16 w, uint16 h);
void grabOverlay(uint16 *buf, uint16 pitch);
@@ -99,6 +99,8 @@
uint32 _mouseScaleX, _mouseScaleY;
uint8 _mTraCol;
+ Graphics::Surface _framebuffer;
+
int _shakePos;
bool _showMouse, _showOverlay, _screenChanged, _overlayChanged, _clutChanged;
Modified: scummvm/trunk/backends/platform/ps2/systemps2.cpp
===================================================================
--- scummvm/trunk/backends/platform/ps2/systemps2.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/ps2/systemps2.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -326,7 +326,7 @@
}
_screen->wantAnim(false);
- _screen->clearScreen();
+ clearScreen();
}
OSystem_PS2::~OSystem_PS2(void) {
@@ -510,11 +510,14 @@
_screen->copyScreenRect((const uint8*)buf, pitch, x, y, w, h);
}
-bool OSystem_PS2::grabRawScreen(Graphics::Surface *surf) {
- _screen->grabScreen(surf);
- return true;
+Graphics::Surface *OSystem_PS2::lockScreen() {
+ return _screen->lockScreen();
}
+void OSystem_PS2::unlockScreen() {
+ _screen->unlockScreen();
+}
+
void OSystem_PS2::updateScreen(void) {
if (_msgClearTime && (_msgClearTime < getMillis())) {
_screen->clearPrintfOverlay();
Modified: scummvm/trunk/backends/platform/ps2/systemps2.h
===================================================================
--- scummvm/trunk/backends/platform/ps2/systemps2.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/ps2/systemps2.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -56,7 +56,8 @@
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
virtual void setShakePos(int shakeOffset);
virtual void grabPalette(byte *colors, uint start, uint num);
- virtual bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
virtual void updateScreen();
virtual void showOverlay();
Modified: scummvm/trunk/backends/platform/psp/osys_psp.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/psp/osys_psp.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -209,15 +209,20 @@
}
}
-bool OSystem_PSP::grabRawScreen(Graphics::Surface *surf) {
- assert(surf);
+Graphics::Surface *OSystem_PSP::lockScreen() {
+ _framebuffer.pixels = _offscreen;
+ _framebuffer.w = _screenWidth;
+ _framebuffer.h = _screenHeight;
+ _framebuffer.pitch = _screenWidth;
+ _framebuffer.bytesPerPixel = 1;
- surf->create(_screenWidth, _screenHeight, 1);
- memcpy(surf->pixels, _offscreen, _screenWidth * _screenHeight);
-
- return true;
+ return &_framebuffer;
}
+void OSystem_PSP::unlockScreen() {
+ // The screen is always completely update anyway, so we don't have to force a full update here.
+}
+
void OSystem_PSP::updateScreen() {
unsigned short *temp;
Modified: scummvm/trunk/backends/platform/psp/osys_psp.h
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/psp/osys_psp.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -62,6 +62,7 @@
bool _overlayVisible;
uint32 _shakePos;
+ Graphics::Surface _framebuffer;
bool _mouseVisible;
int _mouseX, _mouseY;
@@ -101,7 +102,8 @@
virtual int16 getHeight();
virtual void setPalette(const byte *colors, uint start, uint num);
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h);
- virtual bool grabRawScreen(Graphics::Surface *surf);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
virtual void updateScreen();
virtual void setShakePos(int shakeOffset);
Modified: scummvm/trunk/backends/platform/sdl/graphics.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/graphics.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/sdl/graphics.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -761,22 +761,6 @@
}
}
-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 @@
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) {
Modified: scummvm/trunk/backends/platform/sdl/sdl-common.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl-common.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/sdl/sdl-common.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -92,12 +92,9 @@
// 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);
+ virtual Graphics::Surface *lockScreen();
+ virtual void unlockScreen();
- // Clear the screen
- void clearScreen();
-
// Update the dirty areas of the screen
void updateScreen();
@@ -218,6 +215,8 @@
// 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 @@
int _mode;
int _transactionMode;
bool _fullscreen;
+
+ bool _screenIsLocked;
+ Graphics::Surface _framebuffer;
/** Current video mode flags (see DF_* constants) */
uint32 _modeFlags;
Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -243,6 +243,7 @@
_savefile(0),
_mixer(0),
_timer(0),
+ _screenIsLocked(false),
_graphicsMutex(0), _transactionMode(kTransactionNone) {
// allocate palette storage
Modified: scummvm/trunk/backends/platform/wince/wince-sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/wince/wince-sdl.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/wince/wince-sdl.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -1587,11 +1587,17 @@
_forceFull = false;
}
-bool OSystem_WINCE3::grabRawScreen(Graphics::Surface *surf) {
+Graphics::Surface *OSystem_WINCE3::lockScreen() {
+ // FIXME: Fingolfing asks: Why is undrawMouse() needed here?
+ // Please document this.
undrawMouse();
- return OSystem_SDL::grabRawScreen(surf);
+ return OSystem_SDL::lockScreen();
}
+void OSystem_WINCE3::unlockScreen() {
+ OSystem_SDL::unlockScreen();
+}
+
bool OSystem_WINCE3::saveScreenshot(const char *filename) {
assert(_hwscreen != NULL);
Modified: scummvm/trunk/backends/platform/wince/wince-sdl.h
===================================================================
--- scummvm/trunk/backends/platform/wince/wince-sdl.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/backends/platform/wince/wince-sdl.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -97,7 +97,8 @@
void copyRectToOverlay(const OverlayColor *buf, int pitch, int x, int y, int w, int h);
void showOverlay();
void hideOverlay();
- bool grabRawScreen(Graphics::Surface *surf);
+ Graphics::Surface *lockScreen();
+ void unlockScreen();
// GUI and action stuff
void swap_panel_visibility();
Modified: scummvm/trunk/common/system.cpp
===================================================================
--- scummvm/trunk/common/system.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/common/system.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -101,3 +101,8 @@
return s_eventManager;
}
+void OSystem::clearScreen() {
+ Graphics::Surface *screen = lockScreen();
+ memset(screen->pixels, 0, screen->h * screen->pitch);
+ unlockScreen();
+}
Modified: scummvm/trunk/common/system.h
===================================================================
--- scummvm/trunk/common/system.h 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/common/system.h 2007-06-19 22:39:59 UTC (rev 27548)
@@ -452,21 +452,34 @@
virtual void copyRectToScreen(const byte *buf, int pitch, int x, int y, int w, int h) = 0;
/**
- * Copies the current screen contents to a new surface, with the original
- * bit depth. This will allocate memory for the pixel data.
- * WARNING: surf->free() must be called by the user to avoid leaking.
+ * Lock the active screen framebuffer and return a Graphics::Surface
+ * representing it. The caller can then perform arbitrary graphics
+ * transformations on the framebuffer (blitting, scrolling, etc.).
+ * Must be followed by matching call to unlockScreen(). Calling code
+ * should make sure to only lock the framebuffer for the briefest
+ * periods of time possible, as the whole system is potentially stalled
+ * while the lock is active.
+ * Returns 0 if an error occurred. Otherwise an 8bit surface is returned.
*
- * @param surf the surfce to store the data in it
- * @return true if all went well, false if an error occured
+ * The returned surface must *not* be deleted by the client code.
*/
- virtual bool grabRawScreen(Graphics::Surface *surf) = 0;
+ virtual Graphics::Surface *lockScreen() = 0;
/**
+ * Unlock the screen framebuffer, and mark it as dirty (i.e. during the
+ * next updateScreen() call, the whole screen will be updated.
+ */
+ virtual void unlockScreen() = 0;
+
+ /**
* Clear the screen to black.
*/
- virtual void clearScreen() {}
+ virtual void clearScreen();
- /** Update the dirty areas of the screen. */
+ /**
+ * Flush the whole screen, that is render the current content of the screen
+ * framebuffer (resp. the dirty/changed parts of it) to the display.
+ */
virtual void updateScreen() = 0;
/**
Modified: scummvm/trunk/engines/scumm/gfx.cpp
===================================================================
--- scummvm/trunk/engines/scumm/gfx.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/engines/scumm/gfx.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -1146,12 +1146,11 @@
if ((dx == 0 && dy == 0) || height <= 0)
return;
- Graphics::Surface screen;
- assert(_system->grabRawScreen(&screen));
-
- screen.move(dx, dy, height);
- _system->copyRectToScreen((byte *)screen.pixels, screen.pitch, 0, 0, screen.w, screen.h);
- screen.free();
+ Graphics::Surface *screen = _system->lockScreen();
+ if (!screen)
+ return;
+ screen->move(dx, dy, height);
+ _system->unlockScreen();
}
void ScummEngine_v5::clearFlashlight() {
Modified: scummvm/trunk/graphics/scaler/thumbnail.cpp
===================================================================
--- scummvm/trunk/graphics/scaler/thumbnail.cpp 2007-06-19 11:50:22 UTC (rev 27547)
+++ scummvm/trunk/graphics/scaler/thumbnail.cpp 2007-06-19 22:39:59 UTC (rev 27548)
@@ -97,32 +97,32 @@
* Copies the current screen contents to a new surface, using RGB565 format.
* WARNING: surf->free() must be called by the user to avoid leaking.
*
- * @param surf the surfce to store the data in it
+ * @param surf the surface to store the data in it
*/
static bool grabScreen565(Graphics::Surface *surf) {
- Graphics::Surface screen;
- if (!g_system->grabRawScreen(&screen))
+ Graphics::Surface *screen = g_system->lockScreen();
+ if (!screen)
return false;
- assert(screen.bytesPerPixel == 1 && screen.pixels != 0);
+ assert(screen->bytesPerPixel == 1 && screen->pixels != 0);
byte palette[256 * 4];
g_system->grabPalette(&palette[0], 0, 256);
- surf->create(screen.w, screen.h, 2);
+ surf->create(screen->w, screen->h, 2);
- for (uint y = 0; y < screen.h; ++y) {
- for (uint x = 0; x < screen.w; ++x) {
+ for (uint y = 0; y < screen->h; ++y) {
+ for (uint x = 0; x < screen->w; ++x) {
byte r, g, b;
- r = palette[((uint8*)screen.pixels)[y * screen.pitch + x] * 4];
- g = palette[((uint8*)screen.pixels)[y * screen.pitch + x] * 4 + 1];
- b = palette[((uint8*)screen.pixels)[y * screen.pitch + x] * 4 + 2];
+ r = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4];
+ g = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 1];
+ b = palette[((uint8*)screen->pixels)[y * screen->pitch + x] * 4 + 2];
((uint16*)surf->pixels)[y * surf->w + x] = (((r >> 3) & 0x1F) << 11) | (((g >> 2) & 0x3F) << 5) | ((b >> 3) & 0x1F);
}
}
- screen.free();
+ g_system->unlockScreen();
return true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list