[Scummvm-cvs-logs] CVS: scummvm/backends/sdl fb2opengl.h,1.5,1.6 sdl.cpp,1.14,1.15 sdl_gl.cpp,1.15,1.16

Max Horn fingolfin at users.sourceforge.net
Fri Dec 13 08:17:05 CET 2002


Update of /cvsroot/scummvm/scummvm/backends/sdl
In directory sc8-pr-cvs1:/tmp/cvs-serv22013/backends/sdl

Modified Files:
	fb2opengl.h sdl.cpp sdl_gl.cpp 
Log Message:
changed OSystem to allow RBG<->16bit color conversion to be done in the backend; after all, the backend 'knows' best what format the overlay uses. Default implementations of RBGToColor and colorToRBG assume 565 mode, backends other than SDL may want to provide alternate implementations (SDL backend already does the right thing for non-565 modes)

Index: fb2opengl.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/fb2opengl.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- fb2opengl.h	29 Oct 2002 14:57:32 -0000	1.5
+++ fb2opengl.h	13 Dec 2002 16:15:38 -0000	1.6
@@ -22,8 +22,8 @@
 // Andre Souza <asouza at olinux.com.br>
 
 #include <SDL.h>
-//#include <SDL_opengl.h>
-#include <GL/gl.h>
+#include <SDL_opengl.h>
+//#include <GL/gl.h>	NOTE! Before anybody comments out SDL_opengl.h and enables this again, talk to Fingolfin first! GL/gl.h is NOT portable!
 #include <stdlib.h>
 #include <string.h>
 

Index: sdl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- sdl.cpp	8 Dec 2002 14:08:51 -0000	1.14
+++ sdl.cpp	13 Dec 2002 16:15:40 -0000	1.15
@@ -45,6 +45,10 @@
 	virtual void grab_overlay(int16 *buf, int pitch);
 	virtual void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h);
 
+	// Methods that convert RBG to/from colors suitable for the overlay.
+	virtual int16 RBGToColor(uint8 r, uint8 g, uint8 b);
+	virtual void colorToRBG(int16 color, uint8 &r, uint8 &g, uint8 &b);
+
 protected:
 	typedef void ScalerProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
 								uint8 *dstPtr, uint32 dstPitch, int width, int height);
@@ -153,7 +157,7 @@
 			*bak++ = *dst;
 			color = *src++;
 			if (color != 0xFF)	// 0xFF = transparent, don't draw
-				*dst = RGB_TO_16(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);
+				*dst = RBGToColor(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);
 			dst++;
 			width--;
 		}
@@ -466,14 +470,20 @@
 		}
 #endif
 		return 1;
-	} else if (param == PROP_OVERLAY_IS_565) {
-		assert(_tmpscreen != 0);
-		return (_tmpscreen->format->Rmask != 0x7C00);
 	}
 	
 	return OSystem_SDL_Common::property(param, value);
 }
 
+int16 OSystem_SDL_Normal::RBGToColor(uint8 r, uint8 g, uint8 b)
+{
+	return SDL_MapRGB(_tmpscreen->format, r, g, b);
+}
+
+void OSystem_SDL_Normal::colorToRBG(int16 color, uint8 &r, uint8 &g, uint8 &b)
+{
+	SDL_GetRGB(color, _tmpscreen->format, &r, &g, &b);
+}
 
 void OSystem_SDL_Normal::show_overlay()
 {

Index: sdl_gl.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl_gl.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- sdl_gl.cpp	13 Nov 2002 14:38:49 -0000	1.15
+++ sdl_gl.cpp	13 Dec 2002 16:15:45 -0000	1.16
@@ -34,7 +34,7 @@
 
 class OSystem_SDL_Normal : public OSystem_SDL_Common {
 public:
-	OSystem_SDL_Normal() : sdl_tmpscreen(0), sdl_hwscreen(0), _overlay_visible(false) { _glScreenStart = 0; _glBilinearFilter = true; }
+	OSystem_SDL_Normal() : _tmpscreen(0), _overlay_visible(false) { _glScreenStart = 0; _glBilinearFilter = true; }
 
 	// Set colors of the palette
 	void set_palette(const byte *colors, uint start, uint num);
@@ -63,12 +63,9 @@
 	typedef void ScalerProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr,
 								uint8 *dstPtr, uint32 dstPitch, int width, int height);
 
-	SDL_Surface *sdl_tmpscreen;   // temporary screen (for scalers/overlay)
-	SDL_Surface *sdl_hwscreen;    // hardware screen
+	SDL_Surface *_tmpscreen;   // temporary screen (for scalers/overlay)
 	bool _overlay_visible;
 
-	ScalerProc *_scaler_proc;
-
 	virtual void draw_mouse();
 	virtual void undraw_mouse();
 
@@ -148,17 +145,20 @@
 
 	// Draw the mouse cursor; backup the covered area in "bak"
 
-	if (SDL_LockSurface(sdl_tmpscreen) == -1)
+	if (SDL_LockSurface(_tmpscreen) == -1)
 		error("SDL_LockSurface failed: %s.\n", SDL_GetError());
 
-	dst = (uint16 *)sdl_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
+	// Mark as dirty
+	add_dirty_rect(x, y, w, h);
+
+	dst = (uint16 *)_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
 	while (h > 0) {
 		int width = w;
 		while (width > 0) {
 			*bak++ = *dst;
 			color = *src++;
 			if (color != 0xFF)	// 0xFF = transparent, don't draw
-				*dst = RGB_TO_16(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);
+				*dst = RBGToColor(_currentPalette[color].r, _currentPalette[color].g, _currentPalette[color].b);
 			dst++;
 			width--;
 		}
@@ -168,11 +168,8 @@
 		h--;
 	}
 
-	SDL_UnlockSurface(sdl_tmpscreen);
+	SDL_UnlockSurface(_tmpscreen);
 	
-	// Mark as dirty
-	add_dirty_rect(x, y, w, h);
-
 	// Finally, set the flag to indicate the mouse has been drawn
 	_mouseDrawn = true;
 }
@@ -186,7 +183,7 @@
 		return;
 	_mouseDrawn = false;
 
-	if (SDL_LockSurface(sdl_tmpscreen) == -1)
+	if (SDL_LockSurface(_tmpscreen) == -1)
 		error("SDL_LockSurface failed: %s.\n", SDL_GetError());
 
 	uint16 *dst, *bak = (uint16 *)_mouseBackup;
@@ -198,7 +195,7 @@
 
 	// No need to do clipping here, since draw_mouse() did that already
 
-	dst = (uint16 *)sdl_tmpscreen->pixels + (old_mouse_y+1) * TMP_SCREEN_WIDTH + (old_mouse_x+1);
+	dst = (uint16 *)_tmpscreen->pixels + (old_mouse_y+1) * TMP_SCREEN_WIDTH + (old_mouse_x+1);
 	for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += TMP_SCREEN_WIDTH) {
 		for (x = 0; x < old_mouse_w; ++x) {
 			dst[x] = bak[x];
@@ -207,7 +204,7 @@
 
 	add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h);
 
-	SDL_UnlockSurface(sdl_tmpscreen);
+	SDL_UnlockSurface(_tmpscreen);
 }
 
 void OSystem_SDL_Normal::load_gfx_mode() {
@@ -223,7 +220,7 @@
 	_mode_flags = DF_WANT_RECT_OPTIM | DF_UPDATE_EXPAND_1_PIXEL;
 	_scaleFactor = 2;
 
-	sdl_tmpscreen = NULL;
+	_tmpscreen = NULL;
 	TMP_SCREEN_WIDTH = (_screenWidth + 3);
 	
 	//
@@ -255,7 +252,7 @@
 
 	// Need some extra bytes around when using 2xSaI
 	uint16 *tmp_screen = (uint16*)calloc(TMP_SCREEN_WIDTH*(_screenHeight+3),sizeof(uint16));
-	sdl_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
+	_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen,
 						TMP_SCREEN_WIDTH, _screenHeight + 3, 16, TMP_SCREEN_WIDTH*2,
 						Rmask,
 						Gmask,
@@ -276,8 +273,8 @@
 	tmpBlackRect.w = _screenWidth;
 	tmpBlackRect.h = 256-_screenHeight-_glScreenStart;
 	
-	if (sdl_tmpscreen == NULL)
-		error("sdl_tmpscreen failed");
+	if (_tmpscreen == NULL)
+		error("_tmpscreen failed");
 	
 	// keyboard cursor control, some other better place for it?
 	km.x_max = _screenWidth * _scaleFactor - 1;
@@ -293,10 +290,10 @@
 		_screen = NULL; 
 	}
 
-	if (sdl_tmpscreen) {
-		free((uint16*)sdl_tmpscreen->pixels);
-		SDL_FreeSurface(sdl_tmpscreen);
-		sdl_tmpscreen = NULL;
+	if (_tmpscreen) {
+		free((uint16*)_tmpscreen->pixels);
+		SDL_FreeSurface(_tmpscreen);
+		_tmpscreen = NULL;
 	}
 }
 
@@ -352,13 +349,13 @@
 				dst = *r;
 //				dst.x++;	// Shift rect by one since 2xSai needs to acces the data around
 //				dst.y++;	// any pixel to scale it, and we want to avoid mem access crashes.
-				if (SDL_BlitSurface(_screen, r, sdl_tmpscreen, &dst) != 0)
+				if (SDL_BlitSurface(_screen, r, _tmpscreen, &dst) != 0)
 					error("SDL_BlitSurface failed: %s", SDL_GetError());
 			}
 		}
 
 		// Almost the same thing as SDL_UpdateRects
-		fb2gl.blit16(sdl_tmpscreen,_num_dirty_rects,_dirty_rect_list,0,
+		fb2gl.blit16(_tmpscreen,_num_dirty_rects,_dirty_rect_list,0,
 		    _currentShakePos+_glScreenStart);
 
 		tmpBlackRect.h = 256-_screenHeight-_glScreenStart-_currentShakePos;
@@ -403,9 +400,6 @@
 	
 		SDL_WM_ToggleFullScreen(fb2gl.screen);
 		return 1;
-	} else if (param == PROP_OVERLAY_IS_565) {
-		assert(sdl_tmpscreen != 0);
-		return (sdl_tmpscreen->format->Rmask != 0x7C00);
 	}
 	else if (param == PROP_SET_GFX_MODE) {
 		SDL_Rect full = {0,0,_screenWidth,_screenHeight};
@@ -455,7 +449,7 @@
 		      1.0+(double)(value->gfx_mode-1)/10,
 		      0);
 		};
-		fb2gl.blit16(sdl_tmpscreen,1,&full,0,_glScreenStart);
+		fb2gl.blit16(_tmpscreen,1,&full,0,_glScreenStart);
 		fb2gl.display();
 		
 		return 1;
@@ -499,7 +493,7 @@
 	dst.x = dst.y = 0;
 	src.w = dst.w = _screenWidth;
 	src.h = dst.h = _screenHeight;
-	if (SDL_BlitSurface(_screen, &src, sdl_tmpscreen, &dst) != 0)
+	if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0)
 		error("SDL_BlitSurface failed: %s", SDL_GetError());
 
 	_forceFull = true;
@@ -510,16 +504,16 @@
 	if (!_overlay_visible)
 		return;
 
-	if (sdl_tmpscreen == NULL)
+	if (_tmpscreen == NULL)
 		return;
 
 	// hide the mouse
 	undraw_mouse();
 
-	if (SDL_LockSurface(sdl_tmpscreen) == -1)
+	if (SDL_LockSurface(_tmpscreen) == -1)
 		error("SDL_LockSurface failed: %s.\n", SDL_GetError());
 
-	int16 *src = (int16 *)sdl_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1;
+	int16 *src = (int16 *)_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1;
 	int h = _screenHeight;
 	do {
 		memcpy(buf, src, _screenWidth*2);
@@ -527,7 +521,7 @@
 		buf += pitch;
 	} while (--h);
 
-	SDL_UnlockSurface(sdl_tmpscreen);
+	SDL_UnlockSurface(_tmpscreen);
 }
 
 void OSystem_SDL_Normal::copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h)
@@ -535,7 +529,7 @@
 	if (!_overlay_visible)
 		return;
 
-	if (sdl_tmpscreen == NULL)
+	if (_tmpscreen == NULL)
 		return;
 
 	// Clip the coordinates
@@ -553,17 +547,17 @@
 	/* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
 	undraw_mouse();
 
-	if (SDL_LockSurface(sdl_tmpscreen) == -1)
+	if (SDL_LockSurface(_tmpscreen) == -1)
 		error("SDL_LockSurface failed: %s.\n", SDL_GetError());
 
-	int16 *dst = (int16 *)sdl_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
+	int16 *dst = (int16 *)_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1);
 	do {
 		memcpy(dst, buf, w*2);
 		dst += TMP_SCREEN_WIDTH;
 		buf += pitch;
 	} while (--h);
 
-	SDL_UnlockSurface(sdl_tmpscreen);
+	SDL_UnlockSurface(_tmpscreen);
 }
 
 





More information about the Scummvm-git-logs mailing list