comparison src/video/bwindow/SDL_sysvideo.cc @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 3a8920cc822b
children c611cb0638b2
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
26 #include <unistd.h> 26 #include <unistd.h>
27 27
28 #include "SDL_BWin.h" 28 #include "SDL_BWin.h"
29 #include "SDL_timer.h" 29 #include "SDL_timer.h"
30 30
31 extern "C" { 31 extern "C"
32 {
32 33
33 #include "../SDL_sysvideo.h" 34 #include "../SDL_sysvideo.h"
34 #include "../../events/SDL_events_c.h" 35 #include "../../events/SDL_events_c.h"
35 #include "SDL_sysevents_c.h" 36 #include "SDL_sysevents_c.h"
36 #include "SDL_sysmouse_c.h" 37 #include "SDL_sysmouse_c.h"
38 #include "SDL_lowvideo.h" 39 #include "SDL_lowvideo.h"
39 #include "../SDL_yuvfuncs.h" 40 #include "../SDL_yuvfuncs.h"
40 #include "SDL_sysyuv.h" 41 #include "SDL_sysyuv.h"
41 #include "../blank_cursor.h" 42 #include "../blank_cursor.h"
42 43
43 #define BEOS_HIDDEN_SIZE 32 /* starting hidden window size */ 44 #define BEOS_HIDDEN_SIZE 32 /* starting hidden window size */
44 45
45 /* Initialization/Query functions */ 46 /* Initialization/Query functions */
46 static int BE_VideoInit(_THIS, SDL_PixelFormat *vformat); 47 static int BE_VideoInit(_THIS, SDL_PixelFormat * vformat);
47 static SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 48 static SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat * format,
48 static SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 49 Uint32 flags);
49 static void BE_UpdateMouse(_THIS); 50 static SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface * current,
50 static int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 51 int width, int height, int bpp,
51 static void BE_VideoQuit(_THIS); 52 Uint32 flags);
53 static void BE_UpdateMouse(_THIS);
54 static int BE_SetColors(_THIS, int firstcolor, int ncolors,
55 SDL_Color * colors);
56 static void BE_VideoQuit(_THIS);
52 57
53 /* Hardware surface functions */ 58 /* Hardware surface functions */
54 static int BE_AllocHWSurface(_THIS, SDL_Surface *surface); 59 static int BE_AllocHWSurface(_THIS, SDL_Surface * surface);
55 static int BE_LockHWSurface(_THIS, SDL_Surface *surface); 60 static int BE_LockHWSurface(_THIS, SDL_Surface * surface);
56 static void BE_UnlockHWSurface(_THIS, SDL_Surface *surface); 61 static void BE_UnlockHWSurface(_THIS, SDL_Surface * surface);
57 static void BE_FreeHWSurface(_THIS, SDL_Surface *surface); 62 static void BE_FreeHWSurface(_THIS, SDL_Surface * surface);
58 63
59 static int BE_ToggleFullScreen(_THIS, int fullscreen); 64 static int BE_ToggleFullScreen(_THIS, int fullscreen);
60 static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display); 65 static SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height,
66 Uint32 format,
67 SDL_Surface * display);
61 68
62 /* OpenGL functions */ 69 /* OpenGL functions */
63 #if SDL_VIDEO_OPENGL 70 #if SDL_VIDEO_OPENGL
64 static int BE_GL_LoadLibrary(_THIS, const char *path); 71 static int BE_GL_LoadLibrary(_THIS, const char *path);
65 static void* BE_GL_GetProcAddress(_THIS, const char *proc); 72 static void *BE_GL_GetProcAddress(_THIS, const char *proc);
66 static int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); 73 static int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
67 static int BE_GL_MakeCurrent(_THIS); 74 static int BE_GL_MakeCurrent(_THIS);
68 static void BE_GL_SwapBuffers(_THIS); 75 static void BE_GL_SwapBuffers(_THIS);
69 #endif 76 #endif
70 77
71 /* FB driver bootstrap functions */ 78 /* FB driver bootstrap functions */
72 79
73 static int BE_Available(void) 80 static int BE_Available(void)
74 { 81 {
75 return(1); 82 return (1);
76 } 83 }
77 84
78 static void BE_DeleteDevice(SDL_VideoDevice *device) 85 static void BE_DeleteDevice(SDL_VideoDevice * device)
79 { 86 {
80 SDL_free(device->hidden); 87 SDL_free(device->hidden);
81 SDL_free(device); 88 SDL_free(device);
82 } 89 }
83 90
84 static SDL_VideoDevice *BE_CreateDevice(int devindex) 91 static SDL_VideoDevice *BE_CreateDevice(int devindex)
85 { 92 {
86 SDL_VideoDevice *device; 93 SDL_VideoDevice *device;
87 94
88 /* Initialize all variables that we clean on shutdown */ 95 /* Initialize all variables that we clean on shutdown */
89 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 96 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
90 if ( device ) { 97 if (device) {
91 SDL_memset(device, 0, (sizeof *device)); 98 SDL_memset(device, 0, (sizeof *device));
92 device->hidden = (struct SDL_PrivateVideoData *) 99 device->hidden = (struct SDL_PrivateVideoData *)
93 SDL_malloc((sizeof *device->hidden)); 100 SDL_malloc((sizeof *device->hidden));
94 } 101 }
95 if ( (device == NULL) || (device->hidden == NULL) ) { 102 if ((device == NULL) || (device->hidden == NULL)) {
96 SDL_OutOfMemory(); 103 SDL_OutOfMemory();
97 if ( device ) { 104 if (device) {
98 SDL_free(device); 105 SDL_free(device);
99 } 106 }
100 return(0); 107 return (0);
101 } 108 }
102 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 109 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
103 110
104 /* Set the function pointers */ 111 /* Set the function pointers */
105 /* Initialization/Query functions */ 112 /* Initialization/Query functions */
106 device->VideoInit = BE_VideoInit; 113 device->VideoInit = BE_VideoInit;
107 device->ListModes = BE_ListModes; 114 device->ListModes = BE_ListModes;
108 device->SetVideoMode = BE_SetVideoMode; 115 device->SetVideoMode = BE_SetVideoMode;
109 device->ToggleFullScreen = BE_ToggleFullScreen; 116 device->ToggleFullScreen = BE_ToggleFullScreen;
110 device->UpdateMouse = BE_UpdateMouse; 117 device->UpdateMouse = BE_UpdateMouse;
111 device->CreateYUVOverlay = BE_CreateYUVOverlay; 118 device->CreateYUVOverlay = BE_CreateYUVOverlay;
112 device->SetColors = BE_SetColors; 119 device->SetColors = BE_SetColors;
113 device->UpdateRects = NULL; 120 device->UpdateRects = NULL;
114 device->VideoQuit = BE_VideoQuit; 121 device->VideoQuit = BE_VideoQuit;
115 /* Hardware acceleration functions */ 122 /* Hardware acceleration functions */
116 device->AllocHWSurface = BE_AllocHWSurface; 123 device->AllocHWSurface = BE_AllocHWSurface;
117 device->CheckHWBlit = NULL; 124 device->CheckHWBlit = NULL;
118 device->FillHWRect = NULL; 125 device->FillHWRect = NULL;
119 device->SetHWColorKey = NULL; 126 device->SetHWColorKey = NULL;
120 device->SetHWAlpha = NULL; 127 device->SetHWAlpha = NULL;
121 device->LockHWSurface = BE_LockHWSurface; 128 device->LockHWSurface = BE_LockHWSurface;
122 device->UnlockHWSurface = BE_UnlockHWSurface; 129 device->UnlockHWSurface = BE_UnlockHWSurface;
123 device->FlipHWSurface = NULL; 130 device->FlipHWSurface = NULL;
124 device->FreeHWSurface = BE_FreeHWSurface; 131 device->FreeHWSurface = BE_FreeHWSurface;
125 /* Gamma support */ 132 /* Gamma support */
126 #if SDL_VIDEO_OPENGL 133 #if SDL_VIDEO_OPENGL
127 /* OpenGL support */ 134 /* OpenGL support */
128 device->GL_LoadLibrary = BE_GL_LoadLibrary; 135 device->GL_LoadLibrary = BE_GL_LoadLibrary;
129 device->GL_GetProcAddress = BE_GL_GetProcAddress; 136 device->GL_GetProcAddress = BE_GL_GetProcAddress;
130 device->GL_GetAttribute = BE_GL_GetAttribute; 137 device->GL_GetAttribute = BE_GL_GetAttribute;
131 device->GL_MakeCurrent = BE_GL_MakeCurrent; 138 device->GL_MakeCurrent = BE_GL_MakeCurrent;
132 device->GL_SwapBuffers = BE_GL_SwapBuffers; 139 device->GL_SwapBuffers = BE_GL_SwapBuffers;
133 #endif 140 #endif
134 /* Window manager functions */ 141 /* Window manager functions */
135 device->SetCaption = BE_SetWMCaption; 142 device->SetCaption = BE_SetWMCaption;
136 device->SetIcon = NULL; 143 device->SetIcon = NULL;
137 device->IconifyWindow = BE_IconifyWindow; 144 device->IconifyWindow = BE_IconifyWindow;
138 device->GrabInput = NULL; 145 device->GrabInput = NULL;
139 device->GetWMInfo = BE_GetWMInfo; 146 device->GetWMInfo = BE_GetWMInfo;
140 /* Cursor manager functions */ 147 /* Cursor manager functions */
141 device->FreeWMCursor = BE_FreeWMCursor; 148 device->FreeWMCursor = BE_FreeWMCursor;
142 device->CreateWMCursor = BE_CreateWMCursor; 149 device->CreateWMCursor = BE_CreateWMCursor;
143 device->ShowWMCursor = BE_ShowWMCursor; 150 device->ShowWMCursor = BE_ShowWMCursor;
144 device->WarpWMCursor = BE_WarpWMCursor; 151 device->WarpWMCursor = BE_WarpWMCursor;
145 device->MoveWMCursor = NULL; 152 device->MoveWMCursor = NULL;
146 device->CheckMouseMode = NULL; 153 device->CheckMouseMode = NULL;
147 /* Event manager functions */ 154 /* Event manager functions */
148 device->InitOSKeymap = BE_InitOSKeymap; 155 device->InitOSKeymap = BE_InitOSKeymap;
149 device->PumpEvents = BE_PumpEvents; 156 device->PumpEvents = BE_PumpEvents;
150 157
151 device->free = BE_DeleteDevice; 158 device->free = BE_DeleteDevice;
152 159
153 /* Set the driver flags */ 160 /* Set the driver flags */
154 device->handles_any_size = 1; 161 device->handles_any_size = 1;
155 162
156 return device; 163 return device;
157 } 164 }
158 165
159 VideoBootStrap BWINDOW_bootstrap = { 166 VideoBootStrap BWINDOW_bootstrap = {
160 "bwindow", "BDirectWindow graphics", 167 "bwindow", "BDirectWindow graphics",
161 BE_Available, BE_CreateDevice 168 BE_Available, BE_CreateDevice
162 }; 169 };
163 170
164 static inline int ColorSpaceToBitsPerPixel(uint32 colorspace) 171 static inline int ColorSpaceToBitsPerPixel(uint32 colorspace)
165 { 172 {
166 int bitsperpixel; 173 int bitsperpixel;
167 174
168 bitsperpixel = 0; 175 bitsperpixel = 0;
169 switch (colorspace) { 176 switch (colorspace) {
170 case B_CMAP8: 177 case B_CMAP8:
171 bitsperpixel = 8; 178 bitsperpixel = 8;
172 break; 179 break;
173 case B_RGB15: 180 case B_RGB15:
174 case B_RGBA15: 181 case B_RGBA15:
175 case B_RGB15_BIG: 182 case B_RGB15_BIG:
176 case B_RGBA15_BIG: 183 case B_RGBA15_BIG:
177 bitsperpixel = 15; 184 bitsperpixel = 15;
178 break; 185 break;
179 case B_RGB16: 186 case B_RGB16:
180 case B_RGB16_BIG: 187 case B_RGB16_BIG:
181 bitsperpixel = 16; 188 bitsperpixel = 16;
182 break; 189 break;
183 case B_RGB32: 190 case B_RGB32:
184 case B_RGBA32: 191 case B_RGBA32:
185 case B_RGB32_BIG: 192 case B_RGB32_BIG:
186 case B_RGBA32_BIG: 193 case B_RGBA32_BIG:
187 bitsperpixel = 32; 194 bitsperpixel = 32;
188 break; 195 break;
189 default: 196 default:
190 break; 197 break;
191 } 198 }
192 return(bitsperpixel); 199 return (bitsperpixel);
193 } 200 }
194 201
195 /* Function to sort the display_list in bscreen */ 202 /* Function to sort the display_list in bscreen */
196 static int CompareModes(const void *A, const void *B) 203 static int CompareModes(const void *A, const void *B)
197 { 204 {
198 const display_mode *a = (display_mode *)A; 205 const display_mode *a = (display_mode *) A;
199 const display_mode *b = (display_mode *)B; 206 const display_mode *b = (display_mode *) B;
200 207
201 if ( a->space == b->space ) { 208 if (a->space == b->space) {
202 return((b->virtual_width*b->virtual_height)- 209 return ((b->virtual_width * b->virtual_height) -
203 (a->virtual_width*a->virtual_height)); 210 (a->virtual_width * a->virtual_height));
204 } else { 211 } else {
205 return(ColorSpaceToBitsPerPixel(b->space)- 212 return (ColorSpaceToBitsPerPixel(b->space) -
206 ColorSpaceToBitsPerPixel(a->space)); 213 ColorSpaceToBitsPerPixel(a->space));
207 } 214 }
208 } 215 }
209 216
210 /* Yes, this isn't the fastest it could be, but it works nicely */ 217 /* Yes, this isn't the fastest it could be, but it works nicely */
211 static int BE_AddMode(_THIS, int index, unsigned int w, unsigned int h) 218 static int BE_AddMode(_THIS, int index, unsigned int w, unsigned int h)
212 { 219 {
213 SDL_Rect *mode; 220 SDL_Rect *mode;
214 int i; 221 int i;
215 int next_mode; 222 int next_mode;
216 223
217 /* Check to see if we already have this mode */ 224 /* Check to see if we already have this mode */
218 if ( SDL_nummodes[index] > 0 ) { 225 if (SDL_nummodes[index] > 0) {
219 for ( i=SDL_nummodes[index]-1; i >= 0; --i ) { 226 for (i = SDL_nummodes[index] - 1; i >= 0; --i) {
220 mode = SDL_modelist[index][i]; 227 mode = SDL_modelist[index][i];
221 if ( (mode->w == w) && (mode->h == h) ) { 228 if ((mode->w == w) && (mode->h == h)) {
222 #ifdef BWINDOW_DEBUG 229 #ifdef BWINDOW_DEBUG
223 fprintf(stderr, "We already have mode %dx%d at %d bytes per pixel\n", w, h, index+1); 230 fprintf(stderr,
231 "We already have mode %dx%d at %d bytes per pixel\n",
232 w, h, index + 1);
224 #endif 233 #endif
225 return(0); 234 return (0);
226 } 235 }
227 } 236 }
228 } 237 }
229 238
230 /* Set up the new video mode rectangle */ 239 /* Set up the new video mode rectangle */
231 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); 240 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
232 if ( mode == NULL ) { 241 if (mode == NULL) {
233 SDL_OutOfMemory(); 242 SDL_OutOfMemory();
234 return(-1); 243 return (-1);
235 } 244 }
236 mode->x = 0; 245 mode->x = 0;
237 mode->y = 0; 246 mode->y = 0;
238 mode->w = w; 247 mode->w = w;
239 mode->h = h; 248 mode->h = h;
240 #ifdef BWINDOW_DEBUG 249 #ifdef BWINDOW_DEBUG
241 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1); 250 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h,
251 index + 1);
242 #endif 252 #endif
243 253
244 /* Allocate the new list of modes, and fill in the new mode */ 254 /* Allocate the new list of modes, and fill in the new mode */
245 next_mode = SDL_nummodes[index]; 255 next_mode = SDL_nummodes[index];
246 SDL_modelist[index] = (SDL_Rect **) 256 SDL_modelist[index] = (SDL_Rect **)
247 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 257 SDL_realloc(SDL_modelist[index],
248 if ( SDL_modelist[index] == NULL ) { 258 (1 + next_mode + 1) * sizeof(SDL_Rect *));
249 SDL_OutOfMemory(); 259 if (SDL_modelist[index] == NULL) {
250 SDL_nummodes[index] = 0; 260 SDL_OutOfMemory();
251 SDL_free(mode); 261 SDL_nummodes[index] = 0;
252 return(-1); 262 SDL_free(mode);
253 } 263 return (-1);
254 SDL_modelist[index][next_mode] = mode; 264 }
255 SDL_modelist[index][next_mode+1] = NULL; 265 SDL_modelist[index][next_mode] = mode;
256 SDL_nummodes[index]++; 266 SDL_modelist[index][next_mode + 1] = NULL;
257 267 SDL_nummodes[index]++;
258 return(0); 268
259 } 269 return (0);
260 270 }
261 int BE_VideoInit(_THIS, SDL_PixelFormat *vformat) 271
262 { 272 int BE_VideoInit(_THIS, SDL_PixelFormat * vformat)
263 display_mode *modes; 273 {
264 uint32 i, nmodes; 274 display_mode *modes;
265 int bpp; 275 uint32 i, nmodes;
266 BRect bounds; 276 int bpp;
267 277 BRect bounds;
268 /* Initialize the Be Application for appserver interaction */ 278
269 if ( SDL_InitBeApp() < 0 ) { 279 /* Initialize the Be Application for appserver interaction */
270 return(-1); 280 if (SDL_InitBeApp() < 0) {
271 } 281 return (-1);
272 282 }
273 /* It is important that this be created after SDL_InitBeApp() */ 283
274 BScreen bscreen; 284 /* It is important that this be created after SDL_InitBeApp() */
275 285 BScreen bscreen;
276 /* Save the current display mode */ 286
277 bscreen.GetMode(&saved_mode); 287 /* Save the current display mode */
278 _this->info.current_w = saved_mode.virtual_width; 288 bscreen.GetMode(&saved_mode);
279 _this->info.current_h = saved_mode.virtual_height; 289 _this->info.current_w = saved_mode.virtual_width;
280 290 _this->info.current_h = saved_mode.virtual_height;
281 /* Determine the screen depth */ 291
282 vformat->BitsPerPixel = ColorSpaceToBitsPerPixel(bscreen.ColorSpace()); 292 /* Determine the screen depth */
283 if ( vformat->BitsPerPixel == 0 ) { 293 vformat->BitsPerPixel =
284 SDL_SetError("Unknown BScreen colorspace: 0x%x", 294 ColorSpaceToBitsPerPixel(bscreen.ColorSpace());
285 bscreen.ColorSpace()); 295 if (vformat->BitsPerPixel == 0) {
286 return(-1); 296 SDL_SetError("Unknown BScreen colorspace: 0x%x",
287 } 297 bscreen.ColorSpace());
288 298 return (-1);
289 /* Get the video modes we can switch to in fullscreen mode */ 299 }
290 bscreen.GetModeList(&modes, &nmodes); 300
291 SDL_qsort(modes, nmodes, sizeof *modes, CompareModes); 301 /* Get the video modes we can switch to in fullscreen mode */
292 for ( i=0; i<nmodes; ++i ) { 302 bscreen.GetModeList(&modes, &nmodes);
293 bpp = ColorSpaceToBitsPerPixel(modes[i].space); 303 SDL_qsort(modes, nmodes, sizeof *modes, CompareModes);
294 //if ( bpp != 0 ) { // There are bugs in changing colorspace 304 for (i = 0; i < nmodes; ++i) {
295 if ( modes[i].space == saved_mode.space ) { 305 bpp = ColorSpaceToBitsPerPixel(modes[i].space);
296 BE_AddMode(_this, ((bpp+7)/8)-1, 306 //if ( bpp != 0 ) { // There are bugs in changing colorspace
297 modes[i].virtual_width, 307 if (modes[i].space == saved_mode.space) {
298 modes[i].virtual_height); 308 BE_AddMode(_this, ((bpp + 7) / 8) - 1,
299 } 309 modes[i].virtual_width, modes[i].virtual_height);
300 } 310 }
301 311 }
302 /* Create the window and view */ 312
303 bounds.top = 0; bounds.left = 0; 313 /* Create the window and view */
304 bounds.right = BEOS_HIDDEN_SIZE; 314 bounds.top = 0;
305 bounds.bottom = BEOS_HIDDEN_SIZE; 315 bounds.left = 0;
306 SDL_Win = new SDL_BWin(bounds); 316 bounds.right = BEOS_HIDDEN_SIZE;
317 bounds.bottom = BEOS_HIDDEN_SIZE;
318 SDL_Win = new SDL_BWin(bounds);
307 319
308 #if SDL_VIDEO_OPENGL 320 #if SDL_VIDEO_OPENGL
309 /* testgl application doesn't load library, just tries to load symbols */ 321 /* testgl application doesn't load library, just tries to load symbols */
310 /* is it correct? if so we have to load library here */ 322 /* is it correct? if so we have to load library here */
311 BE_GL_LoadLibrary(_this, NULL); 323 BE_GL_LoadLibrary(_this, NULL);
312 #endif 324 #endif
313 325
314 /* Create the clear cursor */ 326 /* Create the clear cursor */
315 SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask, 327 SDL_BlankCursor = BE_CreateWMCursor(_this, blank_cdata, blank_cmask,
316 BLANK_CWIDTH, BLANK_CHEIGHT, BLANK_CHOTX, BLANK_CHOTY); 328 BLANK_CWIDTH, BLANK_CHEIGHT,
317 329 BLANK_CHOTX, BLANK_CHOTY);
318 /* Fill in some window manager capabilities */ 330
319 _this->info.wm_available = 1; 331 /* Fill in some window manager capabilities */
320 332 _this->info.wm_available = 1;
321 /* We're done! */ 333
322 return(0); 334 /* We're done! */
323 } 335 return (0);
336 }
324 337
325 /* We support any dimension at our bit-depth */ 338 /* We support any dimension at our bit-depth */
326 SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 339 SDL_Rect **BE_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
327 { 340 {
328 SDL_Rect **modes; 341 SDL_Rect **modes;
329 342
330 modes = ((SDL_Rect **)0); 343 modes = ((SDL_Rect **) 0);
331 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 344 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
332 modes = SDL_modelist[((format->BitsPerPixel+7)/8)-1]; 345 modes = SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1];
333 } else { 346 } else {
334 if ( format->BitsPerPixel == 347 if (format->BitsPerPixel == _this->screen->format->BitsPerPixel) {
335 _this->screen->format->BitsPerPixel ) { 348 modes = ((SDL_Rect **) - 1);
336 modes = ((SDL_Rect **)-1); 349 }
337 } 350 }
338 } 351 return (modes);
339 return(modes); 352 }
340 }
341 353
342 /* Various screen update functions available */ 354 /* Various screen update functions available */
343 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); 355 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect * rects);
344 356
345 357
346 /* Find the closest display mode for fullscreen */ 358 /* Find the closest display mode for fullscreen */
347 static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp, 359 static bool BE_FindClosestFSMode(_THIS, int width, int height, int bpp,
348 display_mode *mode) 360 display_mode * mode)
349 { 361 {
350 BScreen bscreen; 362 BScreen bscreen;
351 uint32 i, nmodes; 363 uint32 i, nmodes;
352 SDL_Rect **modes; 364 SDL_Rect **modes;
353 display_mode *dmodes; 365 display_mode *dmodes;
354 display_mode current; 366 display_mode current;
355 float current_refresh; 367 float current_refresh;
356 bscreen.GetMode(&current); 368 bscreen.GetMode(&current);
357 current_refresh = (1000 * current.timing.pixel_clock) / 369 current_refresh = (1000 * current.timing.pixel_clock) /
358 (current.timing.h_total * current.timing.v_total); 370 (current.timing.h_total * current.timing.v_total);
359 371
360 modes = SDL_modelist[((bpp+7)/8)-1]; 372 modes = SDL_modelist[((bpp + 7) / 8) - 1];
361 for ( i=0; modes[i] && (modes[i]->w > width) && 373 for (i = 0; modes[i] && (modes[i]->w > width) &&
362 (modes[i]->h > height); ++i ) { 374 (modes[i]->h > height); ++i) {
363 /* still looking */ 375 /* still looking */
364 } 376 }
365 if ( ! modes[i] || (modes[i]->w < width) || (modes[i]->h < width) ) { 377 if (!modes[i] || (modes[i]->w < width) || (modes[i]->h < width)) {
366 --i; /* We went too far */ 378 --i; /* We went too far */
367 } 379 }
368 width = modes[i]->w; 380 width = modes[i]->w;
369 height = modes[i]->h; 381 height = modes[i]->h;
370 bscreen.GetModeList(&dmodes, &nmodes); 382 bscreen.GetModeList(&dmodes, &nmodes);
371 for ( i = 0; i < nmodes; ++i ) { 383 for (i = 0; i < nmodes; ++i) {
372 if ( (bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) && 384 if ((bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) &&
373 (width == dmodes[i].virtual_width) && 385 (width == dmodes[i].virtual_width) &&
374 (height == dmodes[i].virtual_height) ) { 386 (height == dmodes[i].virtual_height)) {
375 break; 387 break;
376 } 388 }
377 } 389 }
378 if ( i != nmodes ) { 390 if (i != nmodes) {
379 *mode = dmodes[i]; 391 *mode = dmodes[i];
380 if ((mode->virtual_width <= current.virtual_width) && 392 if ((mode->virtual_width <= current.virtual_width) &&
381 (mode->virtual_height <= current.virtual_height)) { 393 (mode->virtual_height <= current.virtual_height)) {
382 float new_refresh = (1000 * mode->timing.pixel_clock) / 394 float new_refresh = (1000 * mode->timing.pixel_clock) /
383 (mode->timing.h_total * mode->timing.v_total); 395 (mode->timing.h_total * mode->timing.v_total);
384 if (new_refresh < current_refresh) { 396 if (new_refresh < current_refresh) {
385 mode->timing.pixel_clock = (uint32)((mode->timing.h_total * mode->timing.v_total) 397 mode->timing.pixel_clock =
386 * current_refresh / 1000); 398 (uint32) ((mode->timing.h_total *
387 } 399 mode->timing.v_total) *
388 } 400 current_refresh / 1000);
389 return true; 401 }
390 } else { 402 }
391 return false; 403 return true;
392 } 404 } else {
393 } 405 return false;
394 406 }
395 static int BE_SetFullScreen(_THIS, SDL_Surface *screen, int fullscreen) 407 }
396 { 408
397 int was_fullscreen; 409 static int BE_SetFullScreen(_THIS, SDL_Surface * screen, int fullscreen)
398 bool needs_unlock; 410 {
399 BScreen bscreen; 411 int was_fullscreen;
400 BRect bounds; 412 bool needs_unlock;
401 display_mode mode; 413 BScreen bscreen;
402 int width, height, bpp; 414 BRect bounds;
403 415 display_mode mode;
404 /* Set the fullscreen mode */ 416 int width, height, bpp;
405 was_fullscreen = SDL_Win->IsFullScreen(); 417
406 SDL_Win->SetFullScreen(fullscreen); 418 /* Set the fullscreen mode */
407 fullscreen = SDL_Win->IsFullScreen(); 419 was_fullscreen = SDL_Win->IsFullScreen();
408 420 SDL_Win->SetFullScreen(fullscreen);
409 width = screen->w; 421 fullscreen = SDL_Win->IsFullScreen();
410 height = screen->h; 422
411 423 width = screen->w;
412 /* Set the appropriate video mode */ 424 height = screen->h;
413 if ( fullscreen ) { 425
414 bpp = screen->format->BitsPerPixel; 426 /* Set the appropriate video mode */
415 bscreen.GetMode(&mode); 427 if (fullscreen) {
416 if ( (bpp != ColorSpaceToBitsPerPixel(mode.space)) || 428 bpp = screen->format->BitsPerPixel;
417 (width != mode.virtual_width) || 429 bscreen.GetMode(&mode);
418 (height != mode.virtual_height)) { 430 if ((bpp != ColorSpaceToBitsPerPixel(mode.space)) ||
419 if(BE_FindClosestFSMode(_this, width, height, bpp, &mode)) { 431 (width != mode.virtual_width) ||
420 bscreen.SetMode(&mode); 432 (height != mode.virtual_height)) {
421 /* This simply stops the next resize event from being 433 if (BE_FindClosestFSMode(_this, width, height, bpp, &mode)) {
422 * sent to the SDL handler. 434 bscreen.SetMode(&mode);
423 */ 435 /* This simply stops the next resize event from being
424 SDL_Win->InhibitResize(); 436 * sent to the SDL handler.
425 } else { 437 */
426 fullscreen = 0; 438 SDL_Win->InhibitResize();
427 SDL_Win->SetFullScreen(fullscreen); 439 } else {
428 } 440 fullscreen = 0;
429 } 441 SDL_Win->SetFullScreen(fullscreen);
430 } 442 }
431 if ( was_fullscreen && ! fullscreen ) { 443 }
432 bscreen.SetMode(&saved_mode); 444 }
433 } 445 if (was_fullscreen && !fullscreen) {
434 446 bscreen.SetMode(&saved_mode);
435 if ( SDL_Win->Lock() ) { 447 }
436 int xoff, yoff; 448
437 if ( SDL_Win->Shown() ) { 449 if (SDL_Win->Lock()) {
438 needs_unlock = 1; 450 int xoff, yoff;
439 SDL_Win->Hide(); 451 if (SDL_Win->Shown()) {
440 } else { 452 needs_unlock = 1;
441 needs_unlock = 0; 453 SDL_Win->Hide();
442 } 454 } else {
443 /* This resizes the window and view area, but inhibits resizing 455 needs_unlock = 0;
444 * of the BBitmap due to the InhibitResize call above. Thus the 456 }
445 * bitmap (pixel data) never changes. 457 /* This resizes the window and view area, but inhibits resizing
446 */ 458 * of the BBitmap due to the InhibitResize call above. Thus the
447 SDL_Win->ResizeTo(width, height); 459 * bitmap (pixel data) never changes.
448 bounds = bscreen.Frame(); 460 */
449 /* Calculate offsets - used either to center window 461 SDL_Win->ResizeTo(width, height);
450 * (windowed mode) or to set drawing offsets (fullscreen mode) 462 bounds = bscreen.Frame();
451 */ 463 /* Calculate offsets - used either to center window
452 xoff = (bounds.IntegerWidth() - width)/2; 464 * (windowed mode) or to set drawing offsets (fullscreen mode)
453 yoff = (bounds.IntegerHeight() - height)/2; 465 */
454 if ( fullscreen ) { 466 xoff = (bounds.IntegerWidth() - width) / 2;
455 /* Set offset for drawing */ 467 yoff = (bounds.IntegerHeight() - height) / 2;
456 SDL_Win->SetXYOffset(xoff, yoff); 468 if (fullscreen) {
457 } else { 469 /* Set offset for drawing */
458 /* Center window and reset the drawing offset */ 470 SDL_Win->SetXYOffset(xoff, yoff);
459 SDL_Win->SetXYOffset(0, 0); 471 } else {
460 } 472 /* Center window and reset the drawing offset */
461 if ( ! needs_unlock || was_fullscreen ) { 473 SDL_Win->SetXYOffset(0, 0);
462 /* Center the window the first time */ 474 }
463 SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f, 475 if (!needs_unlock || was_fullscreen) {
464 yoff > 0 ? (float)yoff : 0.0f); 476 /* Center the window the first time */
465 } 477 SDL_Win->MoveTo(xoff > 0 ? (float) xoff : 0.0f,
466 SDL_Win->Show(); 478 yoff > 0 ? (float) yoff : 0.0f);
467 479 }
468 /* Unlock the window manually after the first Show() */ 480 SDL_Win->Show();
469 if ( needs_unlock ) { 481
470 SDL_Win->Unlock(); 482 /* Unlock the window manually after the first Show() */
471 } 483 if (needs_unlock) {
472 } 484 SDL_Win->Unlock();
473 485 }
474 /* Set the fullscreen flag in the screen surface */ 486 }
475 if ( fullscreen ) { 487
476 screen->flags |= SDL_FULLSCREEN; 488 /* Set the fullscreen flag in the screen surface */
477 } else { 489 if (fullscreen) {
478 screen->flags &= ~SDL_FULLSCREEN; 490 screen->flags |= SDL_FULLSCREEN;
479 } 491 } else {
480 return(1); 492 screen->flags &= ~SDL_FULLSCREEN;
481 } 493 }
482 494 return (1);
483 static int BE_ToggleFullScreen(_THIS, int fullscreen) 495 }
484 { 496
485 return BE_SetFullScreen(_this, _this->screen, fullscreen); 497 static int BE_ToggleFullScreen(_THIS, int fullscreen)
486 } 498 {
499 return BE_SetFullScreen(_this, _this->screen, fullscreen);
500 }
487 501
488 /* FIXME: check return values and cleanup here */ 502 /* FIXME: check return values and cleanup here */
489 SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface *current, 503 SDL_Surface *BE_SetVideoMode(_THIS, SDL_Surface * current,
490 int width, int height, int bpp, Uint32 flags) 504 int width, int height, int bpp, Uint32 flags)
491 { 505 {
492 BScreen bscreen; 506 BScreen bscreen;
493 BBitmap *bbitmap; 507 BBitmap *bbitmap;
494 BRect bounds; 508 BRect bounds;
495 Uint32 gl_flags = 0; 509 Uint32 gl_flags = 0;
496 510
497 /* Only RGB works on r5 currently */ 511 /* Only RGB works on r5 currently */
498 gl_flags = BGL_RGB; 512 gl_flags = BGL_RGB;
499 if (_this->gl_config.double_buffer) 513 if (_this->gl_config.double_buffer)
500 gl_flags |= BGL_DOUBLE; 514 gl_flags |= BGL_DOUBLE;
501 else 515 else
502 gl_flags |= BGL_SINGLE; 516 gl_flags |= BGL_SINGLE;
503 if (_this->gl_config.alpha_size > 0 || bpp == 32) 517 if (_this->gl_config.alpha_size > 0 || bpp == 32)
504 gl_flags |= BGL_ALPHA; 518 gl_flags |= BGL_ALPHA;
505 if (_this->gl_config.depth_size > 0) 519 if (_this->gl_config.depth_size > 0)
506 gl_flags |= BGL_DEPTH; 520 gl_flags |= BGL_DEPTH;
507 if (_this->gl_config.stencil_size > 0) 521 if (_this->gl_config.stencil_size > 0)
508 gl_flags |= BGL_STENCIL; 522 gl_flags |= BGL_STENCIL;
509 if (_this->gl_config.accum_red_size > 0 523 if (_this->gl_config.accum_red_size > 0
510 || _this->gl_config.accum_green_size > 0 524 || _this->gl_config.accum_green_size > 0
511 || _this->gl_config.accum_blue_size > 0 525 || _this->gl_config.accum_blue_size > 0
512 || _this->gl_config.accum_alpha_size > 0) 526 || _this->gl_config.accum_alpha_size > 0)
513 gl_flags |= BGL_ACCUM; 527 gl_flags |= BGL_ACCUM;
514 528
515 /* Create the view for this window, using found flags */ 529 /* Create the view for this window, using found flags */
516 if ( SDL_Win->CreateView(flags, gl_flags) < 0 ) { 530 if (SDL_Win->CreateView(flags, gl_flags) < 0) {
517 return(NULL); 531 return (NULL);
518 } 532 }
519 533
520 current->flags = 0; /* Clear flags */ 534 current->flags = 0; /* Clear flags */
521 current->w = width; 535 current->w = width;
522 current->h = height; 536 current->h = height;
523 SDL_Win->SetType(B_TITLED_WINDOW); 537 SDL_Win->SetType(B_TITLED_WINDOW);
524 if ( flags & SDL_NOFRAME ) { 538 if (flags & SDL_NOFRAME) {
525 current->flags |= SDL_NOFRAME; 539 current->flags |= SDL_NOFRAME;
526 SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK); 540 SDL_Win->SetLook(B_NO_BORDER_WINDOW_LOOK);
527 } else { 541 } else {
528 if ( (flags & SDL_RESIZABLE) && !(flags & SDL_OPENGL) ) { 542 if ((flags & SDL_RESIZABLE) && !(flags & SDL_INTERNALOPENGL)) {
529 current->flags |= SDL_RESIZABLE; 543 current->flags |= SDL_RESIZABLE;
530 /* We don't want opaque resizing (TM). :-) */ 544 /* We don't want opaque resizing (TM). :-) */
531 SDL_Win->SetFlags(B_OUTLINE_RESIZE); 545 SDL_Win->SetFlags(B_OUTLINE_RESIZE);
532 } else { 546 } else {
533 SDL_Win->SetFlags(B_NOT_RESIZABLE|B_NOT_ZOOMABLE); 547 SDL_Win->SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
534 } 548 }
535 } 549 }
536 550
537 if ( flags & SDL_OPENGL ) { 551 if (flags & SDL_INTERNALOPENGL) {
538 current->flags |= SDL_OPENGL; 552 current->flags |= SDL_INTERNALOPENGL;
539 current->pitch = 0; 553 current->pitch = 0;
540 current->pixels = NULL; 554 current->pixels = NULL;
541 _this->UpdateRects = NULL; 555 _this->UpdateRects = NULL;
542 } else { 556 } else {
543 /* Create the BBitmap framebuffer */ 557 /* Create the BBitmap framebuffer */
544 bounds.top = 0; bounds.left = 0; 558 bounds.top = 0;
545 bounds.right = width-1; 559 bounds.left = 0;
546 bounds.bottom = height-1; 560 bounds.right = width - 1;
547 bbitmap = new BBitmap(bounds, bscreen.ColorSpace()); 561 bounds.bottom = height - 1;
548 if ( ! bbitmap->IsValid() ) { 562 bbitmap = new BBitmap(bounds, bscreen.ColorSpace());
549 SDL_SetError("Couldn't create screen bitmap"); 563 if (!bbitmap->IsValid()) {
550 delete bbitmap; 564 SDL_SetError("Couldn't create screen bitmap");
551 return(NULL); 565 delete bbitmap;
552 } 566 return (NULL);
553 current->pitch = bbitmap->BytesPerRow(); 567 }
554 current->pixels = (void *)bbitmap->Bits(); 568 current->pitch = bbitmap->BytesPerRow();
555 SDL_Win->SetBitmap(bbitmap); 569 current->pixels = (void *) bbitmap->Bits();
556 _this->UpdateRects = BE_NormalUpdate; 570 SDL_Win->SetBitmap(bbitmap);
557 } 571 _this->UpdateRects = BE_NormalUpdate;
558 572 }
559 /* Set the correct fullscreen mode */ 573
560 BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0); 574 /* Set the correct fullscreen mode */
561 575 BE_SetFullScreen(_this, current, flags & SDL_FULLSCREEN ? 1 : 0);
562 /* We're done */ 576
563 return(current); 577 /* We're done */
564 } 578 return (current);
579 }
565 580
566 /* Update the current mouse state and position */ 581 /* Update the current mouse state and position */
567 void BE_UpdateMouse(_THIS) 582 void BE_UpdateMouse(_THIS)
568 { 583 {
569 BPoint point; 584 BPoint point;
570 uint32 buttons; 585 uint32 buttons;
571 586
572 if ( SDL_Win->Lock() ) { 587 if (SDL_Win->Lock()) {
573 /* Get new input state, if still active */ 588 /* Get new input state, if still active */
574 if ( SDL_Win->IsActive() ) { 589 if (SDL_Win->IsActive()) {
575 (SDL_Win->View())->GetMouse(&point, &buttons, true); 590 (SDL_Win->View())->GetMouse(&point, &buttons, true);
576 } else { 591 } else {
577 point.x = -1; 592 point.x = -1;
578 point.y = -1; 593 point.y = -1;
579 } 594 }
580 SDL_Win->Unlock(); 595 SDL_Win->Unlock();
581 596
582 if ( (point.x >= 0) && (point.x < SDL_VideoSurface->w) && 597 if ((point.x >= 0) && (point.x < SDL_VideoSurface->w) &&
583 (point.y >= 0) && (point.y < SDL_VideoSurface->h) ) { 598 (point.y >= 0) && (point.y < SDL_VideoSurface->h)) {
584 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 599 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
585 SDL_PrivateMouseMotion(0, 0, 600 SDL_PrivateMouseMotion(0, 0,
586 (Sint16)point.x, (Sint16)point.y); 601 (Sint16) point.x, (Sint16) point.y);
587 } else { 602 } else {
588 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 603 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
589 } 604 }
590 } 605 }
591 } 606 }
592 607
593 /* We don't actually allow hardware surfaces other than the main one */ 608 /* We don't actually allow hardware surfaces other than the main one */
594 static int BE_AllocHWSurface(_THIS, SDL_Surface *surface) 609 static int BE_AllocHWSurface(_THIS, SDL_Surface * surface)
595 { 610 {
596 return(-1); 611 return (-1);
597 } 612 }
598 static void BE_FreeHWSurface(_THIS, SDL_Surface *surface) 613 static void BE_FreeHWSurface(_THIS, SDL_Surface * surface)
599 { 614 {
600 return; 615 return;
601 } 616 }
602 static int BE_LockHWSurface(_THIS, SDL_Surface *surface) 617 static int BE_LockHWSurface(_THIS, SDL_Surface * surface)
603 { 618 {
604 return(0); 619 return (0);
605 } 620 }
606 static void BE_UnlockHWSurface(_THIS, SDL_Surface *surface) 621 static void BE_UnlockHWSurface(_THIS, SDL_Surface * surface)
607 { 622 {
608 return; 623 return;
609 } 624 }
610 625
611 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) 626 static void BE_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
612 { 627 {
613 if ( SDL_Win->BeginDraw() ) { 628 if (SDL_Win->BeginDraw()) {
614 int i; 629 int i;
615 630
616 for ( i=0; i<numrects; ++i ) { 631 for (i = 0; i < numrects; ++i) {
617 BRect rect; 632 BRect rect;
618 633
619 rect.top = rects[i].y; 634 rect.top = rects[i].y;
620 rect.left = rects[i].x; 635 rect.left = rects[i].x;
621 rect.bottom = rect.top+rects[i].h-1; 636 rect.bottom = rect.top + rects[i].h - 1;
622 rect.right = rect.left+rects[i].w-1; 637 rect.right = rect.left + rects[i].w - 1;
623 SDL_Win->DrawAsync(rect); 638 SDL_Win->DrawAsync(rect);
624 } 639 }
625 SDL_Win->EndDraw(); 640 SDL_Win->EndDraw();
626 } 641 }
627 } 642 }
628 643
629 #if SDL_VIDEO_OPENGL 644 #if SDL_VIDEO_OPENGL
630 /* Passing a NULL path means load pointers from the application */ 645 /* Passing a NULL path means load pointers from the application */
631 int BE_GL_LoadLibrary(_THIS, const char *path) 646 int BE_GL_LoadLibrary(_THIS, const char *path)
632 { 647 {
633 if (path == NULL) { 648 if (path == NULL) {
634 if (_this->gl_config.dll_handle == NULL) { 649 if (_this->gl_config.dll_handle == NULL) {
635 image_info info; 650 image_info info;
636 int32 cookie = 0; 651 int32 cookie = 0;
637 while (get_next_image_info(0,&cookie,&info) == B_OK) { 652 while (get_next_image_info(0, &cookie, &info) == B_OK) {
638 void *location = NULL; 653 void *location = NULL;
639 if (get_image_symbol((image_id)cookie,"glBegin",B_SYMBOL_TYPE_ANY,&location) == B_OK) { 654 if (get_image_symbol
640 _this->gl_config.dll_handle = (void*)cookie; 655 ((image_id) cookie, "glBegin",
641 _this->gl_config.driver_loaded = 1; 656 B_SYMBOL_TYPE_ANY, &location) == B_OK) {
642 SDL_strlcpy(_this->gl_config.driver_path, "libGL.so", SDL_arraysize(_this->gl_config.driver_path)); 657 _this->gl_config.dll_handle = (void *) cookie;
643 } 658 _this->gl_config.driver_loaded = 1;
644 } 659 SDL_strlcpy(_this->gl_config.driver_path,
645 } 660 "libGL.so",
646 } else { 661 SDL_arraysize(_this->gl_config.
647 /* 662 driver_path));
648 FIXME None of BeOS libGL.so implementations have exported functions 663 }
649 to load BGLView, which should be reloaded from new lib. 664 }
650 So for now just "load" linked libGL.so :( 665 }
651 */ 666 } else {
652 if (_this->gl_config.dll_handle == NULL) { 667 /*
653 return BE_GL_LoadLibrary(_this, NULL); 668 FIXME None of BeOS libGL.so implementations have exported functions
654 } 669 to load BGLView, which should be reloaded from new lib.
655 670 So for now just "load" linked libGL.so :(
656 /* Unload old first */ 671 */
657 /*if (_this->gl_config.dll_handle != NULL) {*/ 672 if (_this->gl_config.dll_handle == NULL) {
658 /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */ 673 return BE_GL_LoadLibrary(_this, NULL);
659 /* image_info info; 674 }
660 if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) { 675
661 if (info.type != B_APP_IMAGE) { 676 /* Unload old first */
662 unload_add_on((image_id)_this->gl_config.dll_handle); 677 /*if (_this->gl_config.dll_handle != NULL) { */
663 } 678 /* Do not try to unload application itself (if LoadLibrary was called before with NULL ;) */
664 } 679 /* image_info info;
665 680 if (get_image_info((image_id)_this->gl_config.dll_handle, &info) == B_OK) {
666 } 681 if (info.type != B_APP_IMAGE) {
667 682 unload_add_on((image_id)_this->gl_config.dll_handle);
668 if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) { 683 }
669 _this->gl_config.driver_loaded = 1; 684 }
670 SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); 685
671 }*/ 686 }
672 } 687
673 688 if ((_this->gl_config.dll_handle = (void*)load_add_on(path)) != (void*)B_ERROR) {
674 if (_this->gl_config.dll_handle != NULL) { 689 _this->gl_config.driver_loaded = 1;
675 return 0; 690 SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
676 } else { 691 } */
677 _this->gl_config.dll_handle = NULL; 692 }
678 _this->gl_config.driver_loaded = 0; 693
679 *_this->gl_config.driver_path = '\0'; 694 if (_this->gl_config.dll_handle != NULL) {
680 return -1; 695 return 0;
681 } 696 } else {
682 } 697 _this->gl_config.dll_handle = NULL;
683 698 _this->gl_config.driver_loaded = 0;
684 void* BE_GL_GetProcAddress(_THIS, const char *proc) 699 *_this->gl_config.driver_path = '\0';
685 { 700 return -1;
686 if (_this->gl_config.dll_handle != NULL) { 701 }
687 void *location = NULL; 702 }
688 status_t err; 703
689 if ((err = get_image_symbol((image_id)_this->gl_config.dll_handle, proc, B_SYMBOL_TYPE_ANY, &location)) == B_OK) { 704 void *BE_GL_GetProcAddress(_THIS, const char *proc)
690 return location; 705 {
691 } else { 706 if (_this->gl_config.dll_handle != NULL) {
692 SDL_SetError("Couldn't find OpenGL symbol"); 707 void *location = NULL;
693 return NULL; 708 status_t err;
694 } 709 if ((err =
695 } else { 710 get_image_symbol((image_id) _this->gl_config.dll_handle,
696 SDL_SetError("OpenGL library not loaded"); 711 proc, B_SYMBOL_TYPE_ANY,
697 return NULL; 712 &location)) == B_OK) {
698 } 713 return location;
699 } 714 } else {
700 715 SDL_SetError("Couldn't find OpenGL symbol");
701 int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) 716 return NULL;
702 { 717 }
703 /* 718 } else {
704 FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values 719 SDL_SetError("OpenGL library not loaded");
705 */ 720 return NULL;
706 switch (attrib) 721 }
707 { 722 }
708 case SDL_GL_RED_SIZE: 723
709 glGetIntegerv(GL_RED_BITS, (GLint*)value); 724 int BE_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
710 break; 725 {
711 case SDL_GL_GREEN_SIZE: 726 /*
712 glGetIntegerv(GL_GREEN_BITS, (GLint*)value); 727 FIXME? Right now BE_GL_GetAttribute shouldn't be called between glBegin() and glEnd() - it doesn't use "cached" values
713 break; 728 */
714 case SDL_GL_BLUE_SIZE: 729 switch (attrib) {
715 glGetIntegerv(GL_BLUE_BITS, (GLint*)value); 730 case SDL_GL_RED_SIZE:
716 break; 731 glGetIntegerv(GL_RED_BITS, (GLint *) value);
717 case SDL_GL_ALPHA_SIZE: 732 break;
718 glGetIntegerv(GL_ALPHA_BITS, (GLint*)value); 733 case SDL_GL_GREEN_SIZE:
719 break; 734 glGetIntegerv(GL_GREEN_BITS, (GLint *) value);
720 case SDL_GL_DOUBLEBUFFER: 735 break;
721 glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean*)value); 736 case SDL_GL_BLUE_SIZE:
722 break; 737 glGetIntegerv(GL_BLUE_BITS, (GLint *) value);
723 case SDL_GL_BUFFER_SIZE: 738 break;
724 int v; 739 case SDL_GL_ALPHA_SIZE:
725 glGetIntegerv(GL_RED_BITS, (GLint*)&v); 740 glGetIntegerv(GL_ALPHA_BITS, (GLint *) value);
726 *value = v; 741 break;
727 glGetIntegerv(GL_GREEN_BITS, (GLint*)&v); 742 case SDL_GL_DOUBLEBUFFER:
728 *value += v; 743 glGetBooleanv(GL_DOUBLEBUFFER, (GLboolean *) value);
729 glGetIntegerv(GL_BLUE_BITS, (GLint*)&v); 744 break;
730 *value += v; 745 case SDL_GL_BUFFER_SIZE:
731 glGetIntegerv(GL_ALPHA_BITS, (GLint*)&v); 746 int v;
732 *value += v; 747 glGetIntegerv(GL_RED_BITS, (GLint *) & v);
733 break; 748 *value = v;
734 case SDL_GL_DEPTH_SIZE: 749 glGetIntegerv(GL_GREEN_BITS, (GLint *) & v);
735 glGetIntegerv(GL_DEPTH_BITS, (GLint*)value); /* Mesa creates 16 only? r5 always 32 */ 750 *value += v;
736 break; 751 glGetIntegerv(GL_BLUE_BITS, (GLint *) & v);
737 case SDL_GL_STENCIL_SIZE: 752 *value += v;
738 glGetIntegerv(GL_STENCIL_BITS, (GLint*)value); 753 glGetIntegerv(GL_ALPHA_BITS, (GLint *) & v);
739 break; 754 *value += v;
740 case SDL_GL_ACCUM_RED_SIZE: 755 break;
741 glGetIntegerv(GL_ACCUM_RED_BITS, (GLint*)value); 756 case SDL_GL_DEPTH_SIZE:
742 break; 757 glGetIntegerv(GL_DEPTH_BITS, (GLint *) value); /* Mesa creates 16 only? r5 always 32 */
743 case SDL_GL_ACCUM_GREEN_SIZE: 758 break;
744 glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint*)value); 759 case SDL_GL_STENCIL_SIZE:
745 break; 760 glGetIntegerv(GL_STENCIL_BITS, (GLint *) value);
746 case SDL_GL_ACCUM_BLUE_SIZE: 761 break;
747 glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint*)value); 762 case SDL_GL_ACCUM_RED_SIZE:
748 break; 763 glGetIntegerv(GL_ACCUM_RED_BITS, (GLint *) value);
749 case SDL_GL_ACCUM_ALPHA_SIZE: 764 break;
750 glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint*)value); 765 case SDL_GL_ACCUM_GREEN_SIZE:
751 break; 766 glGetIntegerv(GL_ACCUM_GREEN_BITS, (GLint *) value);
752 case SDL_GL_STEREO: 767 break;
753 case SDL_GL_MULTISAMPLEBUFFERS: 768 case SDL_GL_ACCUM_BLUE_SIZE:
754 case SDL_GL_MULTISAMPLESAMPLES: 769 glGetIntegerv(GL_ACCUM_BLUE_BITS, (GLint *) value);
755 default: 770 break;
756 *value=0; 771 case SDL_GL_ACCUM_ALPHA_SIZE:
757 return(-1); 772 glGetIntegerv(GL_ACCUM_ALPHA_BITS, (GLint *) value);
758 } 773 break;
759 return 0; 774 case SDL_GL_STEREO:
760 } 775 case SDL_GL_MULTISAMPLEBUFFERS:
761 776 case SDL_GL_MULTISAMPLESAMPLES:
762 int BE_GL_MakeCurrent(_THIS) 777 default:
763 { 778 *value = 0;
764 /* FIXME: should we glview->unlock and then glview->lock()? */ 779 return (-1);
765 return 0; 780 }
766 } 781 return 0;
767 782 }
768 void BE_GL_SwapBuffers(_THIS) 783
769 { 784 int BE_GL_MakeCurrent(_THIS)
770 SDL_Win->SwapBuffers(); 785 {
771 } 786 /* FIXME: should we glview->unlock and then glview->lock()? */
787 return 0;
788 }
789
790 void BE_GL_SwapBuffers(_THIS)
791 {
792 SDL_Win->SwapBuffers();
793 }
772 #endif 794 #endif
773 795
774 /* Is the system palette settable? */ 796 /* Is the system palette settable? */
775 int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 797 int BE_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
776 { 798 {
777 int i; 799 int i;
778 SDL_Palette *palette; 800 SDL_Palette *palette;
779 const color_map *cmap = BScreen().ColorMap(); 801 const color_map *cmap = BScreen().ColorMap();
780 802
781 /* Get the screen colormap */ 803 /* Get the screen colormap */
782 palette = _this->screen->format->palette; 804 palette = _this->screen->format->palette;
783 for ( i=0; i<256; ++i ) { 805 for (i = 0; i < 256; ++i) {
784 palette->colors[i].r = cmap->color_list[i].red; 806 palette->colors[i].r = cmap->color_list[i].red;
785 palette->colors[i].g = cmap->color_list[i].green; 807 palette->colors[i].g = cmap->color_list[i].green;
786 palette->colors[i].b = cmap->color_list[i].blue; 808 palette->colors[i].b = cmap->color_list[i].blue;
787 } 809 }
788 return(0); 810 return (0);
789 } 811 }
790 812
791 void BE_VideoQuit(_THIS) 813 void BE_VideoQuit(_THIS)
792 { 814 {
793 int i, j; 815 int i, j;
794 816
795 SDL_Win->Quit(); 817 SDL_Win->Quit();
796 SDL_Win = NULL; 818 SDL_Win = NULL;
797 819
798 if ( SDL_BlankCursor != NULL ) { 820 if (SDL_BlankCursor != NULL) {
799 BE_FreeWMCursor(_this, SDL_BlankCursor); 821 BE_FreeWMCursor(_this, SDL_BlankCursor);
800 SDL_BlankCursor = NULL; 822 SDL_BlankCursor = NULL;
801 } 823 }
802 for ( i=0; i<NUM_MODELISTS; ++i ) { 824 for (i = 0; i < NUM_MODELISTS; ++i) {
803 if ( SDL_modelist[i] ) { 825 if (SDL_modelist[i]) {
804 for ( j=0; SDL_modelist[i][j]; ++j ) { 826 for (j = 0; SDL_modelist[i][j]; ++j) {
805 SDL_free(SDL_modelist[i][j]); 827 SDL_free(SDL_modelist[i][j]);
806 } 828 }
807 SDL_free(SDL_modelist[i]); 829 SDL_free(SDL_modelist[i]);
808 SDL_modelist[i] = NULL; 830 SDL_modelist[i] = NULL;
809 } 831 }
810 } 832 }
811 /* Restore the original video mode */ 833 /* Restore the original video mode */
812 if ( _this->screen ) { 834 if (_this->screen) {
813 if ( (_this->screen->flags&SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 835 if ((_this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
814 BScreen bscreen; 836 BScreen bscreen;
815 bscreen.SetMode(&saved_mode); 837 bscreen.SetMode(&saved_mode);
816 } 838 }
817 _this->screen->pixels = NULL; 839 _this->screen->pixels = NULL;
818 } 840 }
819
820 #if SDL_VIDEO_OPENGL 841 #if SDL_VIDEO_OPENGL
821 if (_this->gl_config.dll_handle != NULL) 842 if (_this->gl_config.dll_handle != NULL)
822 unload_add_on((image_id)_this->gl_config.dll_handle); 843 unload_add_on((image_id) _this->gl_config.dll_handle);
823 #endif 844 #endif
824 845
825 SDL_QuitBeApp(); 846 SDL_QuitBeApp();
826 } 847 }
827 848
828 }; /* Extern C */ 849 }; /* Extern C */
850
851 /* vi: set ts=4 sw=4 expandtab: */