diff --git a/docs.html b/docs.html
index ebab5214a..106a4e356 100644
--- a/docs.html
+++ b/docs.html
@@ -16,6 +16,7 @@ be found at the main SDL page.
Major changes since SDL 1.0.0:
+ - 1.2.3: Added double-buffering support for SVGAlib (thanks Kutak!)
- 1.2.3: Fixed crash when using double-buffering with DGA
- 1.2.3: Fixed resuming a paused CD on Win2K (thanks Aragorn)
- 1.2.3: Improved MacOS international keyboard handling (thanks Max!)
diff --git a/src/video/svga/SDL_svgavideo.c b/src/video/svga/SDL_svgavideo.c
index 33dc53dc6..899a78c62 100644
--- a/src/video/svga/SDL_svgavideo.c
+++ b/src/video/svga/SDL_svgavideo.c
@@ -145,7 +145,7 @@ static SDL_VideoDevice *SVGA_CreateDevice(int devindex)
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 @@ static void SVGA_UpdateVideoInfo(_THIS)
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 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
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 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
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 @@ static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface)
/* 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 @@ static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface)
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 @@ void SVGA_VideoQuit(_THIS)
this->screen->pixels = NULL;
}
}
+
diff --git a/src/video/svga/SDL_svgavideo.h b/src/video/svga/SDL_svgavideo.h
index 796c5e343..1510fcd99 100644
--- a/src/video/svga/SDL_svgavideo.h
+++ b/src/video/svga/SDL_svgavideo.h
@@ -40,10 +40,19 @@ struct SDL_PrivateVideoData {
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 */
+