src/video/macrom/SDL_romvideo.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
    51 #include "../maccommon/SDL_macwm_c.h"
    51 #include "../maccommon/SDL_macwm_c.h"
    52 #include "../maccommon/SDL_macmouse_c.h"
    52 #include "../maccommon/SDL_macmouse_c.h"
    53 #include "../maccommon/SDL_macevents_c.h"
    53 #include "../maccommon/SDL_macevents_c.h"
    54 
    54 
    55 /* Initialization/Query functions */
    55 /* Initialization/Query functions */
    56 static int ROM_VideoInit (_THIS, SDL_PixelFormat * vformat);
    56 static int ROM_VideoInit(_THIS, SDL_PixelFormat * vformat);
    57 static SDL_Rect **ROM_ListModes (_THIS, SDL_PixelFormat * format,
    57 static SDL_Rect **ROM_ListModes(_THIS, SDL_PixelFormat * format,
    58                                  Uint32 flags);
    58                                 Uint32 flags);
    59 static SDL_Surface *ROM_SetVideoMode (_THIS, SDL_Surface * current, int width,
    59 static SDL_Surface *ROM_SetVideoMode(_THIS, SDL_Surface * current, int width,
    60                                       int height, int bpp, Uint32 flags);
    60                                      int height, int bpp, Uint32 flags);
    61 static int ROM_SetColors (_THIS, int firstcolor, int ncolors,
    61 static int ROM_SetColors(_THIS, int firstcolor, int ncolors,
    62                           SDL_Color * colors);
    62                          SDL_Color * colors);
    63 static void ROM_VideoQuit (_THIS);
    63 static void ROM_VideoQuit(_THIS);
    64 
    64 
    65 /* Hardware surface functions */
    65 /* Hardware surface functions */
    66 static int ROM_AllocHWSurface (_THIS, SDL_Surface * surface);
    66 static int ROM_AllocHWSurface(_THIS, SDL_Surface * surface);
    67 static int ROM_LockHWSurface (_THIS, SDL_Surface * surface);
    67 static int ROM_LockHWSurface(_THIS, SDL_Surface * surface);
    68 static void ROM_UnlockHWSurface (_THIS, SDL_Surface * surface);
    68 static void ROM_UnlockHWSurface(_THIS, SDL_Surface * surface);
    69 static void ROM_FreeHWSurface (_THIS, SDL_Surface * surface);
    69 static void ROM_FreeHWSurface(_THIS, SDL_Surface * surface);
    70 
    70 
    71 #if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
    71 #if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
    72 /* Saved state for the menu bar */
    72 /* Saved state for the menu bar */
    73 static RgnHandle gSaveGrayRgn = nil;
    73 static RgnHandle gSaveGrayRgn = nil;
    74 static short gSaveMenuBar = 0;
    74 static short gSaveMenuBar = 0;
    88 		{ 0x41FA, 0x0014, 0x209F, (p1), (p2), (p3), 0x41FA, \
    88 		{ 0x41FA, 0x0014, 0x209F, (p1), (p2), (p3), 0x41FA, \
    89 		  0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 }
    89 		  0x0008, 0x2F10, 0x4E75, 0x0000, 0x0000, 0x0000 }
    90 
    90 
    91 /* ControlStrip inline glue for PowerPC */
    91 /* ControlStrip inline glue for PowerPC */
    92 static pascal Boolean
    92 static pascal Boolean
    93 SBIsControlStripVisible (void)
    93 SBIsControlStripVisible(void)
    94 {
    94 {
    95     static short procData[] = TWOWORDSTUB (0x7000, 0xAAF2);
    95     static short procData[] = TWOWORDSTUB(0x7000, 0xAAF2);
    96     ProcInfoType procInfo = kD0DispatchedPascalStackBased
    96     ProcInfoType procInfo = kD0DispatchedPascalStackBased
    97         | RESULT_SIZE (SIZE_CODE (sizeof (Boolean)))
    97         | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
    98         | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE (kFourByteCode);
    98         | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode);
    99 
    99 
   100     return ((Boolean)
   100     return ((Boolean)
   101             CallUniversalProc ((UniversalProcPtr) procData, procInfo, 0x00));
   101             CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x00));
   102 }
   102 }
   103 
   103 
   104 static pascal void
   104 static pascal void
   105 SBShowHideControlStrip (Boolean showIt)
   105 SBShowHideControlStrip(Boolean showIt)
   106 {
   106 {
   107     static short procData[] = THREEWORDSTUB (0x303C, 0x0101, 0xAAF2);
   107     static short procData[] = THREEWORDSTUB(0x303C, 0x0101, 0xAAF2);
   108     ProcInfoType procInfo = kD0DispatchedPascalStackBased
   108     ProcInfoType procInfo = kD0DispatchedPascalStackBased
   109         | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE (kFourByteCode)
   109         | DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(kFourByteCode)
   110         | DISPATCHED_STACK_ROUTINE_PARAMETER (1,
   110         | DISPATCHED_STACK_ROUTINE_PARAMETER(1,
   111                                               SIZE_CODE (sizeof (Boolean)));
   111                                              SIZE_CODE(sizeof(Boolean)));
   112 
   112 
   113     CallUniversalProc ((UniversalProcPtr) procData, procInfo, 0x01, showIt);
   113     CallUniversalProc((UniversalProcPtr) procData, procInfo, 0x01, showIt);
   114 }
   114 }
   115 #endif /* powerc */
   115 #endif /* powerc */
   116 #endif /* !TARGET_API_MAC_CARBON */
   116 #endif /* !TARGET_API_MAC_CARBON */
   117 
   117 
   118 /* Macintosh toolbox driver bootstrap functions */
   118 /* Macintosh toolbox driver bootstrap functions */
   119 
   119 
   120 static int
   120 static int
   121 ROM_Available (void)
   121 ROM_Available(void)
   122 {
   122 {
   123     return (1);
   123     return (1);
   124 }
   124 }
   125 
   125 
   126 static void
   126 static void
   127 ROM_DeleteDevice (SDL_VideoDevice * device)
   127 ROM_DeleteDevice(SDL_VideoDevice * device)
   128 {
   128 {
   129     SDL_free (device->hidden);
   129     SDL_free(device->hidden);
   130     SDL_free (device);
   130     SDL_free(device);
   131 }
   131 }
   132 
   132 
   133 static SDL_VideoDevice *
   133 static SDL_VideoDevice *
   134 ROM_CreateDevice (int devindex)
   134 ROM_CreateDevice(int devindex)
   135 {
   135 {
   136     SDL_VideoDevice *device;
   136     SDL_VideoDevice *device;
   137 
   137 
   138     /* Initialize all variables that we clean on shutdown */
   138     /* Initialize all variables that we clean on shutdown */
   139     device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
   139     device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
   140     if (device) {
   140     if (device) {
   141         SDL_memset (device, 0, (sizeof *device));
   141         SDL_memset(device, 0, (sizeof *device));
   142         device->hidden = (struct SDL_PrivateVideoData *)
   142         device->hidden = (struct SDL_PrivateVideoData *)
   143             SDL_malloc ((sizeof *device->hidden));
   143             SDL_malloc((sizeof *device->hidden));
   144     }
   144     }
   145     if ((device == NULL) || (device->hidden == NULL)) {
   145     if ((device == NULL) || (device->hidden == NULL)) {
   146         SDL_OutOfMemory ();
   146         SDL_OutOfMemory();
   147         if (device) {
   147         if (device) {
   148             SDL_free (device);
   148             SDL_free(device);
   149         }
   149         }
   150         return (0);
   150         return (0);
   151     }
   151     }
   152     SDL_memset (device->hidden, 0, (sizeof *device->hidden));
   152     SDL_memset(device->hidden, 0, (sizeof *device->hidden));
   153 
   153 
   154     /* Set the function pointers */
   154     /* Set the function pointers */
   155     device->VideoInit = ROM_VideoInit;
   155     device->VideoInit = ROM_VideoInit;
   156     device->ListModes = ROM_ListModes;
   156     device->ListModes = ROM_ListModes;
   157     device->SetVideoMode = ROM_SetVideoMode;
   157     device->SetVideoMode = ROM_SetVideoMode;
   195     ROM_Available, ROM_CreateDevice
   195     ROM_Available, ROM_CreateDevice
   196 };
   196 };
   197 
   197 
   198 
   198 
   199 static int
   199 static int
   200 ROM_VideoInit (_THIS, SDL_PixelFormat * vformat)
   200 ROM_VideoInit(_THIS, SDL_PixelFormat * vformat)
   201 {
   201 {
   202     long info;
   202     long info;
   203 
   203 
   204     /* Check out some things about the system */
   204     /* Check out some things about the system */
   205     Gestalt (gestaltQuickdrawVersion, &info);
   205     Gestalt(gestaltQuickdrawVersion, &info);
   206     if (info == gestaltOriginalQD) {
   206     if (info == gestaltOriginalQD) {
   207         SDL_SetError ("Color Quickdraw not available");
   207         SDL_SetError("Color Quickdraw not available");
   208         return (-1);
   208         return (-1);
   209     }
   209     }
   210 
   210 
   211     /* Start ROMintosh events */
   211     /* Start ROMintosh events */
   212     Mac_InitEvents (this);
   212     Mac_InitEvents(this);
   213 
   213 
   214     /* Get a handle to the main monitor */
   214     /* Get a handle to the main monitor */
   215     SDL_Display = GetMainDevice ();
   215     SDL_Display = GetMainDevice();
   216 
   216 
   217     /* Determine the current screen size */
   217     /* Determine the current screen size */
   218     this->info.current_w = (**SDL_Display).gdRect.right;
   218     this->info.current_w = (**SDL_Display).gdRect.right;
   219     this->info.current_h = (**SDL_Display).gdRect.bottom;
   219     this->info.current_h = (**SDL_Display).gdRect.bottom;
   220 
   220 
   229     default:
   229     default:
   230         break;
   230         break;
   231     }
   231     }
   232 
   232 
   233     /* Create our palette */
   233     /* Create our palette */
   234     SDL_CTab = (CTabHandle) NewHandle (sizeof (ColorSpec) * 256 + 8);
   234     SDL_CTab = (CTabHandle) NewHandle(sizeof(ColorSpec) * 256 + 8);
   235     if (SDL_CTab == nil) {
   235     if (SDL_CTab == nil) {
   236         SDL_OutOfMemory ();
   236         SDL_OutOfMemory();
   237         return (-1);
   237         return (-1);
   238     }
   238     }
   239     (**SDL_CTab).ctSeed = GetCTSeed ();
   239     (**SDL_CTab).ctSeed = GetCTSeed();
   240     (**SDL_CTab).ctFlags = 0;
   240     (**SDL_CTab).ctFlags = 0;
   241     (**SDL_CTab).ctSize = 255;
   241     (**SDL_CTab).ctSize = 255;
   242     CTabChanged (SDL_CTab);
   242     CTabChanged(SDL_CTab);
   243     SDL_CPal = NewPalette (256, SDL_CTab, pmExplicit + pmTolerant, 0);
   243     SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit + pmTolerant, 0);
   244 
   244 
   245     /* Get a list of available fullscreen modes */
   245     /* Get a list of available fullscreen modes */
   246     SDL_modelist = (SDL_Rect **) SDL_malloc ((1 + 1) * sizeof (SDL_Rect *));
   246     SDL_modelist = (SDL_Rect **) SDL_malloc((1 + 1) * sizeof(SDL_Rect *));
   247     if (SDL_modelist) {
   247     if (SDL_modelist) {
   248         SDL_modelist[0] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
   248         SDL_modelist[0] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
   249         if (SDL_modelist[0]) {
   249         if (SDL_modelist[0]) {
   250             SDL_modelist[0]->x = 0;
   250             SDL_modelist[0]->x = 0;
   251             SDL_modelist[0]->y = 0;
   251             SDL_modelist[0]->y = 0;
   252             SDL_modelist[0]->w = (**SDL_Display).gdRect.right;
   252             SDL_modelist[0]->w = (**SDL_Display).gdRect.right;
   253             SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom;
   253             SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom;
   261     /* We're done! */
   261     /* We're done! */
   262     return (0);
   262     return (0);
   263 }
   263 }
   264 
   264 
   265 static SDL_Rect **
   265 static SDL_Rect **
   266 ROM_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
   266 ROM_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
   267 {
   267 {
   268     if (this->screen->format->BitsPerPixel == format->BitsPerPixel) {
   268     if (this->screen->format->BitsPerPixel == format->BitsPerPixel) {
   269         if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   269         if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   270             return (SDL_modelist);
   270             return (SDL_modelist);
   271         } else {
   271         } else {
   275         return ((SDL_Rect **) 0);
   275         return ((SDL_Rect **) 0);
   276     }
   276     }
   277 }
   277 }
   278 
   278 
   279 static void
   279 static void
   280 ROM_HideMenuBar (_THIS)
   280 ROM_HideMenuBar(_THIS)
   281 {
   281 {
   282 #if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
   282 #if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
   283     RgnHandle drawRgn = nil;
   283     RgnHandle drawRgn = nil;
   284     RgnHandle tempRgn = nil;
   284     RgnHandle tempRgn = nil;
   285     RgnHandle grayRgn = nil;
   285     RgnHandle grayRgn = nil;
   288     GrafPtr savePort;
   288     GrafPtr savePort;
   289     long response;
   289     long response;
   290     short height;
   290     short height;
   291     EventRecord theEvent;
   291     EventRecord theEvent;
   292 
   292 
   293     height = GetMBarHeight ();
   293     height = GetMBarHeight();
   294 
   294 
   295     if (height > 0) {
   295     if (height > 0) {
   296         tempRgn = NewRgn ();
   296         tempRgn = NewRgn();
   297         drawRgn = NewRgn ();
   297         drawRgn = NewRgn();
   298         gSaveGrayRgn = NewRgn ();
   298         gSaveGrayRgn = NewRgn();
   299         if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
   299         if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
   300             goto CLEANUP;
   300             goto CLEANUP;
   301         }
   301         }
   302         grayRgn = GetGrayRgn ();        /* No need to check for this */
   302         grayRgn = GetGrayRgn(); /* No need to check for this */
   303 
   303 
   304         GetPort (&savePort);
   304         GetPort(&savePort);
   305 
   305 
   306         /* Hide the control strip if it's present, and record its 
   306         /* Hide the control strip if it's present, and record its 
   307            previous position into the dirty region for redrawing. 
   307            previous position into the dirty region for redrawing. 
   308            This isn't necessary, but may help catch stray bits. */
   308            This isn't necessary, but may help catch stray bits. */
   309         CopyRgn (grayRgn, tempRgn);
   309         CopyRgn(grayRgn, tempRgn);
   310         if (!Gestalt (gestaltControlStripAttr, &response) &&
   310         if (!Gestalt(gestaltControlStripAttr, &response) &&
   311             (response & (1L << gestaltControlStripExists))) {
   311             (response & (1L << gestaltControlStripExists))) {
   312             gSaveCSVis = SBIsControlStripVisible ();
   312             gSaveCSVis = SBIsControlStripVisible();
   313             if (gSaveCSVis)
   313             if (gSaveCSVis)
   314                 SBShowHideControlStrip (false);
   314                 SBShowHideControlStrip(false);
   315         }
   315         }
   316         DiffRgn (grayRgn, tempRgn, drawRgn);
   316         DiffRgn(grayRgn, tempRgn, drawRgn);
   317 
   317 
   318         /* Save the gray region once the control strip is hidden */
   318         /* Save the gray region once the control strip is hidden */
   319         CopyRgn (grayRgn, gSaveGrayRgn);
   319         CopyRgn(grayRgn, gSaveGrayRgn);
   320 
   320 
   321         /* Change the menu height in lowmem */
   321         /* Change the menu height in lowmem */
   322         gSaveMenuBar = height;
   322         gSaveMenuBar = height;
   323         LMSetMBarHeight (0);
   323         LMSetMBarHeight(0);
   324 
   324 
   325         /* Walk the monitor rectangles, and combine any pieces that
   325         /* Walk the monitor rectangles, and combine any pieces that
   326            aren't in GrayRgn: menubar, round corners, fake floaters. */
   326            aren't in GrayRgn: menubar, round corners, fake floaters. */
   327         for (gd = GetDeviceList (); gd; gd = GetNextDevice (gd)) {
   327         for (gd = GetDeviceList(); gd; gd = GetNextDevice(gd)) {
   328             if (!TestDeviceAttribute (gd, screenDevice))
   328             if (!TestDeviceAttribute(gd, screenDevice))
   329                 continue;
   329                 continue;
   330             if (!TestDeviceAttribute (gd, screenActive))
   330             if (!TestDeviceAttribute(gd, screenActive))
   331                 continue;
   331                 continue;
   332 
   332 
   333             RectRgn (tempRgn, &(*gd)->gdRect);  /* Get the whole screen */
   333             RectRgn(tempRgn, &(*gd)->gdRect);   /* Get the whole screen */
   334             DiffRgn (tempRgn, grayRgn, tempRgn);        /* Subtract out GrayRgn */
   334             DiffRgn(tempRgn, grayRgn, tempRgn); /* Subtract out GrayRgn */
   335             UnionRgn (tempRgn, drawRgn, drawRgn);       /* Combine all the bits */
   335             UnionRgn(tempRgn, drawRgn, drawRgn);        /* Combine all the bits */
   336         }
   336         }
   337 
   337 
   338         /* Add the bits into the GrayRgn */
   338         /* Add the bits into the GrayRgn */
   339         UnionRgn (drawRgn, grayRgn, grayRgn);
   339         UnionRgn(drawRgn, grayRgn, grayRgn);
   340 
   340 
   341         /* Modify the vis regions of exposed windows */
   341         /* Modify the vis regions of exposed windows */
   342         window = (FrontWindow ())? FrontWindow () : (WindowPtr) - 1L;
   342         window = (FrontWindow())? FrontWindow() : (WindowPtr) - 1L;
   343         PaintBehind (window, drawRgn);
   343         PaintBehind(window, drawRgn);
   344         CalcVisBehind (window, drawRgn);
   344         CalcVisBehind(window, drawRgn);
   345 
   345 
   346         SetPort (savePort);
   346         SetPort(savePort);
   347 
   347 
   348         /* Yield time so that floaters can catch up */
   348         /* Yield time so that floaters can catch up */
   349         EventAvail (0, &theEvent);
   349         EventAvail(0, &theEvent);
   350         EventAvail (0, &theEvent);
   350         EventAvail(0, &theEvent);
   351         EventAvail (0, &theEvent);
   351         EventAvail(0, &theEvent);
   352         EventAvail (0, &theEvent);
   352         EventAvail(0, &theEvent);
   353     }
   353     }
   354 
   354 
   355   CLEANUP:
   355   CLEANUP:
   356 
   356 
   357     if (tempRgn)
   357     if (tempRgn)
   358         DisposeRgn (tempRgn);
   358         DisposeRgn(tempRgn);
   359     if (drawRgn)
   359     if (drawRgn)
   360         DisposeRgn (drawRgn);
   360         DisposeRgn(drawRgn);
   361 #endif /* !TARGET_API_MAC_CARBON */
   361 #endif /* !TARGET_API_MAC_CARBON */
   362 }
   362 }
   363 
   363 
   364 static void
   364 static void
   365 ROM_ShowMenuBar (_THIS)
   365 ROM_ShowMenuBar(_THIS)
   366 {
   366 {
   367 #if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
   367 #if !TARGET_API_MAC_CARBON      /* This seems not to be available? -sts Aug 2000 */
   368     RgnHandle drawRgn = nil;
   368     RgnHandle drawRgn = nil;
   369     RgnHandle menuRgn = nil;
   369     RgnHandle menuRgn = nil;
   370     RgnHandle tempRgn = nil;
   370     RgnHandle tempRgn = nil;
   377     short height;
   377     short height;
   378     EventRecord theEvent;
   378     EventRecord theEvent;
   379     RGBColor saveRGB;
   379     RGBColor saveRGB;
   380     RGBColor blackRGB = { 0, 0, 0 };
   380     RGBColor blackRGB = { 0, 0, 0 };
   381 
   381 
   382     height = GetMBarHeight ();
   382     height = GetMBarHeight();
   383 
   383 
   384     if ((height <= 0) && (gSaveMenuBar > 0)) {
   384     if ((height <= 0) && (gSaveMenuBar > 0)) {
   385         drawRgn = NewRgn ();
   385         drawRgn = NewRgn();
   386         menuRgn = NewRgn ();
   386         menuRgn = NewRgn();
   387         tempRgn = NewRgn ();
   387         tempRgn = NewRgn();
   388         if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
   388         if (!tempRgn || !drawRgn || !gSaveGrayRgn) {
   389             goto CLEANUP;
   389             goto CLEANUP;
   390         }
   390         }
   391         grayRgn = GetGrayRgn ();        /* No need to check for this */
   391         grayRgn = GetGrayRgn(); /* No need to check for this */
   392 
   392 
   393         GetPort (&savePort);
   393         GetPort(&savePort);
   394         GetWMgrPort (&wMgrPort);
   394         GetWMgrPort(&wMgrPort);
   395 
   395 
   396         /* Set the height properly */
   396         /* Set the height properly */
   397         LMSetMBarHeight (gSaveMenuBar);
   397         LMSetMBarHeight(gSaveMenuBar);
   398 
   398 
   399         /* Restore the old GrayRgn: rounded corners, etc, but not
   399         /* Restore the old GrayRgn: rounded corners, etc, but not
   400            the menubar -- subtract that out first! */
   400            the menubar -- subtract that out first! */
   401         if (gSaveGrayRgn) {
   401         if (gSaveGrayRgn) {
   402             menuRect = (*GetMainDevice ())->gdRect;
   402             menuRect = (*GetMainDevice())->gdRect;
   403             menuRect.bottom = menuRect.top + gSaveMenuBar;
   403             menuRect.bottom = menuRect.top + gSaveMenuBar;
   404             RectRgn (menuRgn, &menuRect);
   404             RectRgn(menuRgn, &menuRect);
   405 
   405 
   406             DiffRgn (grayRgn, gSaveGrayRgn, drawRgn);   /* What do we inval? */
   406             DiffRgn(grayRgn, gSaveGrayRgn, drawRgn);    /* What do we inval? */
   407             DiffRgn (drawRgn, menuRgn, drawRgn);        /* Clip out the menu */
   407             DiffRgn(drawRgn, menuRgn, drawRgn); /* Clip out the menu */
   408 
   408 
   409             /* Now redraw the corners and other bits black */
   409             /* Now redraw the corners and other bits black */
   410             SetPort (wMgrPort);
   410             SetPort(wMgrPort);
   411             GetClip (tempRgn);
   411             GetClip(tempRgn);
   412             SetClip (drawRgn);
   412             SetClip(drawRgn);
   413             GetForeColor (&saveRGB);
   413             GetForeColor(&saveRGB);
   414             RGBForeColor (&blackRGB);
   414             RGBForeColor(&blackRGB);
   415             PaintRgn (drawRgn);
   415             PaintRgn(drawRgn);
   416             RGBForeColor (&saveRGB);
   416             RGBForeColor(&saveRGB);
   417             SetClip (tempRgn);
   417             SetClip(tempRgn);
   418             SetPort (savePort);
   418             SetPort(savePort);
   419 
   419 
   420             UnionRgn (drawRgn, menuRgn, drawRgn);       /* Put back the menu */
   420             UnionRgn(drawRgn, menuRgn, drawRgn);        /* Put back the menu */
   421 
   421 
   422             /* Now actually restore the GrayRgn */
   422             /* Now actually restore the GrayRgn */
   423             CopyRgn (gSaveGrayRgn, grayRgn);
   423             CopyRgn(gSaveGrayRgn, grayRgn);
   424             DisposeRgn (gSaveGrayRgn);
   424             DisposeRgn(gSaveGrayRgn);
   425             gSaveGrayRgn = nil;
   425             gSaveGrayRgn = nil;
   426         }
   426         }
   427 
   427 
   428         /* Modify the vis regions of exposed windows and draw menubar */
   428         /* Modify the vis regions of exposed windows and draw menubar */
   429         window = (FrontWindow ())? FrontWindow () : (WindowPtr) - 1L;
   429         window = (FrontWindow())? FrontWindow() : (WindowPtr) - 1L;
   430         PaintBehind (window, drawRgn);
   430         PaintBehind(window, drawRgn);
   431         CalcVisBehind (window, drawRgn);
   431         CalcVisBehind(window, drawRgn);
   432         DrawMenuBar ();
   432         DrawMenuBar();
   433 
   433 
   434         SetPort (savePort);
   434         SetPort(savePort);
   435         gSaveMenuBar = 0;
   435         gSaveMenuBar = 0;
   436 
   436 
   437         /* Now show the control strip if it's present */
   437         /* Now show the control strip if it's present */
   438         if (!Gestalt (gestaltControlStripAttr, &response) &&
   438         if (!Gestalt(gestaltControlStripAttr, &response) &&
   439             (response & (1L << gestaltControlStripExists))) {
   439             (response & (1L << gestaltControlStripExists))) {
   440             if (gSaveCSVis && !SBIsControlStripVisible ())
   440             if (gSaveCSVis && !SBIsControlStripVisible())
   441                 SBShowHideControlStrip (true);
   441                 SBShowHideControlStrip(true);
   442             gSaveCSVis = true;
   442             gSaveCSVis = true;
   443         }
   443         }
   444 
   444 
   445         /* Yield time so that floaters can catch up */
   445         /* Yield time so that floaters can catch up */
   446         EventAvail (0, &theEvent);
   446         EventAvail(0, &theEvent);
   447         EventAvail (0, &theEvent);
   447         EventAvail(0, &theEvent);
   448         EventAvail (0, &theEvent);
   448         EventAvail(0, &theEvent);
   449         EventAvail (0, &theEvent);
   449         EventAvail(0, &theEvent);
   450     }
   450     }
   451 
   451 
   452   CLEANUP:
   452   CLEANUP:
   453 
   453 
   454     if (drawRgn)
   454     if (drawRgn)
   455         DisposeRgn (drawRgn);
   455         DisposeRgn(drawRgn);
   456     if (menuRgn)
   456     if (menuRgn)
   457         DisposeRgn (menuRgn);
   457         DisposeRgn(menuRgn);
   458     if (tempRgn)
   458     if (tempRgn)
   459         DisposeRgn (tempRgn);
   459         DisposeRgn(tempRgn);
   460 #endif /* !TARGET_API_MAC_CARBON */
   460 #endif /* !TARGET_API_MAC_CARBON */
   461 }
   461 }
   462 
   462 
   463 /* Various screen update functions available */
   463 /* Various screen update functions available */
   464 static void ROM_DirectUpdate (_THIS, int numrects, SDL_Rect * rects);
   464 static void ROM_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
   465 static void ROM_WindowUpdate (_THIS, int numrects, SDL_Rect * rects);
   465 static void ROM_WindowUpdate(_THIS, int numrects, SDL_Rect * rects);
   466 
   466 
   467 static void
   467 static void
   468 ROM_UnsetVideoMode (_THIS, SDL_Surface * current)
   468 ROM_UnsetVideoMode(_THIS, SDL_Surface * current)
   469 {
   469 {
   470     /* Free the current window, if any */
   470     /* Free the current window, if any */
   471     if (SDL_Window != nil) {
   471     if (SDL_Window != nil) {
   472         GWorldPtr memworld;
   472         GWorldPtr memworld;
   473 
   473 
   474         /* Handle OpenGL support */
   474         /* Handle OpenGL support */
   475         Mac_GL_Quit (this);
   475         Mac_GL_Quit(this);
   476 
   476 
   477         memworld = (GWorldPtr) GetWRefCon (SDL_Window);
   477         memworld = (GWorldPtr) GetWRefCon(SDL_Window);
   478         if (memworld != nil) {
   478         if (memworld != nil) {
   479             UnlockPixels (GetGWorldPixMap (memworld));
   479             UnlockPixels(GetGWorldPixMap(memworld));
   480             DisposeGWorld (memworld);
   480             DisposeGWorld(memworld);
   481         }
   481         }
   482         if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   482         if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   483 #if USE_QUICKTIME
   483 #if USE_QUICKTIME
   484             EndFullScreen (fullscreen_ctx, nil);
   484             EndFullScreen(fullscreen_ctx, nil);
   485             SDL_Window = nil;
   485             SDL_Window = nil;
   486 #else
   486 #else
   487             ROM_ShowMenuBar (this);
   487             ROM_ShowMenuBar(this);
   488 #endif
   488 #endif
   489         }
   489         }
   490     }
   490     }
   491     current->pixels = NULL;
   491     current->pixels = NULL;
   492     current->flags &= ~(SDL_HWSURFACE | SDL_FULLSCREEN);
   492     current->flags &= ~(SDL_HWSURFACE | SDL_FULLSCREEN);
   493 }
   493 }
   494 
   494 
   495 static SDL_Surface *
   495 static SDL_Surface *
   496 ROM_SetVideoMode (_THIS, SDL_Surface * current,
   496 ROM_SetVideoMode(_THIS, SDL_Surface * current,
   497                   int width, int height, int bpp, Uint32 flags)
   497                  int width, int height, int bpp, Uint32 flags)
   498 {
   498 {
   499     Rect wrect, orect;
   499     Rect wrect, orect;
   500 #if TARGET_API_MAC_CARBON
   500 #if TARGET_API_MAC_CARBON
   501     Rect tmprect;
   501     Rect tmprect;
   502 #endif
   502 #endif
   503 
   503 
   504     /* Free any previous video mode */
   504     /* Free any previous video mode */
   505     ROM_UnsetVideoMode (this, current);
   505     ROM_UnsetVideoMode(this, current);
   506 
   506 
   507     /* Create the ROM window and SDL video surface */
   507     /* Create the ROM window and SDL video surface */
   508     current->flags = 0;         /* Clear flags */
   508     current->flags = 0;         /* Clear flags */
   509     current->w = width;
   509     current->w = width;
   510     current->h = height;
   510     current->h = height;
   511     SetRect (&wrect, 0, 0, width, height);
   511     SetRect(&wrect, 0, 0, width, height);
   512     if (SDL_Window) {
   512     if (SDL_Window) {
   513         /* If we recreate the window, don't move it around */
   513         /* If we recreate the window, don't move it around */
   514 #if TARGET_API_MAC_CARBON
   514 #if TARGET_API_MAC_CARBON
   515         orect = *GetWindowPortBounds (SDL_Window, &tmprect);
   515         orect = *GetWindowPortBounds(SDL_Window, &tmprect);
   516 #else
   516 #else
   517         orect = SDL_Window->portRect;
   517         orect = SDL_Window->portRect;
   518 #endif
   518 #endif
   519         OffsetRect (&wrect, orect.left, orect.top);
   519         OffsetRect(&wrect, orect.left, orect.top);
   520     } else {
   520     } else {
   521         /* Center the window the first time we show it */
   521         /* Center the window the first time we show it */
   522         OffsetRect (&wrect,
   522         OffsetRect(&wrect,
   523                     (SDL_modelist[0]->w - width) / 2,
   523                    (SDL_modelist[0]->w - width) / 2,
   524                     (SDL_modelist[0]->h - height) / 2);
   524                    (SDL_modelist[0]->h - height) / 2);
   525     }
   525     }
   526 
   526 
   527 #if defined(__MACOSX__) && !USE_QUICKTIME
   527 #if defined(__MACOSX__) && !USE_QUICKTIME
   528     /* Hum.. fullscreen mode is broken */
   528     /* Hum.. fullscreen mode is broken */
   529     flags &= ~SDL_FULLSCREEN;
   529     flags &= ~SDL_FULLSCREEN;
   530 #endif
   530 #endif
   531     if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   531     if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
   532         /* Create the fullscreen window and use screen bits */
   532         /* Create the fullscreen window and use screen bits */
   533         current->flags |= SDL_HWSURFACE | SDL_FULLSCREEN;
   533         current->flags |= SDL_HWSURFACE | SDL_FULLSCREEN;
   534         if (SDL_Window) {
   534         if (SDL_Window) {
   535             DisposeWindow (SDL_Window);
   535             DisposeWindow(SDL_Window);
   536         }
   536         }
   537 #if USE_QUICKTIME
   537 #if USE_QUICKTIME
   538         BeginFullScreen (&fullscreen_ctx, nil, 0, 0, &SDL_Window, nil, 0);
   538         BeginFullScreen(&fullscreen_ctx, nil, 0, 0, &SDL_Window, nil, 0);
   539 #else
   539 #else
   540         SDL_Window = NewCWindow (nil, &wrect, "\p", true, plainDBox,
   540         SDL_Window = NewCWindow(nil, &wrect, "\p", true, plainDBox,
   541                                  (WindowPtr) - 1, false, 0);
   541                                 (WindowPtr) - 1, false, 0);
   542         ROM_HideMenuBar (this);
   542         ROM_HideMenuBar(this);
   543 #endif
   543 #endif
   544         current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF;
   544         current->pitch = (**(**SDL_Display).gdPMap).rowBytes & 0x3FFF;
   545         current->pixels = (**(**SDL_Display).gdPMap).baseAddr;
   545         current->pixels = (**(**SDL_Display).gdPMap).baseAddr;
   546         this->UpdateRects = ROM_DirectUpdate;
   546         this->UpdateRects = ROM_DirectUpdate;
   547     } else {
   547     } else {
   559         }
   559         }
   560         if (SDL_Window && (style == current_style)) {
   560         if (SDL_Window && (style == current_style)) {
   561             /* Resize existing window, if necessary */
   561             /* Resize existing window, if necessary */
   562             if (((orect.right - orect.left) != width) ||
   562             if (((orect.right - orect.left) != width) ||
   563                 ((orect.bottom - orect.top) != height)) {
   563                 ((orect.bottom - orect.top) != height)) {
   564                 SizeWindow (SDL_Window, width, height, false);
   564                 SizeWindow(SDL_Window, width, height, false);
   565             }
   565             }
   566         } else {
   566         } else {
   567             /* Recreate the window in the new style */
   567             /* Recreate the window in the new style */
   568             if (SDL_Window) {
   568             if (SDL_Window) {
   569                 DisposeWindow (SDL_Window);
   569                 DisposeWindow(SDL_Window);
   570             }
   570             }
   571             SDL_Window = NewCWindow (nil, &wrect, "\p", true,
   571             SDL_Window = NewCWindow(nil, &wrect, "\p", true,
   572                                      style, (WindowPtr) - 1, true, 0);
   572                                     style, (WindowPtr) - 1, true, 0);
   573 
   573 
   574             /* Set the window title, if any */
   574             /* Set the window title, if any */
   575             {
   575             {
   576                 char *title;
   576                 char *title;
   577                 SDL_WM_GetCaption (&title, NULL);
   577                 SDL_WM_GetCaption(&title, NULL);
   578                 if (title) {
   578                 if (title) {
   579                     Mac_SetCaption (this, title, NULL);
   579                     Mac_SetCaption(this, title, NULL);
   580                 }
   580                 }
   581             }
   581             }
   582         }
   582         }
   583         current_style = style;
   583         current_style = style;
   584         SetPalette (SDL_Window, SDL_CPal, false);
   584         SetPalette(SDL_Window, SDL_CPal, false);
   585         ActivatePalette (SDL_Window);
   585         ActivatePalette(SDL_Window);
   586         if (NewGWorld (&memworld, 0,
   586         if (NewGWorld(&memworld, 0,
   587 #if TARGET_API_MAC_CARBON
   587 #if TARGET_API_MAC_CARBON
   588                        GetWindowPortBounds (SDL_Window, &tmprect),
   588                       GetWindowPortBounds(SDL_Window, &tmprect),
   589 #else
   589 #else
   590                        &SDL_Window->portRect,
   590                       &SDL_Window->portRect,
   591 #endif
   591 #endif
   592                        SDL_CTab, nil, 0) != noErr) {
   592                       SDL_CTab, nil, 0) != noErr) {
   593             SDL_SetError ("NewGWorld() failed");
   593             SDL_SetError("NewGWorld() failed");
   594             return (NULL);
   594             return (NULL);
   595         }
   595         }
   596         SetWRefCon (SDL_Window, (long) memworld);
   596         SetWRefCon(SDL_Window, (long) memworld);
   597         pixmap = GetGWorldPixMap (memworld);
   597         pixmap = GetGWorldPixMap(memworld);
   598         LockPixels (pixmap);
   598         LockPixels(pixmap);
   599         current->pitch = (**pixmap).rowBytes & 0x3FFF;
   599         current->pitch = (**pixmap).rowBytes & 0x3FFF;
   600         current->pixels = GetPixBaseAddr (pixmap);
   600         current->pixels = GetPixBaseAddr(pixmap);
   601         this->UpdateRects = ROM_WindowUpdate;
   601         this->UpdateRects = ROM_WindowUpdate;
   602     }
   602     }
   603     SetPortWindowPort (SDL_Window);
   603     SetPortWindowPort(SDL_Window);
   604     SelectWindow (SDL_Window);
   604     SelectWindow(SDL_Window);
   605 
   605 
   606     /* Handle OpenGL support */
   606     /* Handle OpenGL support */
   607     if (flags & SDL_INTERNALOPENGL) {
   607     if (flags & SDL_INTERNALOPENGL) {
   608         if (Mac_GL_Init (this) == 0) {
   608         if (Mac_GL_Init(this) == 0) {
   609             current->flags |= SDL_INTERNALOPENGL;
   609             current->flags |= SDL_INTERNALOPENGL;
   610         } else {
   610         } else {
   611             current = NULL;
   611             current = NULL;
   612         }
   612         }
   613     }
   613     }
   619     return (current);
   619     return (current);
   620 }
   620 }
   621 
   621 
   622 /* We don't actually allow hardware surfaces other than the main one */
   622 /* We don't actually allow hardware surfaces other than the main one */
   623 static int
   623 static int
   624 ROM_AllocHWSurface (_THIS, SDL_Surface * surface)
   624 ROM_AllocHWSurface(_THIS, SDL_Surface * surface)
   625 {
   625 {
   626     return (-1);
   626     return (-1);
   627 }
   627 }
   628 static void
   628 static void
   629 ROM_FreeHWSurface (_THIS, SDL_Surface * surface)
   629 ROM_FreeHWSurface(_THIS, SDL_Surface * surface)
   630 {
   630 {
   631     return;
   631     return;
   632 }
   632 }
   633 static int
   633 static int
   634 ROM_LockHWSurface (_THIS, SDL_Surface * surface)
   634 ROM_LockHWSurface(_THIS, SDL_Surface * surface)
   635 {
   635 {
   636     return (0);
   636     return (0);
   637 }
   637 }
   638 static void
   638 static void
   639 ROM_UnlockHWSurface (_THIS, SDL_Surface * surface)
   639 ROM_UnlockHWSurface(_THIS, SDL_Surface * surface)
   640 {
   640 {
   641     return;
   641     return;
   642 }
   642 }
   643 
   643 
   644 static void
   644 static void
   645 ROM_DirectUpdate (_THIS, int numrects, SDL_Rect * rects)
   645 ROM_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
   646 {
   646 {
   647     /* The application is already updating the visible video memory */
   647     /* The application is already updating the visible video memory */
   648     return;
   648     return;
   649 }
   649 }
   650 
   650 
   651 static void
   651 static void
   652 ROM_WindowUpdate (_THIS, int numrects, SDL_Rect * rects)
   652 ROM_WindowUpdate(_THIS, int numrects, SDL_Rect * rects)
   653 {
   653 {
   654     GWorldPtr memworld;
   654     GWorldPtr memworld;
   655     GrafPtr saveport;
   655     GrafPtr saveport;
   656     CGrafPtr thePort;
   656     CGrafPtr thePort;
   657     const BitMap *memBits;
   657     const BitMap *memBits;
   658     const BitMap *winBits;
   658     const BitMap *winBits;
   659     int i;
   659     int i;
   660     Rect update;
   660     Rect update;
   661 
   661 
   662     /* Copy from the offscreen GWorld to the window port */
   662     /* Copy from the offscreen GWorld to the window port */
   663     GetPort (&saveport);
   663     GetPort(&saveport);
   664     SetPortWindowPort (SDL_Window);
   664     SetPortWindowPort(SDL_Window);
   665     thePort = GetWindowPort (SDL_Window);
   665     thePort = GetWindowPort(SDL_Window);
   666     memworld = (GWorldPtr) GetWRefCon (SDL_Window);
   666     memworld = (GWorldPtr) GetWRefCon(SDL_Window);
   667 #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
   667 #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
   668     memBits = GetPortBitMapForCopyBits ((CGrafPtr) memworld);
   668     memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);
   669 #else
   669 #else
   670     memBits = &((GrafPtr) memworld)->portBits;
   670     memBits = &((GrafPtr) memworld)->portBits;
   671 #endif
   671 #endif
   672 #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
   672 #if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
   673     winBits = GetPortBitMapForCopyBits (thePort);
   673     winBits = GetPortBitMapForCopyBits(thePort);
   674 #else
   674 #else
   675     winBits = &SDL_Window->portBits;
   675     winBits = &SDL_Window->portBits;
   676 #endif
   676 #endif
   677     for (i = 0; i < numrects; ++i) {
   677     for (i = 0; i < numrects; ++i) {
   678         update.left = rects[i].x;
   678         update.left = rects[i].x;
   679         update.right = rects[i].x + rects[i].w;
   679         update.right = rects[i].x + rects[i].w;
   680         update.top = rects[i].y;
   680         update.top = rects[i].y;
   681         update.bottom = rects[i].y + rects[i].h;
   681         update.bottom = rects[i].y + rects[i].h;
   682         CopyBits (memBits, winBits, &update, &update, srcCopy, nil);
   682         CopyBits(memBits, winBits, &update, &update, srcCopy, nil);
   683     }
   683     }
   684 #if TARGET_API_MAC_CARBON
   684 #if TARGET_API_MAC_CARBON
   685     if (QDIsPortBuffered (thePort)) {
   685     if (QDIsPortBuffered(thePort)) {
   686         QDFlushPortBuffer (thePort, NULL);
   686         QDFlushPortBuffer(thePort, NULL);
   687     }
   687     }
   688 #endif
   688 #endif
   689     SetPort (saveport);
   689     SetPort(saveport);
   690 }
   690 }
   691 
   691 
   692 static int
   692 static int
   693 ROM_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
   693 ROM_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
   694 {
   694 {
   695     CTabHandle cTab;
   695     CTabHandle cTab;
   696     int i;
   696     int i;
   697 
   697 
   698     /* Get the colortable from the either the display or window */
   698     /* Get the colortable from the either the display or window */
   716         (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b;
   716         (**cTab).ctTable[j].rgb.blue = colors[i].b << 8 | colors[i].b;
   717     }
   717     }
   718 //      if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) 
   718 //      if ( (this->screen->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) 
   719     {
   719     {
   720         GDevice **odisplay;
   720         GDevice **odisplay;
   721         odisplay = GetGDevice ();
   721         odisplay = GetGDevice();
   722         SetGDevice (SDL_Display);
   722         SetGDevice(SDL_Display);
   723         SetEntries (0, (**cTab).ctSize, (ColorSpec *) & (**cTab).ctTable);
   723         SetEntries(0, (**cTab).ctSize, (ColorSpec *) & (**cTab).ctTable);
   724         SetGDevice (odisplay);
   724         SetGDevice(odisplay);
   725     }
   725     }
   726     return (1);
   726     return (1);
   727 }
   727 }
   728 
   728 
   729 void
   729 void
   730 ROM_VideoQuit (_THIS)
   730 ROM_VideoQuit(_THIS)
   731 {
   731 {
   732     int i;
   732     int i;
   733 
   733 
   734     /* Free current video mode */
   734     /* Free current video mode */
   735     ROM_UnsetVideoMode (this, this->screen);
   735     ROM_UnsetVideoMode(this, this->screen);
   736     if (SDL_Window) {
   736     if (SDL_Window) {
   737         DisposeWindow (SDL_Window);
   737         DisposeWindow(SDL_Window);
   738         SDL_Window = nil;
   738         SDL_Window = nil;
   739     }
   739     }
   740 
   740 
   741     /* Free palette and restore original one */
   741     /* Free palette and restore original one */
   742     if (SDL_CTab != nil) {
   742     if (SDL_CTab != nil) {
   743         DisposeHandle ((Handle) SDL_CTab);
   743         DisposeHandle((Handle) SDL_CTab);
   744         SDL_CTab = nil;
   744         SDL_CTab = nil;
   745     }
   745     }
   746     if (SDL_CPal != nil) {
   746     if (SDL_CPal != nil) {
   747         DisposePalette (SDL_CPal);
   747         DisposePalette(SDL_CPal);
   748         SDL_CPal = nil;
   748         SDL_CPal = nil;
   749     }
   749     }
   750     RestoreDeviceClut (GetMainDevice ());
   750     RestoreDeviceClut(GetMainDevice());
   751 
   751 
   752     /* Free list of video modes */
   752     /* Free list of video modes */
   753     if (SDL_modelist != NULL) {
   753     if (SDL_modelist != NULL) {
   754         for (i = 0; SDL_modelist[i]; ++i) {
   754         for (i = 0; SDL_modelist[i]; ++i) {
   755             SDL_free (SDL_modelist[i]);
   755             SDL_free(SDL_modelist[i]);
   756         }
   756         }
   757         SDL_free (SDL_modelist);
   757         SDL_free(SDL_modelist);
   758         SDL_modelist = NULL;
   758         SDL_modelist = NULL;
   759     }
   759     }
   760 }
   760 }
   761 
   761 
   762 /* vi: set ts=4 sw=4 expandtab: */
   762 /* vi: set ts=4 sw=4 expandtab: */