diff options
| -rw-r--r-- | backends/sdl/graphics.cpp | 32 | ||||
| -rw-r--r-- | backends/sdl/sdl-common.h | 6 | ||||
| -rw-r--r-- | common/system.h | 24 | 
3 files changed, 62 insertions, 0 deletions
| diff --git a/backends/sdl/graphics.cpp b/backends/sdl/graphics.cpp index 658a1f3739..43e1a7cd4d 100644 --- a/backends/sdl/graphics.cpp +++ b/backends/sdl/graphics.cpp @@ -25,6 +25,7 @@  #include "common/util.h"  #include "graphics/font.h"  #include "graphics/fontman.h" +#include "graphics/surface.h"  static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {  	{"1x", "Normal (no scaling)", GFX_NORMAL}, @@ -821,6 +822,25 @@ 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); +	 +	Common::StackLock lock(_graphicsMutex);	// Lock the mutex until this function ends +	 +	surf->create(_screenWidth, _screenHeight, _screen->format->BytesPerPixel); +	 +	// 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); +	 +	// Unlock the screen surface +	SDL_UnlockSurface(_screen); +	 +	return true; +}  void OSystem_SDL::addDirtyRect(int x, int y, int w, int h, bool mouseRect) {  	if (_forceFull) @@ -1007,6 +1027,18 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) {  		blitCursor();  } +void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { +	assert(colors);	 +	const SDL_Color *base = _currentPalette + start; +	 +	for (uint i = 0; i < num; ++i) { +		colors[i * 4] = base[i].r; +		colors[i * 4 + 1] = base[i].g; +		colors[i * 4 + 2] = base[i].b; +		colors[i * 4 + 3] = 0xFF; +	} +} +  void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) {  	assert(colors);  	const byte *b = colors; diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h index 2d3337e0d5..a4265c6f31 100644 --- a/backends/sdl/sdl-common.h +++ b/backends/sdl/sdl-common.h @@ -80,11 +80,17 @@ public:  	// Set colors of the palette  	void setPalette(const byte *colors, uint start, uint num); +	 +	// Get colors of the palette +	void grabPalette(byte *colors, uint start, uint num);  	// Draw a bitmap to screen.  	// 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); +  	// Clear the screen  	void clearScreen(); diff --git a/common/system.h b/common/system.h index 262a88c3b9..63d50530ce 100644 --- a/common/system.h +++ b/common/system.h @@ -28,6 +28,10 @@  #include "common/rect.h"  #include "common/singleton.h" +namespace Graphics { +class Surface; +} // end of namespace Graphics +  class SaveFileManager;  /** @@ -361,6 +365,16 @@ public:  	 *       API are probably going to remove it.  	 */  	virtual void setPalette(const byte *colors, uint start, uint num) = 0; +	 +	/** +	 * Grabs a specified part of the currently active palette. +	 * The format is the same as for setPalette. +	 * +	 * @param buf	the buffer +	 * @param start	the first platte entry +	 * @param num	nummber of the entries +	 */ +	virtual void grabPalette(byte *colors, uint start, uint num) = 0;  	/**  	 * Blit a bitmap to the virtual screen. @@ -371,6 +385,16 @@ public:  	 * @see updateScreen  	 */  	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. +	 * +	 * @param surf	the surfce to store the data in it +	 * @return true if all went well, false if an error occured +	 */ +	virtual bool grabRawScreen(Graphics::Surface *surf) { return false; }  	/**  	 * Clear the screen to black. | 
