Commit 877556f5 authored by Sam Lantinga's avatar Sam Lantinga

Fixed bug #84

Date: Sun, 23 Oct 2005 16:39:03 +0200
From: "A. Schmid" <sahib@phreaker.net>
Subject: [SDL] no software surfaces with svgalib driver?

Hi,

I noticed that the SDL (1.2.9) svgalib driver only makes use of linear
addressable (framebuffer) video modes. On older systems (like one of
mine), linear addressable modes are often not available.
Especially for cards with VESA VBE < 2.0 the svgalib vesa driver is
unusable, since VESA only supports framebuffering for VBE 2.0 and later.

The changes necessary to add support for software surfaces seem to be
relatively small. I only had to hack src/video/svga/SDL_svgavideo.c (see
attached patch). The code worked fine for me, but it is no more than a
proof of concept and should be reviewed (probably has a memory leak when
switching modes). It also uses the vgagl library (included in the
svgalib package) and needs to be linked against it.

-Alex

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401558
parent d21bbd6c
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <vga.h> #include <vga.h>
#include <vgamouse.h> #include <vgamouse.h>
#include <vgakeyboard.h> #include <vgakeyboard.h>
#include <vgagl.h>
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_mouse.h" #include "SDL_mouse.h"
...@@ -50,6 +51,8 @@ ...@@ -50,6 +51,8 @@
#include "SDL_svgaevents_c.h" #include "SDL_svgaevents_c.h"
#include "SDL_svgamouse_c.h" #include "SDL_svgamouse_c.h"
static GraphicsContext *realgc = NULL;
static GraphicsContext *virtgc = NULL;
/* Initialization/Query functions */ /* Initialization/Query functions */
static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat); static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
...@@ -168,6 +171,9 @@ static int SVGA_AddMode(_THIS, int mode, int actually_add, int force) ...@@ -168,6 +171,9 @@ static int SVGA_AddMode(_THIS, int mode, int actually_add, int force)
int i, j; int i, j;
i = modeinfo->bytesperpixel-1; i = modeinfo->bytesperpixel-1;
if ( i < 0 ) {
return 0;
}
if ( actually_add ) { if ( actually_add ) {
SDL_Rect saved_rect[2]; SDL_Rect saved_rect[2];
int saved_mode[2]; int saved_mode[2];
...@@ -215,7 +221,7 @@ static void SVGA_UpdateVideoInfo(_THIS) ...@@ -215,7 +221,7 @@ static void SVGA_UpdateVideoInfo(_THIS)
vga_modeinfo *modeinfo; vga_modeinfo *modeinfo;
this->info.wm_available = 0; this->info.wm_available = 0;
this->info.hw_available = 1; this->info.hw_available = (virtgc ? 0 : 1);
modeinfo = vga_getmodeinfo(vga_getcurrentmode()); modeinfo = vga_getmodeinfo(vga_getcurrentmode());
this->info.video_mem = modeinfo->memory; this->info.video_mem = modeinfo->memory;
/* FIXME: Add hardware accelerated blit information */ /* FIXME: Add hardware accelerated blit information */
...@@ -268,7 +274,7 @@ int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -268,7 +274,7 @@ int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
total_modes = 0; total_modes = 0;
for ( mode=vga_lastmodenumber(); mode; --mode ) { for ( mode=vga_lastmodenumber(); mode; --mode ) {
if ( vga_hasmode(mode) ) { if ( vga_hasmode(mode) ) {
if ( SVGA_AddMode(this, mode, 0, 0) ) { if ( SVGA_AddMode(this, mode, 0, 1) ) {
++total_modes; ++total_modes;
} }
} }
...@@ -302,7 +308,7 @@ int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -302,7 +308,7 @@ int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat)
} }
for ( mode=vga_lastmodenumber(); mode; --mode ) { for ( mode=vga_lastmodenumber(); mode; --mode ) {
if ( vga_hasmode(mode) ) { if ( vga_hasmode(mode) ) {
SVGA_AddMode(this, mode, 1, 0); SVGA_AddMode(this, mode, 1, 1);
} }
} }
SVGA_AddMode(this, G320x200x256, 1, 1); SVGA_AddMode(this, G320x200x256, 1, 1);
...@@ -344,6 +350,18 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -344,6 +350,18 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
vga_modeinfo *modeinfo; vga_modeinfo *modeinfo;
int screenpage_len; int screenpage_len;
/* Clean up old video mode data */
if ( realgc ) {
free(realgc);
realgc = NULL;
}
if ( virtgc ) {
/* FIXME: Why does this crash?
gl_freecontext(virtgc);*/
free(virtgc);
virtgc = NULL;
}
/* Try to set the requested linear video mode */ /* Try to set the requested linear video mode */
bpp = (bpp+7)/8-1; bpp = (bpp+7)/8-1;
for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
...@@ -356,14 +374,22 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -356,14 +374,22 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
SDL_SetError("Couldn't find requested mode in list"); SDL_SetError("Couldn't find requested mode in list");
return(NULL); return(NULL);
} }
vga_setmode(SDL_vgamode[bpp][mode]); vgamode = SDL_vgamode[bpp][mode];
vga_setmode(vgamode);
vga_setpage(0); vga_setpage(0);
vgamode=SDL_vgamode[bpp][mode]; if ( (vga_setlinearaddressing() < 0) && (vgamode != G320x200x256) ) {
if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) { gl_setcontextvga(vgamode);
SDL_SetError("Unable to set linear addressing"); realgc = gl_allocatecontext();
return(NULL); gl_getcontext(realgc);
gl_setcontextvgavirtual(vgamode);
virtgc = gl_allocatecontext();
gl_getcontext(virtgc);
flags &= ~SDL_DOUBLEBUF;
} }
modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]);
/* Update hardware acceleration info */ /* Update hardware acceleration info */
...@@ -379,7 +405,12 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -379,7 +405,12 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
} }
/* Set up the new mode framebuffer */ /* Set up the new mode framebuffer */
current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); current->flags = SDL_FULLSCREEN;
if ( virtgc ) {
current->flags |= SDL_SWSURFACE;
} else {
current->flags |= SDL_HWSURFACE;
}
if ( bpp == 8 ) { if ( bpp == 8 ) {
/* FIXME: What about DirectColor? */ /* FIXME: What about DirectColor? */
current->flags |= SDL_HWPALETTE; current->flags |= SDL_HWPALETTE;
...@@ -387,7 +418,11 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -387,7 +418,11 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
current->w = width; current->w = width;
current->h = height; current->h = height;
current->pitch = modeinfo->linewidth; current->pitch = modeinfo->linewidth;
current->pixels = vga_getgraphmem(); if ( virtgc ) {
current->pixels = virtgc->vbuf;
} else {
current->pixels = vga_getgraphmem();
}
/* set double-buffering */ /* set double-buffering */
if ( flags & SDL_DOUBLEBUF ) if ( flags & SDL_DOUBLEBUF )
...@@ -418,7 +453,11 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -418,7 +453,11 @@ SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current,
} }
/* Set the blit function */ /* Set the blit function */
this->UpdateRects = SVGA_DirectUpdate; if ( virtgc ) {
this->UpdateRects = SVGA_BankedUpdate;
} else {
this->UpdateRects = SVGA_DirectUpdate;
}
/* Set up the mouse handler again (buggy SVGAlib 1.40) */ /* Set up the mouse handler again (buggy SVGAlib 1.40) */
mouse_seteventhandler(SVGA_mousecallback); mouse_seteventhandler(SVGA_mousecallback);
...@@ -450,10 +489,12 @@ static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface) ...@@ -450,10 +489,12 @@ static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface)
static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface) static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface)
{ {
vga_setdisplaystart(flip_offset[flip_page]); if ( !virtgc ) {
flip_page=!flip_page; vga_setdisplaystart(flip_offset[flip_page]);
surface->pixels=flip_address[flip_page]; flip_page=!flip_page;
vga_waitretrace(); surface->pixels=flip_address[flip_page];
vga_waitretrace();
}
return(0); return(0);
} }
...@@ -462,9 +503,15 @@ static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) ...@@ -462,9 +503,15 @@ static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects)
return; return;
} }
/* FIXME: Can this be used under SVGAlib? */
static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects) static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects)
{ {
int i;
SDL_Rect *rect;
for ( i=0; i < numrects; ++i ) {
rect = &rects[i];
gl_copyboxtocontext(rect->x, rect->y, rect->w, rect->h, realgc, rect->x, rect->y);
}
return; return;
} }
...@@ -490,6 +537,16 @@ void SVGA_VideoQuit(_THIS) ...@@ -490,6 +537,16 @@ void SVGA_VideoQuit(_THIS)
/* Reset the console video mode */ /* Reset the console video mode */
if ( this->screen && (this->screen->w && this->screen->h) ) { if ( this->screen && (this->screen->w && this->screen->h) ) {
if ( realgc ) {
free(realgc);
realgc = NULL;
}
if ( virtgc ) {
/* FIXME: Why does this crash?
gl_freecontext(virtgc);*/
free(virtgc);
virtgc = NULL;
}
vga_setmode(TEXT); vga_setmode(TEXT);
} }
keyboard_close(); keyboard_close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment