diff src/video/fbcon/SDL_fbmatrox.c @ 106:63ec24e0575f

Merged DGA video surface handling improvements, unified locking code. Fixed matrox blit bug where src Y less than dst Y Fixed hardware surface init when no resolution change
author Sam Lantinga <slouken@lokigames.com>
date Fri, 13 Jul 2001 10:19:51 +0000
parents 3dc008dc229d
children 5a9c36a45db1
line wrap: on
line diff
--- a/src/video/fbcon/SDL_fbmatrox.c	Fri Jul 13 10:15:52 2001 +0000
+++ b/src/video/fbcon/SDL_fbmatrox.c	Fri Jul 13 10:19:51 2001 +0000
@@ -32,18 +32,6 @@
 #include "matrox_mmio.h"
 
 
-static int LockHWSurface(_THIS, SDL_Surface *surface)
-{
-	if ( surface == SDL_VideoSurface ) {
-		mga_waitidle();
-	}
-	return(0);
-}
-static void UnlockHWSurface(_THIS, SDL_Surface *surface)
-{
-	return;
-}
-
 /* Wait for vertical retrace - taken from the XFree86 Matrox driver */
 static void WaitVBL(_THIS)
 {
@@ -60,6 +48,10 @@
 	while ( mga_in32(0x1E20) < count )
 		;
 }
+static void WaitIdle(_THIS)
+{
+	mga_waitidle();
+}
 
 /* Sets video mem colorkey and accelerated blit function */
 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
@@ -91,8 +83,7 @@
 	}
 
 	/* Set up the X/Y base coordinates */
-	dstX = 0;
-	dstY = ((char *)dst->pixels - mapped_mem) / SDL_VideoSurface->pitch;
+	FB_dst_to_xy(this, dst, &dstX, &dstY);
 
 	/* Adjust for the current rectangle */
 	dstX += rect->x;
@@ -104,19 +95,6 @@
 	/* Set up the Y boundaries */
 	ydstlen = (rect->h | (dstY << 16));
 
-#if 0	/* This old way doesn't work on the Matrox G450 */
-	/* Set up for color fill operation */
-	fillop = MGADWG_TRAP | MGADWG_SOLID |
-	         MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO |
-	         MGADWG_BFCOL | MGADWG_BLK;
-
-	/* Execute the operations! */
-	mga_wait(4);
-	mga_out32(MGAREG_FCOL, color);
-	mga_out32(MGAREG_FXBNDRY, fxbndry);
-	mga_out32(MGAREG_YDSTLEN, ydstlen);
-	mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, fillop);
-#else
 	/* Set up for color fill operation */
 	fillop = MGADWG_TRAP | MGADWG_SOLID |
 	         MGADWG_ARZERO | MGADWG_SGNZERO | MGADWG_SHIFTZERO;
@@ -127,7 +105,8 @@
 	mga_out32(MGAREG_FCOL, color);
 	mga_out32(MGAREG_FXBNDRY, fxbndry);
 	mga_out32(MGAREG_YDSTLEN + MGAREG_EXEC, ydstlen);
-#endif
+
+	FB_AddBusySurface(dst);
 
 	return(0);
 }
@@ -136,12 +115,12 @@
                        SDL_Surface *dst, SDL_Rect *dstrect)
 {
 	SDL_VideoDevice *this;
-	int bpp;
+	int pitch, w, h;
 	int srcX, srcY;
 	int dstX, dstY;
 	Uint32 sign;
-	Uint32 sstart, sstop;
-	int sskip;
+	Uint32 start, stop;
+	int skip;
 	Uint32 blitop;
 
 	/* FIXME: For now, only blit to display surface */
@@ -151,16 +130,17 @@
 
 	/* Calculate source and destination base coordinates (in pixels) */
 	this = current_video;
-	srcX= 0;	/* FIXME: Calculate this from memory offset */
-	srcY = ((char *)src->pixels - mapped_mem) / SDL_VideoSurface->pitch;
-	dstX = 0;	/* FIXME: Calculate this from memory offset */
-	dstY = ((char *)dst->pixels - mapped_mem) / SDL_VideoSurface->pitch;
+	w = dstrect->w;
+	h = dstrect->h;
+	FB_dst_to_xy(this, src, &srcX, &srcY);
+	FB_dst_to_xy(this, dst, &dstX, &dstY);
 
 	/* Adjust for the current blit rectangles */
 	srcX += srcrect->x;
 	srcY += srcrect->y;
 	dstX += dstrect->x;
 	dstY += dstrect->y;
+	pitch = dst->pitch/dst->format->BytesPerPixel;
 
 	/* Set up the blit direction (sign) flags */
 	sign = 0;
@@ -169,19 +149,21 @@
 	}
 	if ( srcY < dstY ) {
 		sign |= 4;
+		srcY += (h - 1);
+		dstY += (h - 1);
 	}
 
 	/* Set up the blit source row start, end, and skip (in pixels) */
-	bpp = src->format->BytesPerPixel;
-	sstop = sstart = ((srcY * SDL_VideoSurface->pitch)/bpp) + srcX;
+	stop = start = (srcY * pitch) + srcX;
 	if ( srcX < dstX ) {
-		sstart += (dstrect->w - 1);
+		start += (w - 1);
 	} else {
-		sstop += (dstrect->w - 1);
+		stop  += (w - 1);
 	}
-	sskip = src->pitch/bpp;
 	if ( srcY < dstY ) {
-		sskip = -sskip;
+		skip = -pitch;
+	} else {
+		skip = pitch;
 	}
 
 	/* Set up the blit operation */
@@ -209,13 +191,16 @@
 	}
 	mga_wait(7);
 	mga_out32(MGAREG_SGN, sign);
-	mga_out32(MGAREG_AR3, sstart);
-	mga_out32(MGAREG_AR0, sstop);
-	mga_out32(MGAREG_AR5, sskip);
-	mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + dstrect->w-1) << 16)));
-	mga_out32(MGAREG_YDSTLEN, (dstY << 16) | dstrect->h);
+	mga_out32(MGAREG_AR3, start);
+	mga_out32(MGAREG_AR0, stop);
+	mga_out32(MGAREG_AR5, skip);
+	mga_out32(MGAREG_FXBNDRY, (dstX | ((dstX + w-1) << 16)));
+	mga_out32(MGAREG_YDSTLEN, (dstY << 16) | h);
 	mga_out32(MGAREG_DWGCTL + MGAREG_EXEC, blitop);
 
+	FB_AddBusySurface(src);
+	FB_AddBusySurface(dst);
+
 	return(0);
 }
 
@@ -250,9 +235,8 @@
 {
 	/* We have hardware accelerated surface functions */
 	this->CheckHWBlit = CheckHWBlit;
-	this->LockHWSurface = LockHWSurface;
-	this->UnlockHWSurface = UnlockHWSurface;
 	wait_vbl = WaitVBL;
+	wait_idle = WaitIdle;
 
 	/* The Matrox has an accelerated color fill */
 	this->info.blit_fill = 1;