Added double-buffering support for SVGAlib (thanks Kutak!)
authorSam Lantinga <slouken@libsdl.org>
Sun, 14 Oct 2001 19:49:02 +0000
changeset 205 13161d3d349d
parent 204 62bad9a82022
child 206 b69bb2a368a0
Added double-buffering support for SVGAlib (thanks Kutak!)
docs.html
src/video/svga/SDL_svgavideo.c
src/video/svga/SDL_svgavideo.h
--- a/docs.html	Mon Oct 08 18:54:06 2001 +0000
+++ b/docs.html	Sun Oct 14 19:49:02 2001 +0000
@@ -16,6 +16,7 @@
 Major changes since SDL 1.0.0:
 </H2>
 <UL>
+	<LI> 1.2.3: Added double-buffering support for SVGAlib (thanks Kutak!)
 	<LI> 1.2.3: Fixed crash when using double-buffering with DGA
 	<LI> 1.2.3: Fixed resuming a paused CD on Win2K (thanks Aragorn)
 	<LI> 1.2.3: Improved MacOS international keyboard handling (thanks Max!)
--- a/src/video/svga/SDL_svgavideo.c	Mon Oct 08 18:54:06 2001 +0000
+++ b/src/video/svga/SDL_svgavideo.c	Sun Oct 14 19:49:02 2001 +0000
@@ -145,7 +145,7 @@
 	device->SetHWAlpha = NULL;
 	device->LockHWSurface = SVGA_LockHWSurface;
 	device->UnlockHWSurface = SVGA_UnlockHWSurface;
-	device->FlipHWSurface = NULL;
+	device->FlipHWSurface = SVGA_FlipHWSurface;
 	device->FreeHWSurface = SVGA_FreeHWSurface;
 	device->SetCaption = NULL;
 	device->SetIcon = NULL;
@@ -223,10 +223,7 @@
 	this->info.wm_available = 0;
 	this->info.hw_available = 1;
 	modeinfo = vga_getmodeinfo(vga_getcurrentmode());
-	this->info.video_mem = (modeinfo->maxpixels/1024);
-	if ( modeinfo->bytesperpixel > 0 ) {
-		this->info.video_mem *= modeinfo->bytesperpixel;
-	}
+	this->info.video_mem = modeinfo->memory;
 	/* FIXME: Add hardware accelerated blit information */
 #if 0
 printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not ");
@@ -347,6 +344,7 @@
 	int mode;
 	int vgamode;
 	vga_modeinfo *modeinfo;
+	int screenpage_len;
 
 	/* Try to set the requested linear video mode */
 	bpp = (bpp+7)/8-1;
@@ -393,6 +391,34 @@
 	current->pitch = modeinfo->linewidth;
 	current->pixels = vga_getgraphmem();
 
+	/* set double-buffering */
+	if ( flags & SDL_DOUBLEBUF )
+	{
+	    /* length of one screen page in bytes */
+	    screenpage_len=current->h*modeinfo->linewidth;
+
+	    /* if start address should be aligned */
+	    if ( modeinfo->linewidth_unit )
+	    {
+		if ( screenpage_len % modeinfo->linewidth_unit )    
+		{
+		    screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit );
+		}
+	    }
+
+	    /* if we heve enough videomemory =  ak je dost videopamete  */
+	    if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) )
+	    {
+		current->flags |= SDL_DOUBLEBUF;
+		flip_page = 0;
+		flip_offset[0] = 0;
+		flip_offset[1] = screenpage_len;
+		flip_address[0] = vga_getgraphmem();
+		flip_address[1] = flip_address[0]+screenpage_len;
+		SVGA_FlipHWSurface(this,current);
+	    }
+	} 
+
 	/* Set the blit function */
 	this->UpdateRects = SVGA_DirectUpdate;
 
@@ -416,9 +442,7 @@
 /* We need to wait for vertical retrace on page flipped displays */
 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface)
 {
-	if ( (surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) {
-		vga_waitretrace();
-	}
+	/* The waiting is done in SVGA_FlipHWSurface() */
 	return(0);
 }
 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface)
@@ -426,9 +450,12 @@
 	return;
 }
 
-/* FIXME: How is this done with SVGAlib? */
 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface)
 {
+	vga_setdisplaystart(flip_offset[flip_page]);
+	flip_page=!flip_page;
+	surface->pixels=flip_address[flip_page];
+	vga_waitretrace();
 	return(0);
 }
 
@@ -487,3 +514,4 @@
 		this->screen->pixels = NULL;
 	}
 }
+
--- a/src/video/svga/SDL_svgavideo.h	Mon Oct 08 18:54:06 2001 +0000
+++ b/src/video/svga/SDL_svgavideo.h	Sun Oct 14 19:49:02 2001 +0000
@@ -40,10 +40,19 @@
 	int SDL_nummodes[NUM_MODELISTS];
 	SDL_Rect **SDL_modelist[NUM_MODELISTS];
 	int *SDL_vgamode[NUM_MODELISTS];
+
+	/* information for double-buffering */
+	int flip_page;
+	int flip_offset[2];
+	Uint8 *flip_address[2];
 };
 /* Old variable names */
 #define SDL_nummodes		(this->hidden->SDL_nummodes)
 #define SDL_modelist		(this->hidden->SDL_modelist)
 #define SDL_vgamode		(this->hidden->SDL_vgamode)
+#define flip_page		(this->hidden->flip_page)
+#define flip_offset		(this->hidden->flip_offset)
+#define flip_address		(this->hidden->flip_address)
 
 #endif /* _SDL_svgavideo_h */
+