Mercurial > sdl-ios-xcode
annotate src/video/bwindow/SDL_sysvideo.cc @ 765:4c2ba6161939
Editors Note: The original patch was modified to use SDL_Delay() instead of
nanosleep because nanosleep may not be portable to all systems
using SDL with the ALSA backend. This may be a moot point with
the switch to blocking writes anyway...
Date: Sat, 27 Dec 2003 21:47:36 +0100
From: Michel Daenzer
To: Debian Bug Tracking System
Subject: [SDL] Bug#225252: [PATCH] ALSA fixes
Package: libsdl1.2debian-all
Version: 1.2.6-2
Severity: normal
Tags: patch
For SDL 1.2.6, the ALSA backend was changed to call snd_pcm_open() with
SND_PCM_NONBLOCK. That's a good idea per se, however, it causes high CPU
usage, interrupted sound and stuttering in some games here. Taking a nanosleep
whenever snd_pcm_writei() returns -EAGAIN fixes this, but I think it's more
efficient to use blocking mode for the actual sound playback. Feedback from the
SDL and ALSA lists appreciated.
The patch also fixes the default ALSA device to be used.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 04 Jan 2004 15:40:50 +0000 |
parents | 10332c6fad2e |
children | b8d311d90021 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
206
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* BWindow based framebuffer implementation */ | |
29 | |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 | |
33 #include <stdio.h> | |
34 #include <unistd.h> | |
35 | |
36 #include "SDL.h" | |
37 #include "SDL_BeApp.h" | |
38 #include "SDL_BWin.h" | |
39 #include "SDL_timer.h" | |
40 #include "blank_cursor.h" | |
41 | |
42 extern "C" { | |
43 | |
44 #include "SDL_sysvideo.h" | |
45 #include "SDL_sysmouse_c.h" | |
46 #include "SDL_sysevents_c.h" | |
47 #include "SDL_events_c.h" | |
48 #include "SDL_syswm_c.h" | |
49 #include "SDL_lowvideo.h" | |
756
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
50 #include "SDL_yuvfuncs.h" |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
51 #include "SDL_sysyuv.h" |
0 | 52 |
53 #define BEOS_HIDDEN_SIZE 32 /* starting hidden window size */ | |
54 | |
55 /* Initialization/Query functions */ | |
56 static int BE_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
57 static SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
58 static SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
59 static void BE_UpdateMouse(_THIS); | |
60 static int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
61 static void BE_VideoQuit(_THIS); | |
62 | |
63 /* Hardware surface functions */ | |
64 static int BE_AllocHWSurface(_THIS, SDL_Surface *surface); | |
65 static int BE_LockHWSurface(_THIS, SDL_Surface *surface); | |
66 static void BE_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
67 static void BE_FreeHWSurface(_THIS, SDL_Surface *surface); | |
68 | |
69 static int BE_ToggleFullScreen(_THIS, int fullscreen); | |
756
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
70 static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display); |
0 | 71 |
72 /* OpenGL functions */ | |
73 #ifdef HAVE_OPENGL | |
74 static void BE_GL_SwapBuffers(_THIS); | |
75 #endif | |
76 | |
77 /* FB driver bootstrap functions */ | |
78 | |
79 static int BE_Available(void) | |
80 { | |
81 return(1); | |
82 } | |
83 | |
84 static void BE_DeleteDevice(SDL_VideoDevice *device) | |
85 { | |
86 free(device->hidden); | |
87 free(device); | |
88 } | |
89 | |
90 static SDL_VideoDevice *BE_CreateDevice(int devindex) | |
91 { | |
92 SDL_VideoDevice *device; | |
93 | |
94 /* Initialize all variables that we clean on shutdown */ | |
95 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
96 if ( device ) { | |
97 memset(device, 0, (sizeof *device)); | |
98 device->hidden = (struct SDL_PrivateVideoData *) | |
99 malloc((sizeof *device->hidden)); | |
100 } | |
101 if ( (device == NULL) || (device->hidden == NULL) ) { | |
102 SDL_OutOfMemory(); | |
103 if ( device ) { | |
104 free(device); | |
105 } | |
106 return(0); | |
107 } | |
108 memset(device->hidden, 0, (sizeof *device->hidden)); | |
109 | |
110 /* Set the function pointers */ | |
111 device->VideoInit = BE_VideoInit; | |
112 device->ListModes = BE_ListModes; | |
113 device->SetVideoMode = BE_SetVideoMode; | |
114 device->UpdateMouse = BE_UpdateMouse; | |
115 device->SetColors = BE_SetColors; | |
116 device->UpdateRects = NULL; | |
117 device->VideoQuit = BE_VideoQuit; | |
118 device->AllocHWSurface = BE_AllocHWSurface; | |
119 device->CheckHWBlit = NULL; | |
120 device->FillHWRect = NULL; | |
121 device->SetHWColorKey = NULL; | |
122 device->SetHWAlpha = NULL; | |
123 device->LockHWSurface = BE_LockHWSurface; | |
124 device->UnlockHWSurface = BE_UnlockHWSurface; | |
125 device->FlipHWSurface = NULL; | |
126 device->FreeHWSurface = BE_FreeHWSurface; | |
127 #ifdef HAVE_OPENGL | |
128 device->GL_SwapBuffers = BE_GL_SwapBuffers; | |
129 #endif | |
130 device->SetIcon = NULL; | |
131 device->SetCaption = BE_SetWMCaption; | |
132 device->GetWMInfo = NULL; | |
133 device->FreeWMCursor = BE_FreeWMCursor; | |
134 device->CreateWMCursor = BE_CreateWMCursor; | |
135 device->ShowWMCursor = BE_ShowWMCursor; | |
136 device->WarpWMCursor = BE_WarpWMCursor; | |
137 device->InitOSKeymap = BE_InitOSKeymap; | |
138 device->PumpEvents = BE_PumpEvents; | |
139 | |
140 device->free = BE_DeleteDevice; | |
141 device->ToggleFullScreen = BE_ToggleFullScreen; | |
756
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
142 device->CreateYUVOverlay = BE_CreateYUVOverlay; |
0 | 143 |
144 /* Set the driver flags */ | |
145 device->handles_any_size = 1; | |
146 | |
147 return device; | |
148 } | |
149 | |
150 VideoBootStrap BWINDOW_bootstrap = { | |
151 "bwindow", "BDirectWindow graphics", | |
152 BE_Available, BE_CreateDevice | |
153 }; | |
154 | |
155 static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) | |
156 { | |
157 int bitsperpixel; | |
158 | |
159 bitsperpixel = 0; | |
160 switch (colorspace) { | |
161 case B_CMAP8: | |
162 bitsperpixel = 8; | |
163 break; | |
164 case B_RGB15: | |
165 case B_RGBA15: | |
166 case B_RGB15_BIG: | |
167 case B_RGBA15_BIG: | |
168 bitsperpixel = 15; | |
169 break; | |
170 case B_RGB16: | |
171 case B_RGB16_BIG: | |
172 bitsperpixel = 16; | |
173 break; | |
174 case B_RGB32: | |
175 case B_RGBA32: | |
176 case B_RGB32_BIG: | |
177 case B_RGBA32_BIG: | |
178 bitsperpixel = 32; | |
179 break; | |
180 default: | |
181 break; | |
182 } | |
183 return(bitsperpixel); | |
184 } | |
185 | |
186 /* Function to sort the display_list in bscreen */ | |
187 static int CompareModes(const void *A, const void *B) | |
188 { | |
189 const display_mode *a = (display_mode *)A; | |
190 const display_mode *b = (display_mode *)B; | |
191 | |
192 if ( a->space == b->space ) { | |
193 return((b->virtual_width*b->virtual_height)- | |
194 (a->virtual_width*a->virtual_height)); | |
195 } else { | |
196 return(ColorSpaceToBitsPerPixel(b->space)- | |
197 ColorSpaceToBitsPerPixel(a->space)); | |
198 } | |
199 } | |
200 | |
201 /* Yes, this isn't the fastest it could be, but it works nicely */ | |
202 static int BE_AddMode(_THIS, int index, unsigned int w, unsigned int h) | |
203 { | |
204 SDL_Rect *mode; | |
205 int i; | |
206 int next_mode; | |
207 | |
208 /* Check to see if we already have this mode */ | |
209 if ( SDL_nummodes[index] > 0 ) { | |
210 for ( i=SDL_nummodes[index]-1; i >= 0; --i ) { | |
211 mode = SDL_modelist[index][i]; | |
212 if ( (mode->w == w) && (mode->h == h) ) { | |
213 #ifdef BWINDOW_DEBUG | |
214 fprintf(stderr, "We already have mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
215 #endif | |
216 return(0); | |
217 } | |
218 } | |
219 } | |
220 | |
221 /* Set up the new video mode rectangle */ | |
222 mode = (SDL_Rect *)malloc(sizeof *mode); | |
223 if ( mode == NULL ) { | |
224 SDL_OutOfMemory(); | |
225 return(-1); | |
226 } | |
227 mode->x = 0; | |
228 mode->y = 0; | |
229 mode->w = w; | |
230 mode->h = h; | |
231 #ifdef BWINDOW_DEBUG | |
232 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
233 #endif | |
234 | |
235 /* Allocate the new list of modes, and fill in the new mode */ | |
236 next_mode = SDL_nummodes[index]; | |
237 SDL_modelist[index] = (SDL_Rect **) | |
238 realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); | |
239 if ( SDL_modelist[index] == NULL ) { | |
240 SDL_OutOfMemory(); | |
241 SDL_nummodes[index] = 0; | |
242 free(mode); | |
243 return(-1); | |
244 } | |
245 SDL_modelist[index][next_mode] = mode; | |
246 SDL_modelist[index][next_mode+1] = NULL; | |
247 SDL_nummodes[index]++; | |
248 | |
249 return(0); | |
250 } | |
251 | |
252 int BE_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
253 { | |
254 display_mode *modes; | |
255 uint32 i, nmodes; | |
256 int bpp; | |
257 BRect bounds; | |
258 | |
259 /* Initialize the Be Application for appserver interaction */ | |
260 if ( SDL_InitBeApp() < 0 ) { | |
261 return(-1); | |
262 } | |
263 | |
264 /* It is important that this be created after SDL_InitBeApp() */ | |
265 BScreen bscreen; | |
266 | |
267 /* Save the current display mode */ | |
268 bscreen.GetMode(&saved_mode); | |
269 | |
270 /* Determine the screen depth */ | |
271 vformat->BitsPerPixel = ColorSpaceToBitsPerPixel(bscreen.ColorSpace()); | |
272 if ( vformat->BitsPerPixel == 0 ) { | |
273 SDL_SetError("Unknown BScreen colorspace: 0x%x", | |
274 bscreen.ColorSpace()); | |
275 return(-1); | |
276 } | |
277 | |
278 /* Get the video modes we can switch to in fullscreen mode */ | |
279 bscreen.GetModeList(&modes, &nmodes); | |
280 qsort(modes, nmodes, sizeof *modes, CompareModes); | |
281 for ( i=0; i<nmodes; ++i ) { | |
282 bpp = ColorSpaceToBitsPerPixel(modes[i].space); | |
283 //if ( bpp != 0 ) { // There are bugs in changing colorspace | |
284 if ( modes[i].space == saved_mode.space ) { | |
285 BE_AddMode(_this, ((bpp+7)/8)-1, | |
286 modes[i].virtual_width, | |
287 modes[i].virtual_height); | |
288 } | |
289 } | |
290 | |
291 /* Create the window and view */ | |
292 bounds.top = 0; bounds.left = 0; | |
293 bounds.right = BEOS_HIDDEN_SIZE; | |
294 bounds.bottom = BEOS_HIDDEN_SIZE; | |
295 SDL_Win = new SDL_BWin(bounds); | |
296 | |
297 /* Create the clear cursor */ | |
298 SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask, | |
299 BLANK_CWIDTH, BLANK_CHEIGHT, BLANK_CHOTX, BLANK_CHOTY); | |
300 | |
301 /* Fill in some window manager capabilities */ | |
302 _this->info.wm_available = 1; | |
303 | |
304 /* We're done! */ | |
305 return(0); | |
306 } | |
307 | |
308 /* We support any dimension at our bit-depth */ | |
309 SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
310 { | |
311 SDL_Rect **modes; | |
312 | |
313 modes = ((SDL_Rect **)0); | |
314 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
315 modes = SDL_modelist[((format->BitsPerPixel+7)/8)-1]; | |
316 } else { | |
317 if ( format->BitsPerPixel == | |
318 _this->screen->format->BitsPerPixel ) { | |
319 modes = ((SDL_Rect **)-1); | |
320 } | |
321 } | |
322 return(modes); | |
323 } | |
324 | |
325 /* Various screen update functions available */ | |
326 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
327 | |
328 | |
329 /* Find the closest display mode for fullscreen */ | |
330 static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp, | |
331 display_mode *mode) | |
332 { | |
333 BScreen bscreen; | |
334 uint32 i, nmodes; | |
335 SDL_Rect **modes; | |
336 display_mode *dmodes; | |
756
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
337 display_mode current; |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
338 float current_refresh; |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
339 bscreen.GetMode(¤t); |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
340 current_refresh = (1000 * current.timing.pixel_clock) / |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
341 (current.timing.h_total * current.timing.v_total); |
0 | 342 |
343 modes = SDL_modelist[((bpp+7)/8)-1]; | |
344 for ( i=0; modes[i] && (modes[i]->w > width) && | |
345 (modes[i]->h > height); ++i ) { | |
346 /* still looking */ | |
347 } | |
348 if ( ! modes[i] || (modes[i]->w < width) || (modes[i]->h < width) ) { | |
349 --i; /* We went too far */ | |
350 } | |
351 width = modes[i]->w; | |
352 height = modes[i]->h; | |
353 bscreen.GetModeList(&dmodes, &nmodes); | |
354 for ( i = 0; i < nmodes; ++i ) { | |
355 if ( (bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) && | |
356 (width == dmodes[i].virtual_width) && | |
357 (height == dmodes[i].virtual_height) ) { | |
358 break; | |
359 } | |
360 } | |
361 if ( i != nmodes ) { | |
362 *mode = dmodes[i]; | |
756
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
363 if ((mode->virtual_width <= current.virtual_width) && |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
364 (mode->virtual_height <= current.virtual_height)) { |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
365 float new_refresh = (1000 * mode->timing.pixel_clock) / |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
366 (mode->timing.h_total * mode->timing.v_total); |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
367 if (new_refresh < current_refresh) { |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
368 mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
369 * current_refresh / 1000); |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
370 } |
10332c6fad2e
te: Mon, 15 Dec 2003 08:25:14 -0800 PST
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
371 } |
0 | 372 return true; |
373 } else { | |
374 return false; | |
375 } | |
376 } | |
377 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
378 static int BE_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen) |
0 | 379 { |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
380 int was_fullscreen; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
381 bool needs_unlock; |
0 | 382 BScreen bscreen; |
383 BRect bounds; | |
384 display_mode mode; | |
385 int width, height, bpp; | |
386 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
387 /* Set the fullscreen mode */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
388 was_fullscreen = SDL_Win->IsFullScreen(); |
0 | 389 SDL_Win->SetFullScreen(fullscreen); |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
390 fullscreen = SDL_Win->IsFullScreen(); |
0 | 391 |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
392 width = screen->w; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
393 height = screen->h; |
0 | 394 |
395 /* Set the appropriate video mode */ | |
396 if ( fullscreen ) { | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
397 bpp = screen->format->BitsPerPixel; |
0 | 398 bscreen.GetMode(&mode); |
399 if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) || | |
400 (width != mode.virtual_width) || | |
401 (height != mode.virtual_height)) { | |
402 if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) { | |
403 bscreen.SetMode(&mode); | |
404 /* This simply stops the next resize event from being | |
405 * sent to the SDL handler. | |
406 */ | |
407 SDL_Win->InhibitResize(); | |
408 } else { | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
409 fullscreen = 0; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
410 SDL_Win->SetFullScreen(fullscreen); |
0 | 411 } |
412 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
413 } |
206
b69bb2a368a0
Fixed flashing the screen when creating a window on BeOS
Sam Lantinga <slouken@libsdl.org>
parents:
115
diff
changeset
|
414 if ( was_fullscreen && ! fullscreen ) { |
0 | 415 bscreen.SetMode(&saved_mode); |
416 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
417 |
0 | 418 if ( SDL_Win->Lock() ) { |
419 int xoff, yoff; | |
420 if ( SDL_Win->Shown() ) { | |
421 needs_unlock = 1; | |
422 SDL_Win->Hide(); | |
423 } else { | |
424 needs_unlock = 0; | |
425 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
426 /* This resizes the window and view area, but inhibits resizing |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
427 * of the BBitmap due to the InhibitResize call above. Thus the |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
428 * bitmap (pixel data) never changes. |
0 | 429 */ |
430 SDL_Win->ResizeTo(width, height); | |
431 bounds = bscreen.Frame(); | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
432 /* Calculate offsets - used either to center window |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
433 * (windowed mode) or to set drawing offsets (fullscreen mode) |
0 | 434 */ |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
435 xoff = (bounds.IntegerWidth() - width)/2; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
436 yoff = (bounds.IntegerHeight() - height)/2; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
437 if ( fullscreen ) { |
0 | 438 /* Set offset for drawing */ |
439 SDL_Win->SetXYOffset(xoff, yoff); | |
440 } else { | |
441 /* Center window and reset the drawing offset */ | |
442 SDL_Win->SetXYOffset(0, 0); | |
443 } | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
444 if ( ! needs_unlock || was_fullscreen ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
445 /* Center the window the first time */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
446 SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f, |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
447 yoff > 0 ? (float)yoff : 0.0f); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
448 } |
0 | 449 SDL_Win->Show(); |
450 | |
451 /* Unlock the window manually after the first Show() */ | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
452 if ( needs_unlock ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
453 SDL_Win->Unlock(); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
454 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
455 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
456 |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
457 /* Set the fullscreen flag in the screen surface */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
458 if ( fullscreen ) { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
459 screen->flags |= SDL_FULLSCREEN; |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
460 } else { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
461 screen->flags &= ~SDL_FULLSCREEN; |
0 | 462 } |
463 return(1); | |
464 } | |
465 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
466 static int BE_ToggleFullScreen(_THIS, int fullscreen) |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
467 { |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
468 return BE_SetFullScreen(_this, _this->screen, fullscreen); |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
469 } |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
470 |
0 | 471 /* FIXME: check return values and cleanup here */ |
472 SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, | |
473 int width, int height, int bpp, Uint32 flags) | |
474 { | |
475 BScreen bscreen; | |
476 BBitmap *bbitmap; | |
477 BRect bounds; | |
478 | |
479 /* Create the view for this window */ | |
480 if ( SDL_Win->CreateView(flags) < 0 ) { | |
481 return(NULL); | |
482 } | |
483 | |
484 current->flags = 0; /* Clear flags */ | |
485 current->w = width; | |
486 current->h = height; | |
487 SDL_Win->SetType(B_TITLED_WINDOW); | |
488 if ( flags & SDL_NOFRAME ) { | |
489 current->flags |= SDL_NOFRAME; | |
490 SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK); | |
491 } else { | |
492 if ( (flags & SDL_RESIZABLE) && !(flags & SDL_OPENGL) ) { | |
493 current->flags |= SDL_RESIZABLE; | |
494 /* We don't want opaque resizing (TM). :-) */ | |
495 SDL_Win->SetFlags(B_OUTLINE_RESIZE); | |
496 } else { | |
497 SDL_Win->SetFlags(B_NOT_RESIZABLE|B_NOT_ZOOMABLE); | |
498 } | |
499 } | |
500 | |
501 if ( flags & SDL_OPENGL ) { | |
502 current->flags |= SDL_OPENGL; | |
503 current->pitch = 0; | |
504 current->pixels = NULL; | |
505 _this->UpdateRects = NULL; | |
506 } else { | |
507 /* Create the BBitmap framebuffer */ | |
508 bounds.top = 0; bounds.left = 0; | |
509 bounds.right = width-1; | |
510 bounds.bottom = height-1; | |
511 bbitmap = new BBitmap(bounds, bscreen.ColorSpace()); | |
512 if ( ! bbitmap->IsValid() ) { | |
513 SDL_SetError("Couldn't create screen bitmap"); | |
514 delete bbitmap; | |
515 return(NULL); | |
516 } | |
517 current->pitch = bbitmap->BytesPerRow(); | |
518 current->pixels = (void *)bbitmap->Bits(); | |
519 SDL_Win->SetBitmap(bbitmap); | |
520 _this->UpdateRects = BE_NormalUpdate; | |
521 } | |
522 | |
114
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
523 /* Set the correct fullscreen mode */ |
dabc453ce7f7
Now returns an error if unable to open audio on BeOS
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
524 BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0); |
0 | 525 |
526 /* We're done */ | |
527 return(current); | |
528 } | |
529 | |
530 /* Update the current mouse state and position */ | |
531 void BE_UpdateMouse(_THIS) | |
532 { | |
533 BPoint point; | |
534 uint32 buttons; | |
535 | |
536 if ( SDL_Win->Lock() ) { | |
537 /* Get new input state, if still active */ | |
538 if ( SDL_Win->IsActive() ) { | |
539 (SDL_Win->View())->GetMouse(&point, &buttons, true); | |
540 } else { | |
541 point.x = -1; | |
542 point.y = -1; | |
543 } | |
544 SDL_Win->Unlock(); | |
545 | |
546 if ( (point.x >= 0) && (point.x < SDL_VideoSurface->w) && | |
547 (point.y >= 0) && (point.y < SDL_VideoSurface->h) ) { | |
548 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
549 SDL_PrivateMouseMotion(0, 0, | |
550 (Sint16)point.x, (Sint16)point.y); | |
551 } else { | |
552 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
553 } | |
554 } | |
555 } | |
556 | |
557 /* We don't actually allow hardware surfaces other than the main one */ | |
558 static int BE_AllocHWSurface(_THIS, SDL_Surface *surface) | |
559 { | |
560 return(-1); | |
561 } | |
562 static void BE_FreeHWSurface(_THIS, SDL_Surface *surface) | |
563 { | |
564 return; | |
565 } | |
566 static int BE_LockHWSurface(_THIS, SDL_Surface *surface) | |
567 { | |
568 return(0); | |
569 } | |
570 static void BE_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
571 { | |
572 return; | |
573 } | |
574 | |
575 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
576 { | |
577 if ( SDL_Win->BeginDraw() ) { | |
578 int i; | |
579 | |
580 for ( i=0; i<numrects; ++i ) { | |
581 BRect rect; | |
582 | |
583 rect.top = rects[i].y; | |
584 rect.left = rects[i].x; | |
585 rect.bottom = rect.top+rects[i].h-1; | |
586 rect.right = rect.left+rects[i].w-1; | |
587 SDL_Win->DrawAsync(rect); | |
588 } | |
589 SDL_Win->EndDraw(); | |
590 } | |
591 } | |
592 | |
593 #ifdef HAVE_OPENGL | |
594 void BE_GL_SwapBuffers(_THIS) | |
595 { | |
596 SDL_Win->SwapBuffers(); | |
597 } | |
598 #endif | |
599 | |
600 /* Is the system palette settable? */ | |
601 int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
602 { | |
603 int i; | |
604 SDL_Palette *palette; | |
605 const color_map *cmap = BScreen().ColorMap(); | |
606 | |
607 /* Get the screen colormap */ | |
608 palette = _this->screen->format->palette; | |
609 for ( i=0; i<256; ++i ) { | |
610 palette->colors[i].r = cmap->color_list[i].red; | |
611 palette->colors[i].g = cmap->color_list[i].green; | |
612 palette->colors[i].b = cmap->color_list[i].blue; | |
613 } | |
614 return(0); | |
615 } | |
616 | |
617 void BE_VideoQuit(_THIS) | |
618 { | |
619 int i, j; | |
620 | |
621 if ( SDL_BlankCursor != NULL ) { | |
622 BE_FreeWMCursor(_this, SDL_BlankCursor); | |
623 SDL_BlankCursor = NULL; | |
624 } | |
625 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
626 if ( SDL_modelist[i] ) { | |
627 for ( j=0; SDL_modelist[i][j]; ++j ) { | |
628 free(SDL_modelist[i][j]); | |
629 } | |
630 free(SDL_modelist[i]); | |
631 SDL_modelist[i] = NULL; | |
632 } | |
633 } | |
634 /* Restore the original video mode */ | |
635 if ( _this->screen ) { | |
636 if ( (_this->screen->flags&SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
637 BScreen bscreen; | |
638 bscreen.SetMode(&saved_mode); | |
639 } | |
640 _this->screen->pixels = NULL; | |
641 } | |
642 SDL_QuitBeApp(); | |
643 } | |
644 | |
645 }; /* Extern C */ |