comparison 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
comparison
equal deleted inserted replaced
1658:e49147870aac 1659:14717b52abc0
147 /* Internal palette functions */ 147 /* Internal palette functions */
148 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo, 148 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo,
149 struct fb_var_screeninfo *vinfo); 149 struct fb_var_screeninfo *vinfo);
150 static void FB_RestorePalette(_THIS); 150 static void FB_RestorePalette(_THIS);
151 151
152 /* Small wrapper for mmap() so we can play nicely with no-mmu hosts
153 * (non-mmu hosts disallow the MAP_SHARED flag) */
154
155 static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
156 {
157 void *ret;
158 ret = mmap(start, length, prot, flags, fd, offset);
159 if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
160 ret = mmap(start, length, prot,
161 (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
162 }
163 return ret;
164 }
165
152 /* FB driver bootstrap functions */ 166 /* FB driver bootstrap functions */
153 167
154 static int FB_Available(void) 168 static int FB_Available(void)
155 { 169 {
156 int console; 170 int console = -1;
157 /* Added check for /fb/0 (devfs) */ 171 /* Added check for /fb/0 (devfs) */
158 /* but - use environment variable first... if it fails, still check defaults */ 172 /* but - use environment variable first... if it fails, still check defaults */
159 int idx = 0; 173 int idx = 0;
160 const char *SDL_fbdevs[4] = { NULL, "/dev/fb0", "/dev/fb/0", NULL }; 174 const char *SDL_fbdevs[4] = { NULL, "/dev/fb0", "/dev/fb/0", NULL };
161 175
533 547
534 /* Memory map the device, compensating for buggy PPC mmap() */ 548 /* Memory map the device, compensating for buggy PPC mmap() */
535 mapped_offset = (((long)finfo.smem_start) - 549 mapped_offset = (((long)finfo.smem_start) -
536 (((long)finfo.smem_start)&~(PAGE_SIZE-1))); 550 (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
537 mapped_memlen = finfo.smem_len+mapped_offset; 551 mapped_memlen = finfo.smem_len+mapped_offset;
538 mapped_mem = mmap(NULL, mapped_memlen, 552 mapped_mem = do_mmap(NULL, mapped_memlen,
539 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0); 553 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
540 if ( mapped_mem == (char *)-1 ) { 554 if ( mapped_mem == (char *)-1 ) {
541 SDL_SetError("Unable to memory map the video hardware"); 555 SDL_SetError("Unable to memory map the video hardware");
542 mapped_mem = NULL; 556 mapped_mem = NULL;
543 FB_VideoQuit(this); 557 FB_VideoQuit(this);
577 */ 591 */
578 vinfo.accel_flags = 0; /* Temporarily reserve registers */ 592 vinfo.accel_flags = 0; /* Temporarily reserve registers */
579 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo); 593 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
580 if ( finfo.accel && finfo.mmio_len ) { 594 if ( finfo.accel && finfo.mmio_len ) {
581 mapped_iolen = finfo.mmio_len; 595 mapped_iolen = finfo.mmio_len;
582 mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE, 596 mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
583 MAP_SHARED, console_fd, mapped_memlen); 597 MAP_SHARED, console_fd, mapped_memlen);
584 if ( mapped_io == (char *)-1 ) { 598 if ( mapped_io == (char *)-1 ) {
585 /* Hmm, failed to memory map I/O registers */ 599 /* Hmm, failed to memory map I/O registers */
586 mapped_io = NULL; 600 mapped_io = NULL;
587 } 601 }
1236 } 1250 }
1237 surface->pixels = NULL; 1251 surface->pixels = NULL;
1238 surface->hwdata = NULL; 1252 surface->hwdata = NULL;
1239 } 1253 }
1240 1254
1241 /* Routine to check to see if the frame buffer virtual terminal */
1242 /* is the current(active) one. If it is not, result will cause */
1243 /* Lock to fail. (would have waited forever, since the fbevent */
1244 /* keyboard handler maintains a lock when switched away from */
1245 /* current) */
1246 static __inline__ int FB_IsFrameBufferActive(_THIS)
1247 {
1248 struct vt_stat vtstate;
1249 if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
1250 (current_vt != vtstate.v_active) ) {
1251 return 0;
1252 }
1253 return 1;
1254 }
1255
1256
1257 static int FB_LockHWSurface(_THIS, SDL_Surface *surface) 1255 static int FB_LockHWSurface(_THIS, SDL_Surface *surface)
1258 { 1256 {
1259 if ( !FB_IsFrameBufferActive(this) ) { 1257 if ( switched_away ) {
1260 return -1; /* fail locking. */ 1258 return -2; /* no hardware access */
1261 } 1259 }
1262 if ( surface == this->screen ) { 1260 if ( surface == this->screen ) {
1263 SDL_mutexP(hw_lock); 1261 SDL_mutexP(hw_lock);
1264 if ( FB_IsSurfaceBusy(surface) ) { 1262 if ( FB_IsSurfaceBusy(surface) ) {
1265 FB_WaitBusySurfaces(this); 1263 FB_WaitBusySurfaces(this);
1291 return; 1289 return;
1292 } 1290 }
1293 1291
1294 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface) 1292 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface)
1295 { 1293 {
1294 if ( switched_away ) {
1295 return -2; /* no hardware access */
1296 }
1297
1296 /* Wait for vertical retrace and then flip display */ 1298 /* Wait for vertical retrace and then flip display */
1297 cache_vinfo.yoffset = flip_page*surface->h; 1299 cache_vinfo.yoffset = flip_page*surface->h;
1298 if ( FB_IsSurfaceBusy(this->screen) ) { 1300 if ( FB_IsSurfaceBusy(this->screen) ) {
1299 FB_WaitBusySurfaces(this); 1301 FB_WaitBusySurfaces(this);
1300 } 1302 }
1330 int width, height, FBPitch, left, i, j, SRCPitch, phase; 1332 int width, height, FBPitch, left, i, j, SRCPitch, phase;
1331 register Uint32 m; 1333 register Uint32 m;
1332 Uint8 s1, s2, s3, s4; 1334 Uint8 s1, s2, s3, s4;
1333 Uint32 *src, *srcPtr; 1335 Uint32 *src, *srcPtr;
1334 Uint8 *dst, *dstPtr; 1336 Uint8 *dst, *dstPtr;
1337
1338 if ( switched_away ) {
1339 return; /* no hardware access */
1340 }
1335 1341
1336 screen = this->screen; 1342 screen = this->screen;
1337 FBPitch = screen->w >> 3; 1343 FBPitch = screen->w >> 3;
1338 SRCPitch = screen->pitch >> 2; 1344 SRCPitch = screen->pitch >> 2;
1339 1345