diff src/video/fbcon/SDL_fbvideo.c @ 1659:14717b52abc0 SDL-1.3

Merge trunk-1.3-3
author Sam Lantinga <slouken@libsdl.org>
date Wed, 17 May 2006 08:18:28 +0000
parents 980d2a0dc2a3
children 782fd950bd46
line wrap: on
line diff
--- a/src/video/fbcon/SDL_fbvideo.c	Mon May 01 06:58:33 2006 +0000
+++ b/src/video/fbcon/SDL_fbvideo.c	Wed May 17 08:18:28 2006 +0000
@@ -149,11 +149,25 @@
                                   struct fb_var_screeninfo *vinfo);
 static void FB_RestorePalette(_THIS);
 
+/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
+ * (non-mmu hosts disallow the MAP_SHARED flag) */
+
+static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
+{
+	void *ret;
+	ret = mmap(start, length, prot, flags, fd, offset);
+	if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
+		ret = mmap(start, length, prot,
+		           (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
+	}
+	return ret;
+}
+
 /* FB driver bootstrap functions */
 
 static int FB_Available(void)
 {
-	int console;
+	int console = -1;
 	/* Added check for /fb/0 (devfs) */
 	/* but - use environment variable first... if it fails, still check defaults */
 	int idx = 0;
@@ -535,7 +549,7 @@
 	mapped_offset = (((long)finfo.smem_start) -
 	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
 	mapped_memlen = finfo.smem_len+mapped_offset;
-	mapped_mem = mmap(NULL, mapped_memlen,
+	mapped_mem = do_mmap(NULL, mapped_memlen,
 	                  PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
 	if ( mapped_mem == (char *)-1 ) {
 		SDL_SetError("Unable to memory map the video hardware");
@@ -579,7 +593,7 @@
 	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
 	if ( finfo.accel && finfo.mmio_len ) {
 		mapped_iolen = finfo.mmio_len;
-		mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
+		mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
 		                 MAP_SHARED, console_fd, mapped_memlen);
 		if ( mapped_io == (char *)-1 ) {
 			/* Hmm, failed to memory map I/O registers */
@@ -1238,26 +1252,10 @@
 	surface->hwdata = NULL;
 }
 
-/* Routine to check to see if the frame buffer virtual terminal */
-/* is the current(active) one.  If it is not, result will cause */
-/* Lock to fail.  (would have waited forever, since the fbevent */
-/* keyboard handler maintains a lock when switched away from    */
-/* current) */
-static __inline__ int FB_IsFrameBufferActive(_THIS)
-{
-	struct vt_stat vtstate;
-	if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
-	     (current_vt != vtstate.v_active) ) {
-		return 0;
-	}
-	return 1;
-}
-
-
 static int FB_LockHWSurface(_THIS, SDL_Surface *surface)
 {
-	if ( !FB_IsFrameBufferActive(this) ) {
-		return -1; /* fail locking. */
+	if ( switched_away ) {
+		return -2; /* no hardware access */
 	}
 	if ( surface == this->screen ) {
 		SDL_mutexP(hw_lock);
@@ -1293,6 +1291,10 @@
 
 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface)
 {
+	if ( switched_away ) {
+		return -2; /* no hardware access */
+	}
+
 	/* Wait for vertical retrace and then flip display */
 	cache_vinfo.yoffset = flip_page*surface->h;
 	if ( FB_IsSurfaceBusy(this->screen) ) {
@@ -1333,6 +1335,10 @@
     Uint32 *src, *srcPtr;
     Uint8  *dst, *dstPtr;
 
+    if ( switched_away ) {
+        return; /* no hardware access */
+    }
+
     screen = this->screen;
     FBPitch = screen->w >> 3;
     SRCPitch = screen->pitch >> 2;