Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
762 lines (668 loc) · 22.8 KB

SDL_romvideo.c

File metadata and controls

762 lines (668 loc) · 22.8 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 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
Sep 8, 2005
Sep 8, 2005
24
25
26
27
28
29
#if defined(__APPLE__) && defined(__MACH__)
#include <Carbon/Carbon.h>
#if USE_QUICKTIME
#include <QuickTime/Movies.h>
#endif
#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)
Apr 26, 2001
Apr 26, 2001
30
31
#include <Carbon.h>
/* The fullscreen code requires the QuickTime framework, and the window
Apr 13, 2006
Apr 13, 2006
32
is still at the back on Mac OS X, which is where this code is needed.
Apr 26, 2001
Apr 26, 2001
33
34
*/
#if USE_QUICKTIME
Sep 8, 2005
Sep 8, 2005
35
#include <Movies.h>
Apr 26, 2001
Apr 26, 2001
36
37
#endif
#else
May 17, 2006
May 17, 2006
38
#include <Quickdraw.h>
Apr 26, 2001
Apr 26, 2001
39
40
41
42
43
44
45
46
47
#include <LowMem.h>
#include <Gestalt.h>
#include <Devices.h>
#include <DiskInit.h>
#include <QDOffscreen.h>
#endif
#include "SDL_video.h"
#include "SDL_syswm.h"
Feb 16, 2006
Feb 16, 2006
48
#include "../SDL_sysvideo.h"
Apr 26, 2001
Apr 26, 2001
49
#include "SDL_romvideo.h"
Feb 24, 2006
Feb 24, 2006
50
51
52
53
#include "../maccommon/SDL_macgl_c.h"
#include "../maccommon/SDL_macwm_c.h"
#include "../maccommon/SDL_macmouse_c.h"
#include "../maccommon/SDL_macevents_c.h"
Apr 26, 2001
Apr 26, 2001
54
55
/* Initialization/Query functions */
May 28, 2006
May 28, 2006
56
57
58
59
60
61
62
63
static int ROM_VideoInit (_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **ROM_ListModes (_THIS, SDL_PixelFormat * format,
Uint32 flags);
static SDL_Surface *ROM_SetVideoMode (_THIS, SDL_Surface * current, int width,
int height, int bpp, Uint32 flags);
static int ROM_SetColors (_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static void ROM_VideoQuit (_THIS);
Apr 26, 2001
Apr 26, 2001
64
65
/* Hardware surface functions */
May 28, 2006
May 28, 2006
66
67
68
69
static int ROM_AllocHWSurface (_THIS, SDL_Surface * surface);
static int ROM_LockHWSurface (_THIS, SDL_Surface * surface);
static void ROM_UnlockHWSurface (_THIS, SDL_Surface * surface);
static void ROM_FreeHWSurface (_THIS, SDL_Surface * surface);
Apr 26, 2001
Apr 26, 2001
70
May 28, 2006
May 28, 2006
71
#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
Apr 26, 2001
Apr 26, 2001
72
/* Saved state for the menu bar */
May 28, 2006
May 28, 2006
73
74
75
static RgnHandle gSaveGrayRgn = nil;
static short gSaveMenuBar = 0;
static Boolean gSaveCSVis = true;
Apr 26, 2001
Apr 26, 2001
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#if powerc
/* Mixed mode glue to activate the 68K emulator and twiddle a register */
#define ONEWORDSTUB(p1) \
{ 0x41FA, 0x0010, 0x209F, (p1), 0x41FA, \
0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 }
#define TWOWORDSTUB(p1,p2) \
{ 0x41FA, 0x0012, 0x209F, (p1), (p2), 0x41FA, \
0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 }
#define THREEWORDSTUB(p1,p2,p3) \
{ 0x41FA, 0x0014, 0x209F, (p1), (p2), (p3), 0x41FA, \
0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 }
/* ControlStrip inline glue for PowerPC */
May 28, 2006
May 28, 2006
92
93
static pascal Boolean
SBIsControlStripVisible (void)
Apr 26, 2001
Apr 26, 2001
94
{
May 28, 2006
May 28, 2006
95
96
97
98
99
100
101
static short procData[] = TWOWORDSTUB (0x7000, 0xAAF2);
ProcInfoType procInfo = kD0DispatchedPascalStackBased
| RESULT_SIZE (SIZE_CODE (sizeof (Boolean)))
| DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE (kFourByteCode);
return ((Boolean)
CallUniversalProc ((UniversalProcPtr) procData, procInfo, 0x00));
Apr 26, 2001
Apr 26, 2001
102
103
}
May 28, 2006
May 28, 2006
104
105
static pascal void
SBShowHideControlStrip (Boolean showIt)
Apr 26, 2001
Apr 26, 2001
106
{
May 28, 2006
May 28, 2006
107
108
109
110
111
static short procData[] = THREEWORDSTUB (0x303C, 0x0101, 0xAAF2);
ProcInfoType procInfo = kD0DispatchedPascalStackBased
| DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE (kFourByteCode)
| DISPATCHED_STACK_ROUTINE_PARAMETER (1,
SIZE_CODE (sizeof (Boolean)));
Apr 26, 2001
Apr 26, 2001
112
May 28, 2006
May 28, 2006
113
CallUniversalProc ((UniversalProcPtr) procData, procInfo, 0x01, showIt);
Apr 26, 2001
Apr 26, 2001
114
115
116
117
118
119
}
#endif /* powerc */
#endif /* !TARGET_API_MAC_CARBON */
/* Macintosh toolbox driver bootstrap functions */
May 28, 2006
May 28, 2006
120
121
static int
ROM_Available (void)
Apr 26, 2001
Apr 26, 2001
122
{
May 28, 2006
May 28, 2006
123
return (1);
Apr 26, 2001
Apr 26, 2001
124
125
}
May 28, 2006
May 28, 2006
126
127
static void
ROM_DeleteDevice (SDL_VideoDevice * device)
Apr 26, 2001
Apr 26, 2001
128
{
May 28, 2006
May 28, 2006
129
130
SDL_free (device->hidden);
SDL_free (device);
Apr 26, 2001
Apr 26, 2001
131
132
}
May 28, 2006
May 28, 2006
133
134
static SDL_VideoDevice *
ROM_CreateDevice (int devindex)
Apr 26, 2001
Apr 26, 2001
135
{
May 28, 2006
May 28, 2006
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
if (device) {
SDL_memset (device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
SDL_malloc ((sizeof *device->hidden));
}
if ((device == NULL) || (device->hidden == NULL)) {
SDL_OutOfMemory ();
if (device) {
SDL_free (device);
}
return (0);
}
SDL_memset (device->hidden, 0, (sizeof *device->hidden));
/* Set the function pointers */
device->VideoInit = ROM_VideoInit;
device->ListModes = ROM_ListModes;
device->SetVideoMode = ROM_SetVideoMode;
device->SetColors = ROM_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = ROM_VideoQuit;
device->AllocHWSurface = ROM_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = ROM_LockHWSurface;
device->UnlockHWSurface = ROM_UnlockHWSurface;
device->FlipHWSurface = NULL;
device->FreeHWSurface = ROM_FreeHWSurface;
Feb 16, 2006
Feb 16, 2006
170
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
device->GL_MakeCurrent = Mac_GL_MakeCurrent;
device->GL_SwapBuffers = Mac_GL_SwapBuffers;
device->GL_LoadLibrary = Mac_GL_LoadLibrary;
device->GL_GetProcAddress = Mac_GL_GetProcAddress;
#endif // Have OpenGL
device->SetCaption = Mac_SetCaption;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->GetWMInfo = NULL;
device->FreeWMCursor = Mac_FreeWMCursor;
device->CreateWMCursor = Mac_CreateWMCursor;
device->ShowWMCursor = Mac_ShowWMCursor;
device->WarpWMCursor = Mac_WarpWMCursor;
device->InitOSKeymap = Mac_InitOSKeymap;
device->PumpEvents = Mac_PumpEvents;
device->free = ROM_DeleteDevice;
return device;
Apr 26, 2001
Apr 26, 2001
191
192
193
}
VideoBootStrap TOOLBOX_bootstrap = {
May 28, 2006
May 28, 2006
194
195
"toolbox", "MacOS ROM Toolbox",
ROM_Available, ROM_CreateDevice
Apr 26, 2001
Apr 26, 2001
196
197
198
};
May 28, 2006
May 28, 2006
199
200
static int
ROM_VideoInit (_THIS, SDL_PixelFormat * vformat)
Apr 26, 2001
Apr 26, 2001
201
{
May 28, 2006
May 28, 2006
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
long info;
/* Check out some things about the system */
Gestalt (gestaltQuickdrawVersion, &info);
if (info == gestaltOriginalQD) {
SDL_SetError ("Color Quickdraw not available");
return (-1);
}
/* Start ROMintosh events */
Mac_InitEvents (this);
/* Get a handle to the main monitor */
SDL_Display = GetMainDevice ();
/* Determine the current screen size */
this->info.current_w = (**SDL_Display).gdRect.right;
this->info.current_h = (**SDL_Display).gdRect.bottom;
/* Determine pixel format */
vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize;
switch (vformat->BitsPerPixel) {
case 16: /* 5-5-5 RGB */
vformat->Rmask = 0x00007c00;
vformat->Gmask = 0x000003e0;
vformat->Bmask = 0x0000001f;
break;
default:
break;
}
/* Create our palette */
SDL_CTab = (CTabHandle) NewHandle (sizeof (ColorSpec) * 256 + 8);
if (SDL_CTab == nil) {
SDL_OutOfMemory ();
return (-1);
}
(**SDL_CTab).ctSeed = GetCTSeed ();
(**SDL_CTab).ctFlags = 0;
(**SDL_CTab).ctSize = 255;
CTabChanged (SDL_CTab);
SDL_CPal = NewPalette (256, SDL_CTab, pmExplicit + pmTolerant, 0);
/* Get a list of available fullscreen modes */
SDL_modelist = (SDL_Rect **) SDL_malloc ((1 + 1) * sizeof (SDL_Rect *));
if (SDL_modelist) {
SDL_modelist[0] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
if (SDL_modelist[0]) {
SDL_modelist[0]->x = 0;
SDL_modelist[0]->y = 0;
SDL_modelist[0]->w = (**SDL_Display).gdRect.right;
SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom;
}
SDL_modelist[1] = NULL;
}
/* Fill in some window manager capabilities */
this->info.wm_available = 1;
/* We're done! */
return (0);
Apr 26, 2001
Apr 26, 2001
263
264
}
May 28, 2006
May 28, 2006
265
266
static SDL_Rect **
ROM_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
267
{
May 28, 2006
May 28, 2006
268
269
270
271
272
273
274
275
276
if (this->screen->format->BitsPerPixel == format->BitsPerPixel) {
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
return (SDL_modelist);
} else {
return ((SDL_Rect **) - 1);
}
} else {
return ((SDL_Rect **) 0);
}
Apr 26, 2001
Apr 26, 2001
277
278
}
May 28, 2006
May 28, 2006
279
280
static void
ROM_HideMenuBar (_THIS)
Apr 26, 2001
Apr 26, 2001
281
{
May 28, 2006
May 28, 2006
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
354
355
356
357
358
359
360
#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
RgnHandle drawRgn = nil;
RgnHandle tempRgn = nil;
RgnHandle grayRgn = nil;
WindowPtr window = nil;
GDHandle gd = nil;
GrafPtr savePort;
long response;
short height;
EventRecord theEvent;
height = GetMBarHeight ();
if (height > 0) {
tempRgn = NewRgn ();
drawRgn = NewRgn ();
gSaveGrayRgn = NewRgn ();
if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
goto CLEANUP;
}
grayRgn = GetGrayRgn (); /* No need to check for this */
GetPort (&savePort);
/* Hide the control strip if it's present, and record its
previous position into the dirty region for redrawing.
This isn't necessary, but may help catch stray bits. */
CopyRgn (grayRgn, tempRgn);
if (!Gestalt (gestaltControlStripAttr, &response) &&
(response & (1L << gestaltControlStripExists))) {
gSaveCSVis = SBIsControlStripVisible ();
if (gSaveCSVis)
SBShowHideControlStrip (false);
}
DiffRgn (grayRgn, tempRgn, drawRgn);
/* Save the gray region once the control strip is hidden */
CopyRgn (grayRgn, gSaveGrayRgn);
/* Change the menu height in lowmem */
gSaveMenuBar = height;
LMSetMBarHeight (0);
/* Walk the monitor rectangles, and combine any pieces that
aren't in GrayRgn: menubar, round corners, fake floaters. */
for (gd = GetDeviceList (); gd; gd = GetNextDevice (gd)) {
if (!TestDeviceAttribute (gd, screenDevice))
continue;
if (!TestDeviceAttribute (gd, screenActive))
continue;
RectRgn (tempRgn, &(*gd)->gdRect); /* Get the whole screen */
DiffRgn (tempRgn, grayRgn, tempRgn); /* Subtract out GrayRgn */
UnionRgn (tempRgn, drawRgn, drawRgn); /* Combine all the bits */
}
/* Add the bits into the GrayRgn */
UnionRgn (drawRgn, grayRgn, grayRgn);
/* Modify the vis regions of exposed windows */
window = (FrontWindow ())? FrontWindow () : (WindowPtr) - 1L;
PaintBehind (window, drawRgn);
CalcVisBehind (window, drawRgn);
SetPort (savePort);
/* Yield time so that floaters can catch up */
EventAvail (0, &theEvent);
EventAvail (0, &theEvent);
EventAvail (0, &theEvent);
EventAvail (0, &theEvent);
}
CLEANUP:
if (tempRgn)
DisposeRgn (tempRgn);
if (drawRgn)
DisposeRgn (drawRgn);
Apr 26, 2001
Apr 26, 2001
361
362
#endif /* !TARGET_API_MAC_CARBON */
}
May 28, 2006
May 28, 2006
363
364
365
static void
ROM_ShowMenuBar (_THIS)
Apr 26, 2001
Apr 26, 2001
366
{
May 28, 2006
May 28, 2006
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */
RgnHandle drawRgn = nil;
RgnHandle menuRgn = nil;
RgnHandle tempRgn = nil;
RgnHandle grayRgn = nil;
WindowPtr window = nil;
GrafPtr wMgrPort;
GrafPtr savePort;
Rect menuRect;
long response;
short height;
EventRecord theEvent;
RGBColor saveRGB;
RGBColor blackRGB = { 0, 0, 0 };
height = GetMBarHeight ();
if ((height <= 0) && (gSaveMenuBar > 0)) {
drawRgn = NewRgn ();
menuRgn = NewRgn ();
tempRgn = NewRgn ();
if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
goto CLEANUP;
}
grayRgn = GetGrayRgn (); /* No need to check for this */
GetPort (&savePort);
GetWMgrPort (&wMgrPort);
/* Set the height properly */
LMSetMBarHeight (gSaveMenuBar);
/* Restore the old GrayRgn: rounded corners, etc, but not
the menubar -- subtract that out first! */
if (gSaveGrayRgn) {
menuRect = (*GetMainDevice ())->gdRect;
menuRect.bottom = menuRect.top + gSaveMenuBar;
RectRgn (menuRgn, &menuRect);
DiffRgn (grayRgn, gSaveGrayRgn, drawRgn); /* What do we inval? */
DiffRgn (drawRgn, menuRgn, drawRgn); /* Clip out the menu */
/* Now redraw the corners and other bits black */
SetPort (wMgrPort);
GetClip (tempRgn);
SetClip (drawRgn);
GetForeColor (&saveRGB);
RGBForeColor (&blackRGB);
PaintRgn (drawRgn);
RGBForeColor (&saveRGB);
SetClip (tempRgn);
SetPort (savePort);
UnionRgn (drawRgn, menuRgn, drawRgn); /* Put back the menu */
/* Now actually restore the GrayRgn */
CopyRgn (gSaveGrayRgn, grayRgn);
DisposeRgn (gSaveGrayRgn);
gSaveGrayRgn = nil;
}
/* Modify the vis regions of exposed windows and draw menubar */
window = (FrontWindow ())? FrontWindow () : (WindowPtr) - 1L;
PaintBehind (window, drawRgn);
CalcVisBehind (window, drawRgn);
DrawMenuBar ();
SetPort (savePort);
gSaveMenuBar = 0;
/* Now show the control strip if it's present */
if (!Gestalt (gestaltControlStripAttr, &response) &&
(response & (1L << gestaltControlStripExists))) {
if (gSaveCSVis && !SBIsControlStripVisible ())
SBShowHideControlStrip (true);
gSaveCSVis = true;
}
/* Yield time so that floaters can catch up */
EventAvail (0, &theEvent);
EventAvail (0, &theEvent);
EventAvail (0, &theEvent);
EventAvail (0, &theEvent);
}
CLEANUP:
if (drawRgn)
DisposeRgn (drawRgn);
if (menuRgn)
DisposeRgn (menuRgn);
if (tempRgn)
DisposeRgn (tempRgn);
Apr 26, 2001
Apr 26, 2001
460
461
462
463
#endif /* !TARGET_API_MAC_CARBON */
}
/* Various screen update functions available */
May 28, 2006
May 28, 2006
464
465
static void ROM_DirectUpdate (_THIS, int numrects, SDL_Rect * rects);
static void ROM_WindowUpdate (_THIS, int numrects, SDL_Rect * rects);
Apr 26, 2001
Apr 26, 2001
466
May 28, 2006
May 28, 2006
467
468
static void
ROM_UnsetVideoMode (_THIS, SDL_Surface * current)
Apr 26, 2001
Apr 26, 2001
469
{
May 28, 2006
May 28, 2006
470
471
472
473
474
475
476
477
478
479
480
481
482
/* Free the current window, if any */
if (SDL_Window != nil) {
GWorldPtr memworld;
/* Handle OpenGL support */
Mac_GL_Quit (this);
memworld = (GWorldPtr) GetWRefCon (SDL_Window);
if (memworld != nil) {
UnlockPixels (GetGWorldPixMap (memworld));
DisposeGWorld (memworld);
}
if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
Apr 26, 2001
Apr 26, 2001
483
#if USE_QUICKTIME
May 28, 2006
May 28, 2006
484
485
EndFullScreen (fullscreen_ctx, nil);
SDL_Window = nil;
Apr 26, 2001
Apr 26, 2001
486
#else
May 28, 2006
May 28, 2006
487
ROM_ShowMenuBar (this);
Apr 26, 2001
Apr 26, 2001
488
#endif
May 28, 2006
May 28, 2006
489
490
491
492
}
}
current->pixels = NULL;
current->flags &= ~(SDL_HWSURFACE | SDL_FULLSCREEN);
Apr 26, 2001
Apr 26, 2001
493
494
}
May 28, 2006
May 28, 2006
495
496
497
static SDL_Surface *
ROM_SetVideoMode (_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
Apr 26, 2001
Apr 26, 2001
498
{
May 28, 2006
May 28, 2006
499
Rect wrect, orect;
Apr 26, 2001
Apr 26, 2001
500
#if TARGET_API_MAC_CARBON
May 28, 2006
May 28, 2006
501
Rect tmprect;
Apr 26, 2001
Apr 26, 2001
502
503
#endif
May 28, 2006
May 28, 2006
504
505
/* Free any previous video mode */
ROM_UnsetVideoMode (this, current);
Apr 26, 2001
Apr 26, 2001
506
May 28, 2006
May 28, 2006
507
508
509
510
511
512
513
/* Create the ROM window and SDL video surface */
current->flags = 0; /* Clear flags */
current->w = width;
current->h = height;
SetRect (&wrect, 0, 0, width, height);
if (SDL_Window) {
/* If we recreate the window, don't move it around */
Apr 26, 2001
Apr 26, 2001
514
#if TARGET_API_MAC_CARBON
May 28, 2006
May 28, 2006
515
orect = *GetWindowPortBounds (SDL_Window, &tmprect);
Apr 26, 2001
Apr 26, 2001
516
#else
May 28, 2006
May 28, 2006
517
orect = SDL_Window->portRect;
Apr 26, 2001
Apr 26, 2001
518
#endif
May 28, 2006
May 28, 2006
519
520
521
522
523
524
525
OffsetRect (&wrect, orect.left, orect.top);
} else {
/* Center the window the first time we show it */
OffsetRect (&wrect,
(SDL_modelist[0]->w - width) / 2,
(SDL_modelist[0]->h - height) / 2);
}
Apr 26, 2001
Apr 26, 2001
526
Feb 21, 2006
Feb 21, 2006
527
#if defined(__MACOSX__) && !USE_QUICKTIME
May 28, 2006
May 28, 2006
528
529
/* Hum.. fullscreen mode is broken */
flags &= ~SDL_FULLSCREEN;
Apr 26, 2001
Apr 26, 2001
530
#endif
May 28, 2006
May 28, 2006
531
532
533
534
535
536
if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
/* Create the fullscreen window and use screen bits */
current->flags |= SDL_HWSURFACE | SDL_FULLSCREEN;
if (SDL_Window) {
DisposeWindow (SDL_Window);
}
Apr 26, 2001
Apr 26, 2001
537
#if USE_QUICKTIME
May 28, 2006
May 28, 2006
538
BeginFullScreen (&fullscreen_ctx, nil, 0, 0, &SDL_Window, nil, 0);
Apr 26, 2001
Apr 26, 2001
539
#else
May 28, 2006
May 28, 2006
540
541
542
SDL_Window = NewCWindow (nil, &wrect, "\p", true, plainDBox,
(WindowPtr) - 1, false, 0);
ROM_HideMenuBar (this);
Apr 26, 2001
Apr 26, 2001
543
#endif
May 28, 2006
May 28, 2006
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
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
current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF;
current->pixels = (**(**SDL_Display).gdPMap).baseAddr;
this->UpdateRects = ROM_DirectUpdate;
} else {
GWorldPtr memworld;
PixMapHandle pixmap;
int style;
style = noGrowDocProc;
if (flags & SDL_NOFRAME) {
style = plainDBox;
current->flags |= SDL_NOFRAME;
} else if (flags & SDL_RESIZABLE) {
style = zoomDocProc;
current->flags |= SDL_RESIZABLE;
}
if (SDL_Window && (style == current_style)) {
/* Resize existing window, if necessary */
if (((orect.right - orect.left) != width) ||
((orect.bottom - orect.top) != height)) {
SizeWindow (SDL_Window, width, height, false);
}
} else {
/* Recreate the window in the new style */
if (SDL_Window) {
DisposeWindow (SDL_Window);
}
SDL_Window = NewCWindow (nil, &wrect, "\p", true,
style, (WindowPtr) - 1, true, 0);
/* Set the window title, if any */
{
char *title;
SDL_WM_GetCaption (&title, NULL);
if (title) {
Mac_SetCaption (this, title, NULL);
}
}
}
current_style = style;
SetPalette (SDL_Window, SDL_CPal, false);
ActivatePalette (SDL_Window);
if (NewGWorld (&memworld, 0,
Apr 26, 2001
Apr 26, 2001
587
#if TARGET_API_MAC_CARBON
May 28, 2006
May 28, 2006
588
GetWindowPortBounds (SDL_Window, &tmprect),
Apr 26, 2001
Apr 26, 2001
589
#else
May 28, 2006
May 28, 2006
590
&SDL_Window->portRect,
Apr 26, 2001
Apr 26, 2001
591
#endif
May 28, 2006
May 28, 2006
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
SDL_CTab, nil, 0) != noErr) {
SDL_SetError ("NewGWorld() failed");
return (NULL);
}
SetWRefCon (SDL_Window, (long) memworld);
pixmap = GetGWorldPixMap (memworld);
LockPixels (pixmap);
current->pitch = (**pixmap).rowBytes & 0x3FFF;
current->pixels = GetPixBaseAddr (pixmap);
this->UpdateRects = ROM_WindowUpdate;
}
SetPortWindowPort (SDL_Window);
SelectWindow (SDL_Window);
/* Handle OpenGL support */
if (flags & SDL_INTERNALOPENGL) {
if (Mac_GL_Init (this) == 0) {
current->flags |= SDL_INTERNALOPENGL;
} else {
current = NULL;
}
}
if ((flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN))
current->flags |= SDL_HWPALETTE;
/* We're live! */
return (current);
Apr 26, 2001
Apr 26, 2001
620
621
622
}
/* We don't actually allow hardware surfaces other than the main one */
May 28, 2006
May 28, 2006
623
624
static int
ROM_AllocHWSurface (_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
625
{
May 28, 2006
May 28, 2006
626
return (-1);
Apr 26, 2001
Apr 26, 2001
627
}
May 28, 2006
May 28, 2006
628
629
static void
ROM_FreeHWSurface (_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
630
{
May 28, 2006
May 28, 2006
631
return;
Apr 26, 2001
Apr 26, 2001
632
}
May 28, 2006
May 28, 2006
633
634
static int
ROM_LockHWSurface (_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
635
{
May 28, 2006
May 28, 2006
636
return (0);
Apr 26, 2001
Apr 26, 2001
637
}
May 28, 2006
May 28, 2006
638
639
static void
ROM_UnlockHWSurface (_THIS, SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
640
{
May 28, 2006
May 28, 2006
641
return;
Apr 26, 2001
Apr 26, 2001
642
643
}
May 28, 2006
May 28, 2006
644
645
static void
ROM_DirectUpdate (_THIS, int numrects, SDL_Rect * rects)
Apr 26, 2001
Apr 26, 2001
646
{
May 28, 2006
May 28, 2006
647
648
/* The application is already updating the visible video memory */
return;
Apr 26, 2001
Apr 26, 2001
649
650
}
May 28, 2006
May 28, 2006
651
652
static void
ROM_WindowUpdate (_THIS, int numrects, SDL_Rect * rects)
Apr 26, 2001
Apr 26, 2001
653
{
May 28, 2006
May 28, 2006
654
655
656
657
658
659
660
661
662
663
664
665
666
GWorldPtr memworld;
GrafPtr saveport;
CGrafPtr thePort;
const BitMap *memBits;
const BitMap *winBits;
int i;
Rect update;
/* Copy from the offscreen GWorld to the window port */
GetPort (&saveport);
SetPortWindowPort (SDL_Window);
thePort = GetWindowPort (SDL_Window);
memworld = (GWorldPtr) GetWRefCon (SDL_Window);
May 17, 2006
May 17, 2006
667
#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
May 28, 2006
May 28, 2006
668
memBits = GetPortBitMapForCopyBits ((CGrafPtr) memworld);
Apr 26, 2001
Apr 26, 2001
669
#else
May 28, 2006
May 28, 2006
670
memBits = &((GrafPtr) memworld)->portBits;
Apr 26, 2001
Apr 26, 2001
671
#endif
May 17, 2006
May 17, 2006
672
#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
May 28, 2006
May 28, 2006
673
winBits = GetPortBitMapForCopyBits (thePort);
Apr 26, 2001
Apr 26, 2001
674
#else
May 28, 2006
May 28, 2006
675
winBits = &SDL_Window->portBits;
Apr 26, 2001
Apr 26, 2001
676
#endif
May 28, 2006
May 28, 2006
677
678
679
680
681
682
683
for (i = 0; i < numrects; ++i) {
update.left = rects[i].x;
update.right = rects[i].x + rects[i].w;
update.top = rects[i].y;
update.bottom = rects[i].y + rects[i].h;
CopyBits (memBits, winBits, &update, &update, srcCopy, nil);
}
Apr 26, 2001
Apr 26, 2001
684
#if TARGET_API_MAC_CARBON
May 28, 2006
May 28, 2006
685
686
687
if (QDIsPortBuffered (thePort)) {
QDFlushPortBuffer (thePort, NULL);
}
Apr 26, 2001
Apr 26, 2001
688
#endif
May 28, 2006
May 28, 2006
689
SetPort (saveport);
Apr 26, 2001
Apr 26, 2001
690
691
}
May 28, 2006
May 28, 2006
692
693
static int
ROM_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
Apr 26, 2001
Apr 26, 2001
694
{
May 28, 2006
May 28, 2006
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
CTabHandle cTab;
int i;
/* Get the colortable from the either the display or window */
if ((this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
cTab = (**(**SDL_Display).gdPMap).pmTable;
} else {
cTab = SDL_CTab;
}
/* Verify the range of colors */
if ((firstcolor + ncolors) > ((**cTab).ctSize + 1)) {
return (0);
}
/* Set the screen palette and update the display */
for (i = 0; i < ncolors; ++i) {
int j = firstcolor + i;
(**cTab).ctTable[j].value = j;
(**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r;
(**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g;
(**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b;
}
// if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN )
{
GDevice **odisplay;
odisplay = GetGDevice ();
SetGDevice (SDL_Display);
SetEntries (0, (**cTab).ctSize, (ColorSpec *) & (**cTab).ctTable);
SetGDevice (odisplay);
}
return (1);
Apr 26, 2001
Apr 26, 2001
727
728
}
May 28, 2006
May 28, 2006
729
730
void
ROM_VideoQuit (_THIS)
Apr 26, 2001
Apr 26, 2001
731
{
May 28, 2006
May 28, 2006
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
int i;
/* Free current video mode */
ROM_UnsetVideoMode (this, this->screen);
if (SDL_Window) {
DisposeWindow (SDL_Window);
SDL_Window = nil;
}
/* Free palette and restore original one */
if (SDL_CTab != nil) {
DisposeHandle ((Handle) SDL_CTab);
SDL_CTab = nil;
}
if (SDL_CPal != nil) {
DisposePalette (SDL_CPal);
SDL_CPal = nil;
}
RestoreDeviceClut (GetMainDevice ());
/* Free list of video modes */
if (SDL_modelist != NULL) {
for (i = 0; SDL_modelist[i]; ++i) {
SDL_free (SDL_modelist[i]);
}
SDL_free (SDL_modelist);
SDL_modelist = NULL;
}
Apr 26, 2001
Apr 26, 2001
760
761
}
May 28, 2006
May 28, 2006
762
/* vi: set ts=4 sw=4 expandtab: */