Skip to content

Latest commit

 

History

History
829 lines (737 loc) · 21.9 KB

SDL_sysvideo.cc

File metadata and controls

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