Now returns an error if unable to open audio on BeOS
authorSam Lantinga <slouken@lokigames.com>
Fri, 20 Jul 2001 20:07:53 +0000
changeset 114dabc453ce7f7
parent 113 e21ac1dd30f1
child 115 7be1046c4a68
Now returns an error if unable to open audio on BeOS
Fixed bugs in fullscreen/windowed mode changes, removed duplicated code.
docs.html
src/audio/baudio/SDL_beaudio.cc
src/video/bwindow/SDL_BView.h
src/video/bwindow/SDL_sysvideo.cc
     1.1 --- a/docs.html	Wed Jul 18 20:08:18 2001 +0000
     1.2 +++ b/docs.html	Fri Jul 20 20:07:53 2001 +0000
     1.3 @@ -16,6 +16,7 @@
     1.4  Major changes since SDL 1.0.0:
     1.5  </H2>
     1.6  <UL>
     1.7 +	<LI> 1.2.2: Now returns an error if unable to open audio on BeOS
     1.8  	<LI> 1.2.2: Now gets correct keyboard state when starting up on X11
     1.9  	<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
    1.10  	<LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.)
     2.1 --- a/src/audio/baudio/SDL_beaudio.cc	Wed Jul 18 20:08:18 2001 +0000
     2.2 +++ b/src/audio/baudio/SDL_beaudio.cc	Fri Jul 20 20:07:53 2001 +0000
     2.3 @@ -201,8 +201,12 @@
     2.4  		                                                 NULL, _this);
     2.5  		SDL_UnmaskSignals(&omask);
     2.6  	}
     2.7 -	audio_obj->Start();
     2.8 -	audio_obj->SetHasData(true);
     2.9 +	if ( audio_obj->Start() == B_NO_ERROR ) {
    2.10 +		audio_obj->SetHasData(true);
    2.11 +	} else {
    2.12 +		SDL_SetError("Unable to start Be audio");
    2.13 +		return(-1);
    2.14 +	}
    2.15  
    2.16  	/* We're running! */
    2.17  	return(1);
     3.1 --- a/src/video/bwindow/SDL_BView.h	Wed Jul 18 20:08:18 2001 +0000
     3.2 +++ b/src/video/bwindow/SDL_BView.h	Fri Jul 20 20:07:53 2001 +0000
     3.3 @@ -85,7 +85,7 @@
     3.4  				dest.top    = updateRect.top + yoff;
     3.5  				dest.left   = updateRect.left + xoff;
     3.6  				dest.bottom = updateRect.bottom + yoff;
     3.7 -				dest.right  = updateRect.right + xoff;;
     3.8 +				dest.right  = updateRect.right + xoff;
     3.9  				DrawBitmap(image, updateRect, dest);
    3.10  			} else {
    3.11  				DrawBitmap(image, updateRect, updateRect);
     4.1 --- a/src/video/bwindow/SDL_sysvideo.cc	Wed Jul 18 20:08:18 2001 +0000
     4.2 +++ b/src/video/bwindow/SDL_sysvideo.cc	Fri Jul 20 20:07:53 2001 +0000
     4.3 @@ -357,32 +357,26 @@
     4.4  	}	
     4.5  }
     4.6  
     4.7 -static int BE_ToggleFullScreen(_THIS, int fullscreen)
     4.8 +static int BE_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen)
     4.9  {
    4.10 -	bool needs_unlock, is_fullscreen;	
    4.11 +	int was_fullscreen;
    4.12 +	bool needs_unlock;
    4.13  	BScreen bscreen;
    4.14  	BRect bounds;
    4.15  	display_mode mode;
    4.16  	int width, height, bpp;
    4.17  
    4.18 +	/* Set the fullscreen mode */
    4.19 +	was_fullscreen = SDL_Win->IsFullScreen();
    4.20  	SDL_Win->SetFullScreen(fullscreen);
    4.21 -	is_fullscreen = SDL_Win->IsFullScreen();
    4.22 -					     
    4.23 -	if(!((is_fullscreen && fullscreen) ||
    4.24 -	     (!is_fullscreen && !fullscreen))) {
    4.25 -		/* Modeswitch failed */
    4.26 -		return 0;
    4.27 -	}
    4.28 -	
    4.29 -	if(is_fullscreen)	_this->screen->flags |= SDL_FULLSCREEN;
    4.30 -	else			_this->screen->flags &= ~SDL_FULLSCREEN;
    4.31 +	fullscreen = SDL_Win->IsFullScreen();
    4.32  
    4.33 -	width = _this->screen->w;
    4.34 -	height = _this->screen->h;
    4.35 +	width = screen->w;
    4.36 +	height = screen->h;
    4.37  
    4.38  	/* Set the appropriate video mode */
    4.39  	if ( fullscreen ) {
    4.40 -		bpp = _this->screen->format->BitsPerPixel;
    4.41 +		bpp = screen->format->BitsPerPixel;
    4.42  		bscreen.GetMode(&mode);
    4.43  		if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
    4.44  		     (width != mode.virtual_width) ||
    4.45 @@ -394,14 +388,15 @@
    4.46  				 */
    4.47  				SDL_Win->InhibitResize();
    4.48  			} else {
    4.49 -				_this->screen->flags &= ~SDL_FULLSCREEN;
    4.50 +				fullscreen = 0;
    4.51 +				SDL_Win->SetFullScreen(fullscreen);
    4.52  			}
    4.53  		}
    4.54 -		
    4.55 -	} else {
    4.56 +	}
    4.57 +	if ( ! fullscreen ) {
    4.58  		bscreen.SetMode(&saved_mode);
    4.59  	}
    4.60 -	
    4.61 +
    4.62  	if ( SDL_Win->Lock() ) {
    4.63  		int xoff, yoff;
    4.64  		if ( SDL_Win->Shown() ) {
    4.65 @@ -410,82 +405,68 @@
    4.66  		} else {
    4.67  			needs_unlock = 0;
    4.68  		}
    4.69 -		/* This resizes the window and view area, but inhibits resizing of
    4.70 -		 * the BBitmap due to the InhibitResize call above. Thus the bitmap
    4.71 -		 * (pixel data) never changes.
    4.72 +		/* This resizes the window and view area, but inhibits resizing
    4.73 +		 * of the BBitmap due to the InhibitResize call above. Thus the
    4.74 +		 * bitmap (pixel data) never changes.
    4.75  		 */
    4.76  		SDL_Win->ResizeTo(width, height);
    4.77  		bounds = bscreen.Frame();
    4.78 -		/* Calculate offsets - used either to center window (windowed mode)
    4.79 -		 * or to set drawing offsets (fullscreen mode)
    4.80 +		/* Calculate offsets - used either to center window
    4.81 +		 * (windowed mode) or to set drawing offsets (fullscreen mode)
    4.82  		 */
    4.83 -		xoff = (bounds.IntegerWidth() - _this->screen->w)/2;
    4.84 -		yoff = (bounds.IntegerHeight() - _this->screen->h)/2;
    4.85 -		if(fullscreen) {
    4.86 +		xoff = (bounds.IntegerWidth() - width)/2;
    4.87 +		yoff = (bounds.IntegerHeight() - height)/2;
    4.88 +printf("Setting X/Y offset: %d/%d\n", xoff, yoff);
    4.89 +		if ( fullscreen ) {
    4.90  			/* Set offset for drawing */
    4.91  			SDL_Win->SetXYOffset(xoff, yoff);
    4.92  		} else {
    4.93  			/* Center window and reset the drawing offset */
    4.94 -			SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0,
    4.95 -					yoff > 0 ? (float)yoff : 0.0);
    4.96  			SDL_Win->SetXYOffset(0, 0);
    4.97  		}
    4.98 +		if ( ! needs_unlock || was_fullscreen ) {
    4.99 +			/* Center the window the first time */
   4.100 +			SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f,
   4.101 +					yoff > 0 ? (float)yoff : 0.0f);
   4.102 +		}
   4.103  		SDL_Win->Show();
   4.104  		
   4.105  		/* Unlock the window manually after the first Show() */
   4.106 -		if ( needs_unlock ) { SDL_Win->Unlock(); }
   4.107 +		if ( needs_unlock ) {
   4.108 +			SDL_Win->Unlock();
   4.109 +		}
   4.110 +	}
   4.111 +
   4.112 +	/* Set the fullscreen flag in the screen surface */
   4.113 +	if ( fullscreen ) {
   4.114 +		screen->flags |= SDL_FULLSCREEN;
   4.115 +	} else {
   4.116 +		screen->flags &= ~SDL_FULLSCREEN; 
   4.117  	}
   4.118  	return(1);
   4.119  }
   4.120  
   4.121 +static int BE_ToggleFullScreen(_THIS, int fullscreen)
   4.122 +{
   4.123 +	return BE_SetFullScreen(_this, _this->screen, fullscreen);
   4.124 +}
   4.125 +
   4.126  /* FIXME: check return values and cleanup here */
   4.127  SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current,
   4.128  				int width, int height, int bpp, Uint32 flags)
   4.129  {
   4.130  	BScreen bscreen;
   4.131 -	display_mode mode;
   4.132  	BBitmap *bbitmap;
   4.133  	BRect bounds;
   4.134 -	int needs_unlock;
   4.135 -	int xoff = 0, yoff = 0;
   4.136 -
   4.137 -	/* Set the appropriate video mode */
   4.138 -	if ( flags & SDL_FULLSCREEN ) { 
   4.139 -		bscreen.GetMode(&mode);
   4.140 -		if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
   4.141 -		     (width != mode.virtual_width) ||
   4.142 -		     (height != mode.virtual_height) ) {
   4.143 -			if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) {
   4.144 -				bscreen.SetMode(&mode);
   4.145 -				xoff = (mode.virtual_width - width)/2;
   4.146 -				yoff = (mode.virtual_height - height)/2;
   4.147 -			} else {
   4.148 -				flags &= ~SDL_FULLSCREEN;
   4.149 -			}
   4.150 -		}
   4.151 -	} else {
   4.152 -		if ( current->flags & SDL_FULLSCREEN ) {
   4.153 -			bscreen.SetMode(&saved_mode);
   4.154 -		}
   4.155 -	}
   4.156  
   4.157  	/* Create the view for this window */
   4.158  	if ( SDL_Win->CreateView(flags) < 0 ) {
   4.159  		return(NULL);
   4.160  	}
   4.161  
   4.162 -	/* Set offsets */
   4.163 -	SDL_Win->SetXYOffset(xoff, yoff);
   4.164 -
   4.165  	current->flags = 0;		/* Clear flags */
   4.166  	current->w = width;
   4.167  	current->h = height;
   4.168 -	if ( flags & SDL_FULLSCREEN ) {
   4.169 -		SDL_Win->SetFullScreen(1);
   4.170 -		current->flags |= SDL_FULLSCREEN;
   4.171 -	} else {
   4.172 -		SDL_Win->SetFullScreen(0);
   4.173 -	}
   4.174  	SDL_Win->SetType(B_TITLED_WINDOW);
   4.175  	if ( flags & SDL_NOFRAME ) {
   4.176  		current->flags |= SDL_NOFRAME;
   4.177 @@ -523,33 +504,8 @@
   4.178  		_this->UpdateRects = BE_NormalUpdate;
   4.179  	}
   4.180  
   4.181 -	/* Hide the window for resizing */
   4.182 -	if ( SDL_Win->Lock() ) {
   4.183 -		if ( SDL_Win->Shown() ) {
   4.184 -			needs_unlock = 1;
   4.185 -			SDL_Win->Hide();
   4.186 -		} else {
   4.187 -			needs_unlock = 0;
   4.188 -		}
   4.189 -
   4.190 -		/* Resize, but only if the window is different size than
   4.191 -		 * before. Otherwise it jumps funnily when the user resizes.
   4.192 -		 */
   4.193 -		bounds = SDL_Win->Bounds();
   4.194 -		if((int)bounds.Width() != width ||
   4.195 -		   (int)bounds.Height() != height) {
   4.196 -			SDL_Win->ResizeTo(width, height);
   4.197 -			bounds = bscreen.Frame();
   4.198 -			SDL_Win->MoveTo((bounds.Width()-width)/2,
   4.199 -					(bounds.Height()-height)/2);
   4.200 -		}
   4.201 -		SDL_Win->Show();
   4.202 -
   4.203 -		/* Unlock the window manually after the first Show() */
   4.204 -		if ( needs_unlock ) {
   4.205 -			SDL_Win->Unlock();
   4.206 -		}
   4.207 -	}
   4.208 +	/* Set the correct fullscreen mode */
   4.209 +	BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0);
   4.210  
   4.211  	/* We're done */
   4.212  	return(current);