Mercurial > sdl-ios-xcode
annotate src/video/macrom/SDL_romvideo.c @ 1400:5abff0870de2
Date: Mon, 20 Feb 2006 19:54:51 -0500
From: Brian Barnes
Subject: [SDL] Fix for FSAA OS X bug -- Please fix in CVS Code
I stopped complaining and went in an fixed the bug myself :) SDL
always dies if you try to use FSAA on Mac OS X, the problem is in the
file:
SDL_QuartzGL.m
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 21 Feb 2006 02:42:05 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1133
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
47
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
23 #if defined(__APPLE__) && defined(__MACH__) |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
24 #include <Carbon/Carbon.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
25 #if USE_QUICKTIME |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
26 #include <QuickTime/Movies.h> |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
27 #endif |
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
28 #elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335) |
0 | 29 #include <Carbon.h> |
30 /* The fullscreen code requires the QuickTime framework, and the window | |
31 is still at the back on MacOS X, which is where this code is needed. | |
32 */ | |
33 #if USE_QUICKTIME | |
1133
609c060fd2a2
The MacOSX Carbon/Cocoa/X11 all in one library patch. Relevant emails:
Ryan C. Gordon <icculus@icculus.org>
parents:
1032
diff
changeset
|
34 #include <Movies.h> |
0 | 35 #endif |
36 #else | |
37 #include <LowMem.h> | |
38 #include <Gestalt.h> | |
39 #include <Devices.h> | |
40 #include <DiskInit.h> | |
41 #include <QDOffscreen.h> | |
42 #endif | |
43 | |
44 #include "SDL_video.h" | |
45 #include "SDL_syswm.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
46 #include "../SDL_sysvideo.h" |
0 | 47 #include "SDL_romvideo.h" |
48 #include "SDL_macgl_c.h" | |
49 #include "SDL_macwm_c.h" | |
50 #include "SDL_macmouse_c.h" | |
51 #include "SDL_macevents_c.h" | |
52 | |
53 /* Initialization/Query functions */ | |
54 static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
55 static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
56 static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
57 static int ROM_SetColors(_THIS, int firstcolor, int ncolors, | |
58 SDL_Color *colors); | |
59 static void ROM_VideoQuit(_THIS); | |
60 | |
61 /* Hardware surface functions */ | |
62 static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface); | |
63 static int ROM_LockHWSurface(_THIS, SDL_Surface *surface); | |
64 static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
65 static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface); | |
66 | |
67 #if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */ | |
68 /* Saved state for the menu bar */ | |
69 static RgnHandle gSaveGrayRgn = nil; | |
70 static short gSaveMenuBar = 0; | |
71 static Boolean gSaveCSVis = true; | |
72 | |
73 #if powerc | |
74 /* Mixed mode glue to activate the 68K emulator and twiddle a register */ | |
75 #define ONEWORDSTUB(p1) \ | |
76 { 0x41FA, 0x0010, 0x209F, (p1), 0x41FA, \ | |
77 0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 } | |
78 | |
79 #define TWOWORDSTUB(p1,p2) \ | |
80 { 0x41FA, 0x0012, 0x209F, (p1), (p2), 0x41FA, \ | |
81 0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 } | |
82 | |
83 #define THREEWORDSTUB(p1,p2,p3) \ | |
84 { 0x41FA, 0x0014, 0x209F, (p1), (p2), (p3), 0x41FA, \ | |
85 0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 } | |
86 | |
87 /* ControlStrip inline glue for PowerPC */ | |
88 static pascal Boolean SBIsControlStripVisible(void) | |
89 { | |
90 static short procData[] = TWOWORDSTUB(0x7000, 0xAAF2); | |
91 ProcInfoType procInfo = kD0DispatchedPascalStackBased | |
92 | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) | |
93 | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode); | |
94 | |
95 return((Boolean) CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x00)); | |
96 } | |
97 | |
98 static pascal void SBShowHideControlStrip(Boolean showIt) | |
99 { | |
100 static short procData[] = THREEWORDSTUB(0x303C, 0x0101, 0xAAF2); | |
101 ProcInfoType procInfo = kD0DispatchedPascalStackBased | |
102 | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode) | |
103 | DISPATCHED_STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Boolean))); | |
104 | |
105 CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x01, showIt); | |
106 } | |
107 #endif /* powerc */ | |
108 #endif /* !TARGET_API_MAC_CARBON */ | |
109 | |
110 /* Macintosh toolbox driver bootstrap functions */ | |
111 | |
112 static int ROM_Available(void) | |
113 { | |
114 return(1); | |
115 } | |
116 | |
117 static void ROM_DeleteDevice(SDL_VideoDevice *device) | |
118 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
119 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
120 SDL_free(device); |
0 | 121 } |
122 | |
123 static SDL_VideoDevice *ROM_CreateDevice(int devindex) | |
124 { | |
125 SDL_VideoDevice *device; | |
126 | |
127 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
128 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 129 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
130 SDL_memset(device, 0, (sizeof *device)); |
0 | 131 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
132 SDL_malloc((sizeof *device->hidden)); |
0 | 133 } |
134 if ( (device == NULL) || (device->hidden == NULL) ) { | |
135 SDL_OutOfMemory(); | |
136 if ( device ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
137 SDL_free(device); |
0 | 138 } |
139 return(0); | |
140 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
141 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
0 | 142 |
143 /* Set the function pointers */ | |
144 device->VideoInit = ROM_VideoInit; | |
145 device->ListModes = ROM_ListModes; | |
146 device->SetVideoMode = ROM_SetVideoMode; | |
147 device->SetColors = ROM_SetColors; | |
148 device->UpdateRects = NULL; | |
149 device->VideoQuit = ROM_VideoQuit; | |
150 device->AllocHWSurface = ROM_AllocHWSurface; | |
151 device->CheckHWBlit = NULL; | |
152 device->FillHWRect = NULL; | |
153 device->SetHWColorKey = NULL; | |
154 device->SetHWAlpha = NULL; | |
155 device->LockHWSurface = ROM_LockHWSurface; | |
156 device->UnlockHWSurface = ROM_UnlockHWSurface; | |
157 device->FlipHWSurface = NULL; | |
158 device->FreeHWSurface = ROM_FreeHWSurface; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
159 #if SDL_VIDEO_OPENGL |
0 | 160 device->GL_MakeCurrent = Mac_GL_MakeCurrent; |
161 device->GL_SwapBuffers = Mac_GL_SwapBuffers; | |
774
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
162 device->GL_LoadLibrary = Mac_GL_LoadLibrary; |
0c3e00cc9580
Date: Mon, 5 Jan 2004 00:09:36 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
163 device->GL_GetProcAddress = Mac_GL_GetProcAddress; |
916
46916168361d
Date: Sun, 25 Jul 2004 23:10:03 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
774
diff
changeset
|
164 #endif // Have OpenGL |
0 | 165 device->SetCaption = Mac_SetCaption; |
166 device->SetIcon = NULL; | |
167 device->IconifyWindow = NULL; | |
168 device->GrabInput = NULL; | |
169 device->GetWMInfo = NULL; | |
170 device->FreeWMCursor = Mac_FreeWMCursor; | |
171 device->CreateWMCursor = Mac_CreateWMCursor; | |
172 device->ShowWMCursor = Mac_ShowWMCursor; | |
173 device->WarpWMCursor = Mac_WarpWMCursor; | |
174 device->InitOSKeymap = Mac_InitOSKeymap; | |
175 device->PumpEvents = Mac_PumpEvents; | |
176 | |
177 device->free = ROM_DeleteDevice; | |
178 | |
179 return device; | |
180 } | |
181 | |
182 VideoBootStrap TOOLBOX_bootstrap = { | |
183 "toolbox", "MacOS ROM Toolbox", | |
184 ROM_Available, ROM_CreateDevice | |
185 }; | |
186 | |
187 | |
188 static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
189 { | |
190 long info; | |
191 | |
192 /* Check out some things about the system */ | |
193 Gestalt(gestaltQuickdrawVersion, &info); | |
194 if ( info == gestaltOriginalQD ) { | |
195 SDL_SetError("Color Quickdraw not available"); | |
196 return(-1); | |
197 } | |
198 | |
199 /* Start ROMintosh events */ | |
200 Mac_InitEvents(this); | |
201 | |
202 /* Get a handle to the main monitor */ | |
203 SDL_Display = GetMainDevice(); | |
204 | |
205 /* Determine pixel format */ | |
206 vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize; | |
207 switch (vformat->BitsPerPixel) { | |
208 case 16: /* 5-5-5 RGB */ | |
209 vformat->Rmask = 0x00007c00; | |
210 vformat->Gmask = 0x000003e0; | |
211 vformat->Bmask = 0x0000001f; | |
212 break; | |
213 default: | |
214 break; | |
215 } | |
216 | |
217 /* Create our palette */ | |
218 SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8); | |
219 if ( SDL_CTab == nil ) { | |
220 SDL_OutOfMemory(); | |
221 return(-1); | |
222 } | |
223 (**SDL_CTab).ctSeed = GetCTSeed(); | |
224 (**SDL_CTab).ctFlags = 0; | |
225 (**SDL_CTab).ctSize = 255; | |
226 CTabChanged(SDL_CTab); | |
227 SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0); | |
228 | |
229 /* Get a list of available fullscreen modes */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
230 SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *)); |
0 | 231 if ( SDL_modelist ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
232 SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
0 | 233 if ( SDL_modelist[0] ) { |
234 SDL_modelist[0]->x = 0; | |
235 SDL_modelist[0]->y = 0; | |
236 SDL_modelist[0]->w = (**SDL_Display).gdRect.right; | |
237 SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom; | |
238 } | |
239 SDL_modelist[1] = NULL; | |
240 } | |
241 | |
242 /* Fill in some window manager capabilities */ | |
243 this->info.wm_available = 1; | |
244 | |
245 /* We're done! */ | |
246 return(0); | |
247 } | |
248 | |
249 static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
250 { | |
251 if ( this->screen->format->BitsPerPixel == format->BitsPerPixel ) { | |
252 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
253 return(SDL_modelist); | |
254 } else { | |
255 return((SDL_Rect **)-1); | |
256 } | |
257 } else { | |
258 return((SDL_Rect **)0); | |
259 } | |
260 } | |
261 | |
262 static void ROM_HideMenuBar(_THIS) | |
263 { | |
264 #if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */ | |
265 RgnHandle drawRgn = nil; | |
266 RgnHandle tempRgn = nil; | |
267 RgnHandle grayRgn = nil; | |
268 WindowPtr window = nil; | |
269 GDHandle gd = nil; | |
270 GrafPtr savePort; | |
271 long response; | |
272 short height; | |
273 EventRecord theEvent; | |
274 | |
275 height = GetMBarHeight(); | |
276 | |
277 if ( height > 0 ) { | |
278 tempRgn = NewRgn(); | |
279 drawRgn = NewRgn(); | |
280 gSaveGrayRgn = NewRgn(); | |
281 if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) { | |
282 goto CLEANUP; | |
283 } | |
284 grayRgn = GetGrayRgn(); /* No need to check for this */ | |
285 | |
286 GetPort(&savePort); | |
287 | |
288 /* Hide the control strip if it's present, and record its | |
289 previous position into the dirty region for redrawing. | |
290 This isn't necessary, but may help catch stray bits. */ | |
291 CopyRgn(grayRgn, tempRgn); | |
292 if (!Gestalt(gestaltControlStripAttr, &response) && | |
293 (response & (1L << gestaltControlStripExists))) { | |
294 gSaveCSVis = SBIsControlStripVisible(); | |
295 if (gSaveCSVis) | |
296 SBShowHideControlStrip(false); | |
297 } | |
298 DiffRgn(grayRgn, tempRgn, drawRgn); | |
299 | |
300 /* Save the gray region once the control strip is hidden*/ | |
301 CopyRgn(grayRgn, gSaveGrayRgn); | |
302 | |
303 /* Change the menu height in lowmem */ | |
304 gSaveMenuBar = height; | |
305 LMSetMBarHeight(0); | |
306 | |
307 /* Walk the monitor rectangles, and combine any pieces that | |
308 aren't in GrayRgn: menubar, round corners, fake floaters. */ | |
309 for(gd = GetDeviceList(); gd; gd = GetNextDevice(gd)) | |
310 { | |
311 if (!TestDeviceAttribute(gd, screenDevice)) continue; | |
312 if (!TestDeviceAttribute(gd, screenActive)) continue; | |
313 | |
314 RectRgn(tempRgn, &(*gd)->gdRect); /* Get the whole screen */ | |
315 DiffRgn(tempRgn, grayRgn, tempRgn); /* Subtract out GrayRgn */ | |
316 UnionRgn(tempRgn, drawRgn, drawRgn);/* Combine all the bits */ | |
317 } | |
318 | |
319 /* Add the bits into the GrayRgn */ | |
320 UnionRgn(drawRgn, grayRgn, grayRgn); | |
321 | |
322 /* Modify the vis regions of exposed windows */ | |
323 window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L; | |
324 PaintBehind(window, drawRgn); | |
325 CalcVisBehind(window, drawRgn); | |
326 | |
327 SetPort(savePort); | |
328 | |
329 /* Yield time so that floaters can catch up */ | |
330 EventAvail(0, &theEvent); | |
331 EventAvail(0, &theEvent); | |
332 EventAvail(0, &theEvent); | |
333 EventAvail(0, &theEvent); | |
334 } | |
335 | |
336 CLEANUP: | |
337 | |
338 if (tempRgn) DisposeRgn(tempRgn); | |
339 if (drawRgn) DisposeRgn(drawRgn); | |
340 #endif /* !TARGET_API_MAC_CARBON */ | |
341 } | |
342 | |
343 static void ROM_ShowMenuBar(_THIS) | |
344 { | |
345 #if !TARGET_API_MAC_CARBON /* This seems not to be available? -sts Aug 2000 */ | |
346 RgnHandle drawRgn = nil; | |
347 RgnHandle menuRgn = nil; | |
348 RgnHandle tempRgn = nil; | |
349 RgnHandle grayRgn = nil; | |
350 WindowPtr window = nil; | |
351 GrafPtr wMgrPort; | |
352 GrafPtr savePort; | |
353 Rect menuRect; | |
354 long response; | |
355 short height; | |
356 EventRecord theEvent; | |
357 RGBColor saveRGB; | |
358 RGBColor blackRGB = { 0, 0, 0 }; | |
359 | |
360 height = GetMBarHeight(); | |
361 | |
362 if ((height <= 0) && (gSaveMenuBar > 0)) { | |
363 drawRgn = NewRgn(); | |
364 menuRgn = NewRgn(); | |
365 tempRgn = NewRgn(); | |
366 if ( ! tempRgn || ! drawRgn || ! gSaveGrayRgn ) { | |
367 goto CLEANUP; | |
368 } | |
369 grayRgn = GetGrayRgn(); /* No need to check for this */ | |
370 | |
371 GetPort(&savePort); | |
372 GetWMgrPort(&wMgrPort); | |
373 | |
374 /* Set the height properly */ | |
375 LMSetMBarHeight(gSaveMenuBar); | |
376 | |
377 /* Restore the old GrayRgn: rounded corners, etc, but not | |
378 the menubar -- subtract that out first! */ | |
379 if (gSaveGrayRgn) | |
380 { | |
381 menuRect = (*GetMainDevice())->gdRect; | |
382 menuRect.bottom = menuRect.top + gSaveMenuBar; | |
383 RectRgn(menuRgn, &menuRect); | |
384 | |
385 DiffRgn(grayRgn, gSaveGrayRgn, drawRgn); /* What do we inval? */ | |
386 DiffRgn(drawRgn, menuRgn, drawRgn); /* Clip out the menu */ | |
387 | |
388 /* Now redraw the corners and other bits black */ | |
389 SetPort(wMgrPort); | |
390 GetClip(tempRgn); | |
391 SetClip(drawRgn); | |
392 GetForeColor(&saveRGB); | |
393 RGBForeColor(&blackRGB); | |
394 PaintRgn(drawRgn); | |
395 RGBForeColor(&saveRGB); | |
396 SetClip(tempRgn); | |
397 SetPort(savePort); | |
398 | |
399 UnionRgn(drawRgn, menuRgn, drawRgn); /* Put back the menu */ | |
400 | |
401 /* Now actually restore the GrayRgn */ | |
402 CopyRgn(gSaveGrayRgn, grayRgn); | |
403 DisposeRgn(gSaveGrayRgn); | |
404 gSaveGrayRgn = nil; | |
405 } | |
406 | |
407 /* Modify the vis regions of exposed windows and draw menubar */ | |
408 window = (FrontWindow()) ? FrontWindow() : (WindowPtr) -1L; | |
409 PaintBehind(window, drawRgn); | |
410 CalcVisBehind(window, drawRgn); | |
411 DrawMenuBar(); | |
412 | |
413 SetPort(savePort); | |
414 gSaveMenuBar = 0; | |
415 | |
416 /* Now show the control strip if it's present */ | |
417 if (!Gestalt(gestaltControlStripAttr, &response) && | |
418 (response & (1L << gestaltControlStripExists))) | |
419 { | |
420 if (gSaveCSVis && !SBIsControlStripVisible()) | |
421 SBShowHideControlStrip(true); | |
422 gSaveCSVis = true; | |
423 } | |
424 | |
425 /* Yield time so that floaters can catch up */ | |
426 EventAvail(0, &theEvent); | |
427 EventAvail(0, &theEvent); | |
428 EventAvail(0, &theEvent); | |
429 EventAvail(0, &theEvent); | |
430 } | |
431 | |
432 CLEANUP: | |
433 | |
434 if (drawRgn) DisposeRgn(drawRgn); | |
435 if (menuRgn) DisposeRgn(menuRgn); | |
436 if (tempRgn) DisposeRgn(tempRgn); | |
437 #endif /* !TARGET_API_MAC_CARBON */ | |
438 } | |
439 | |
440 /* Various screen update functions available */ | |
441 static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
442 static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects); | |
443 | |
444 static void ROM_UnsetVideoMode(_THIS, SDL_Surface *current) | |
445 { | |
446 /* Free the current window, if any */ | |
447 if ( SDL_Window != nil ) { | |
448 GWorldPtr memworld; | |
449 | |
450 /* Handle OpenGL support */ | |
451 Mac_GL_Quit(this); | |
452 | |
453 memworld = (GWorldPtr)GetWRefCon(SDL_Window); | |
454 if ( memworld != nil ) { | |
455 UnlockPixels(GetGWorldPixMap(memworld)); | |
456 DisposeGWorld(memworld); | |
457 } | |
458 if ( (current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
459 #if USE_QUICKTIME | |
460 EndFullScreen(fullscreen_ctx, nil); | |
461 SDL_Window = nil; | |
462 #else | |
463 ROM_ShowMenuBar(this); | |
464 #endif | |
465 } | |
466 } | |
467 current->pixels = NULL; | |
468 current->flags &= ~(SDL_HWSURFACE|SDL_FULLSCREEN); | |
469 } | |
470 | |
471 static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface *current, | |
472 int width, int height, int bpp, Uint32 flags) | |
473 { | |
474 Rect wrect, orect; | |
475 #if TARGET_API_MAC_CARBON | |
476 Rect tmprect; | |
477 #endif | |
478 | |
479 /* Free any previous video mode */ | |
480 ROM_UnsetVideoMode(this, current); | |
481 | |
482 /* Create the ROM window and SDL video surface */ | |
483 current->flags = 0; /* Clear flags */ | |
484 current->w = width; | |
485 current->h = height; | |
486 SetRect(&wrect, 0, 0, width, height); | |
487 if ( SDL_Window ) { | |
488 /* If we recreate the window, don't move it around */ | |
489 #if TARGET_API_MAC_CARBON | |
490 orect = *GetWindowPortBounds(SDL_Window, &tmprect); | |
491 #else | |
492 orect = SDL_Window->portRect; | |
493 #endif | |
494 OffsetRect(&wrect, orect.left, orect.top); | |
495 } else { | |
496 /* Center the window the first time we show it */ | |
497 OffsetRect(&wrect, | |
498 (SDL_modelist[0]->w-width)/2, (SDL_modelist[0]->h-height)/2); | |
499 } | |
500 | |
501 #if MACOSX && !USE_QUICKTIME | |
502 /* Hum.. fullscreen mode is broken */ | |
503 flags &= ~SDL_FULLSCREEN; | |
504 #endif | |
505 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
506 /* Create the fullscreen window and use screen bits */ | |
507 current->flags |= SDL_HWSURFACE|SDL_FULLSCREEN; | |
508 if ( SDL_Window ) { | |
509 DisposeWindow(SDL_Window); | |
510 } | |
511 #if USE_QUICKTIME | |
512 BeginFullScreen(&fullscreen_ctx, nil, 0,0, &SDL_Window, nil, 0); | |
513 #else | |
514 SDL_Window = NewCWindow(nil, &wrect, "\p", true, plainDBox, | |
515 (WindowPtr)-1, false, 0); | |
516 ROM_HideMenuBar(this); | |
517 #endif | |
518 current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF; | |
519 current->pixels = (**(**SDL_Display).gdPMap).baseAddr; | |
520 this->UpdateRects = ROM_DirectUpdate; | |
521 } else { | |
522 GWorldPtr memworld; | |
523 PixMapHandle pixmap; | |
524 int style; | |
525 | |
526 style = noGrowDocProc; | |
527 if ( flags & SDL_NOFRAME ) { | |
528 style = plainDBox; | |
529 current->flags |= SDL_NOFRAME; | |
530 } else | |
531 if ( flags & SDL_RESIZABLE ) { | |
532 style = zoomDocProc; | |
533 current->flags |= SDL_RESIZABLE; | |
534 } | |
535 if ( SDL_Window && (style == current_style) ) { | |
536 /* Resize existing window, if necessary */ | |
537 if ( ((orect.right-orect.left) != width) || | |
538 ((orect.bottom-orect.top) != height) ) { | |
539 SizeWindow(SDL_Window, width, height, false); | |
540 } | |
541 } else { | |
542 /* Recreate the window in the new style */ | |
543 if ( SDL_Window ) { | |
544 DisposeWindow(SDL_Window); | |
545 } | |
546 SDL_Window = NewCWindow(nil, &wrect, "\p", true, | |
547 style, (WindowPtr)-1, true, 0); | |
548 | |
549 /* Set the window title, if any */ | |
550 { char *title; | |
551 SDL_WM_GetCaption(&title, NULL); | |
552 if ( title ) { | |
553 Mac_SetCaption(this, title, NULL); | |
554 } | |
555 } | |
556 } | |
557 current_style = style; | |
558 SetPalette(SDL_Window, SDL_CPal, false); | |
559 ActivatePalette(SDL_Window); | |
560 if ( NewGWorld(&memworld, 0, | |
561 #if TARGET_API_MAC_CARBON | |
562 GetWindowPortBounds(SDL_Window, &tmprect), | |
563 #else | |
564 &SDL_Window->portRect, | |
565 #endif | |
566 SDL_CTab, nil, 0) != noErr ) { | |
567 SDL_SetError("NewGWorld() failed"); | |
568 return(NULL); | |
569 } | |
570 SetWRefCon(SDL_Window, (long)memworld); | |
571 pixmap = GetGWorldPixMap(memworld); | |
572 LockPixels(pixmap); | |
573 current->pitch = (**pixmap).rowBytes & 0x3FFF; | |
574 current->pixels = GetPixBaseAddr(pixmap); | |
575 this->UpdateRects = ROM_WindowUpdate; | |
576 } | |
577 SetPortWindowPort(SDL_Window); | |
578 SelectWindow(SDL_Window); | |
579 | |
580 /* Handle OpenGL support */ | |
581 if ( flags & SDL_OPENGL ) { | |
582 if ( Mac_GL_Init(this) == 0 ) { | |
583 current->flags |= SDL_OPENGL; | |
584 } else { | |
585 current = NULL; | |
586 } | |
587 } | |
588 | |
589 if ( (flags & SDL_HWPALETTE) && (flags & SDL_FULLSCREEN) ) | |
590 current->flags |= SDL_HWPALETTE; | |
591 | |
592 /* We're live! */ | |
593 return(current); | |
594 } | |
595 | |
596 /* We don't actually allow hardware surfaces other than the main one */ | |
597 static int ROM_AllocHWSurface(_THIS, SDL_Surface *surface) | |
598 { | |
599 return(-1); | |
600 } | |
601 static void ROM_FreeHWSurface(_THIS, SDL_Surface *surface) | |
602 { | |
603 return; | |
604 } | |
605 static int ROM_LockHWSurface(_THIS, SDL_Surface *surface) | |
606 { | |
607 return(0); | |
608 } | |
609 static void ROM_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
610 { | |
611 return; | |
612 } | |
613 | |
614 static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
615 { | |
616 /* The application is already updating the visible video memory */ | |
617 return; | |
618 } | |
619 | |
620 static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect *rects) | |
621 { | |
622 GWorldPtr memworld; | |
623 GrafPtr saveport; | |
624 CGrafPtr thePort; | |
625 const BitMap *memBits; | |
626 const BitMap *winBits; | |
627 int i; | |
628 Rect update; | |
629 | |
630 /* Copy from the offscreen GWorld to the window port */ | |
631 GetPort(&saveport); | |
632 SetPortWindowPort(SDL_Window); | |
633 thePort = GetWindowPort(SDL_Window); | |
634 memworld = (GWorldPtr)GetWRefCon(SDL_Window); | |
635 #if TARGET_API_MAC_CARBON | |
636 memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld); | |
637 #else | |
638 memBits = &((GrafPtr)memworld)->portBits; | |
639 #endif | |
640 #if TARGET_API_MAC_CARBON | |
641 winBits = GetPortBitMapForCopyBits(thePort); | |
642 #else | |
643 winBits = &SDL_Window->portBits; | |
644 #endif | |
645 for ( i=0; i<numrects; ++i ) { | |
646 update.left = rects[i].x; | |
647 update.right = rects[i].x+rects[i].w; | |
648 update.top = rects[i].y; | |
649 update.bottom = rects[i].y+rects[i].h; | |
650 CopyBits(memBits, winBits, | |
651 &update, &update, srcCopy, nil); | |
652 } | |
653 #if TARGET_API_MAC_CARBON | |
654 if ( QDIsPortBuffered(thePort) ) { | |
655 QDFlushPortBuffer(thePort, NULL); | |
656 } | |
657 #endif | |
658 SetPort(saveport); | |
659 } | |
660 | |
661 static int ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
662 { | |
663 CTabHandle cTab; | |
664 int i; | |
665 | |
666 /* Get the colortable from the either the display or window */ | |
667 if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
668 cTab = (**(**SDL_Display).gdPMap).pmTable; | |
669 } else { | |
670 cTab = SDL_CTab; | |
671 } | |
672 | |
673 /* Verify the range of colors */ | |
674 if ( (firstcolor+ncolors) > ((**cTab).ctSize+1) ) { | |
675 return(0); | |
676 } | |
677 | |
678 /* Set the screen palette and update the display */ | |
679 for ( i=0; i< ncolors; ++i ) { | |
680 int j = firstcolor + i; | |
681 (**cTab).ctTable[j].value = j; | |
682 (**cTab).ctTable[j].rgb.red = colors[i].r << 8 | colors[i].r; | |
683 (**cTab).ctTable[j].rgb.green = colors[i].g << 8 | colors[i].g; | |
684 (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b; | |
685 } | |
686 // if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) | |
687 { | |
688 GDevice **odisplay; | |
689 odisplay = GetGDevice(); | |
690 SetGDevice(SDL_Display); | |
691 SetEntries(0, (**cTab).ctSize, (ColorSpec *)&(**cTab).ctTable); | |
692 SetGDevice(odisplay); | |
693 } | |
694 return(1); | |
695 } | |
696 | |
697 void ROM_VideoQuit(_THIS) | |
698 { | |
699 int i; | |
700 | |
701 /* Free current video mode */ | |
702 ROM_UnsetVideoMode(this, this->screen); | |
703 if ( SDL_Window ) { | |
704 DisposeWindow(SDL_Window); | |
705 SDL_Window = nil; | |
706 } | |
707 | |
708 /* Free palette and restore original one */ | |
709 if ( SDL_CTab != nil ) { | |
710 DisposeHandle((Handle)SDL_CTab); | |
711 SDL_CTab = nil; | |
712 } | |
713 if ( SDL_CPal != nil ) { | |
714 DisposePalette(SDL_CPal); | |
715 SDL_CPal = nil; | |
716 } | |
717 RestoreDeviceClut(GetMainDevice()); | |
718 | |
719 /* Free list of video modes */ | |
720 if ( SDL_modelist != NULL ) { | |
721 for ( i=0; SDL_modelist[i]; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
722 SDL_free(SDL_modelist[i]); |
0 | 723 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
724 SDL_free(SDL_modelist); |
0 | 725 SDL_modelist = NULL; |
726 } | |
727 } | |
728 |