diff src/video/photon/SDL_ph_modes.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents e49147870aac
children 4da1ee79c9af
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_modes.c	Sun May 21 17:27:13 2006 +0000
+++ b/src/video/photon/SDL_ph_modes.c	Sun May 28 13:04:16 2006 +0000
@@ -27,136 +27,124 @@
 static PgVideoModes_t mode_list;
 
 /* The current list of available video modes */
-SDL_Rect  SDL_modelist[PH_MAX_VIDEOMODES];
-SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES];
+SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES];
+SDL_Rect *SDL_modearray[PH_MAX_VIDEOMODES];
 
-static int compare_modes_by_res(const void* mode1, const void* mode2)
+static int
+compare_modes_by_res (const void *mode1, const void *mode2)
 {
     PgVideoModeInfo_t mode1_info;
     PgVideoModeInfo_t mode2_info;
 
-    if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode1_info) < 0)
-    {
+    if (PgGetVideoModeInfo (*(unsigned short *) mode1, &mode1_info) < 0) {
         return 0;
     }
 
-    if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode2_info) < 0)
-    {
+    if (PgGetVideoModeInfo (*(unsigned short *) mode2, &mode2_info) < 0) {
         return 0;
     }
 
-    if (mode1_info.width == mode2_info.width)
-    {
+    if (mode1_info.width == mode2_info.width) {
         return mode2_info.height - mode1_info.height;
-    }
-    else
-    {
+    } else {
         return mode2_info.width - mode1_info.width;
     }
 }
 
-SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
+SDL_Rect **
+ph_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
 {
     int i = 0;
     int j = 0;
     SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
 
-    for (i=0; i<PH_MAX_VIDEOMODES; i++)
-    {
-        SDL_modearray[i]=&SDL_modelist[i];
+    for (i = 0; i < PH_MAX_VIDEOMODES; i++) {
+        SDL_modearray[i] = &SDL_modelist[i];
     }
 
-    if (PgGetVideoModeList(&mode_list) < 0)
-    {
-       SDL_SetError("ph_ListModes(): PgGetVideoModeList() function failed !\n");
-       return NULL;
+    if (PgGetVideoModeList (&mode_list) < 0) {
+        SDL_SetError
+            ("ph_ListModes(): PgGetVideoModeList() function failed !\n");
+        return NULL;
     }
 
     mode_info.bits_per_pixel = 0;
 
-    for (i=0; i < mode_list.num_modes; i++) 
-    {
-        if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
-        {
-            SDL_SetError("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", mode_list.modes[i]);
+    for (i = 0; i < mode_list.num_modes; i++) {
+        if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) {
+            SDL_SetError
+                ("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n",
+                 mode_list.modes[i]);
             return NULL;
         }
-        if(mode_info.bits_per_pixel == format->BitsPerPixel)
-        {
+        if (mode_info.bits_per_pixel == format->BitsPerPixel) {
             Amodelist[j].w = mode_info.width;
             Amodelist[j].h = mode_info.height;
             Amodelist[j].x = 0;
             Amodelist[j].y = 0;
-            j++;	
+            j++;
         }
     }
-	
+
     /* reorder biggest for smallest, assume width dominates */
 
-    for(i=0; i<j; i++)
-    {
+    for (i = 0; i < j; i++) {
         SDL_modelist[i].w = Amodelist[j - i - 1].w;
         SDL_modelist[i].h = Amodelist[j - i - 1].h;
         SDL_modelist[i].x = Amodelist[j - i - 1].x;
         SDL_modelist[i].y = Amodelist[j - i - 1].y;
     }
-    SDL_modearray[j]=NULL;
-	
+    SDL_modearray[j] = NULL;
+
     return SDL_modearray;
 }
 
-void ph_FreeVideoModes(_THIS)
+void
+ph_FreeVideoModes (_THIS)
 {
-   return;
+    return;
 }
 
 /* return the mode associated with width, height and bpp */
 /* if there is no mode then zero is returned             */
-int ph_GetVideoMode(int width, int height, int bpp)
+int
+ph_GetVideoMode (int width, int height, int bpp)
 {
     int i;
-    int modestage=0;
-    int closestmode=0;
+    int modestage = 0;
+    int closestmode = 0;
 
-    if (PgGetVideoModeList(&mode_list) < 0)
-    {
+    if (PgGetVideoModeList (&mode_list) < 0) {
         return -1;
     }
 
     /* special case for the double-sized 320x200 mode */
-    if ((width==640) && (height==400))
-    {
-       modestage=1;
+    if ((width == 640) && (height == 400)) {
+        modestage = 1;
     }
 
     /* search list for exact match */
-    for (i=0; i<mode_list.num_modes; i++)
-    {
-        if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
-        {
+    for (i = 0; i < mode_list.num_modes; i++) {
+        if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) {
             return 0;
         }
 
-        if ((mode_info.width == width) && (mode_info.height == height) && 
-            (mode_info.bits_per_pixel == bpp))
-        {
+        if ((mode_info.width == width) && (mode_info.height == height) &&
+            (mode_info.bits_per_pixel == bpp)) {
             return mode_list.modes[i];
-        }
-        else
-        {
-           if ((modestage) && (mode_info.width == width) && (mode_info.height == height+80) && 
-               (mode_info.bits_per_pixel == bpp))
-           {
-              modestage=2;
-              closestmode=mode_list.modes[i];
-           }
+        } else {
+            if ((modestage) && (mode_info.width == width)
+                && (mode_info.height == height + 80)
+                && (mode_info.bits_per_pixel == bpp)) {
+                modestage = 2;
+                closestmode = mode_list.modes[i];
+            }
         }
     }
 
     /* if we are here, then no 640x400xbpp mode found and we'll emulate it via 640x480xbpp mode */
-    if (modestage==2)
-    {
-       return closestmode;
+    if (modestage == 2) {
+        return closestmode;
     }
 
     return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
@@ -164,63 +152,51 @@
 
 /* return the mode associated with width, height and bpp               */
 /* if requested bpp is not found the mode with closest bpp is returned */
-int get_mode_any_format(int width, int height, int bpp)
+int
+get_mode_any_format (int width, int height, int bpp)
 {
     int i, closest, delta, min_delta;
 
-    if (PgGetVideoModeList(&mode_list) < 0)
-    {
+    if (PgGetVideoModeList (&mode_list) < 0) {
         return -1;
     }
 
-    SDL_qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
+    SDL_qsort (mode_list.modes, mode_list.num_modes, sizeof (unsigned short),
+               compare_modes_by_res);
 
-    for(i=0;i<mode_list.num_modes;i++)
-    {
-        if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
-        {
+    for (i = 0; i < mode_list.num_modes; i++) {
+        if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) {
             return 0;
         }
-        if ((mode_info.width == width) && (mode_info.height == height))
-        {
-           break;
+        if ((mode_info.width == width) && (mode_info.height == height)) {
+            break;
         }
     }
 
-    if (i<mode_list.num_modes)
-    {
+    if (i < mode_list.num_modes) {
         /* get closest bpp */
         closest = i++;
-        if (mode_info.bits_per_pixel == bpp)
-        {
+        if (mode_info.bits_per_pixel == bpp) {
             return mode_list.modes[closest];
         }
 
-        min_delta = abs(mode_info.bits_per_pixel - bpp);
+        min_delta = abs (mode_info.bits_per_pixel - bpp);
 
-        while(1)
-        {
-            if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
-            {
+        while (1) {
+            if (PgGetVideoModeInfo (mode_list.modes[i], &mode_info) < 0) {
                 return 0;
             }
 
-            if ((mode_info.width != width) || (mode_info.height != height))
-            {
+            if ((mode_info.width != width)
+                || (mode_info.height != height)) {
                 break;
-            }
-            else
-            {
-                if (mode_info.bits_per_pixel == bpp)
-                {
+            } else {
+                if (mode_info.bits_per_pixel == bpp) {
                     closest = i;
                     break;
-                }
-                else
-                {
-                    delta = abs(mode_info.bits_per_pixel - bpp);
-                    if (delta < min_delta)
-                    {
+                } else {
+                    delta = abs (mode_info.bits_per_pixel - bpp);
+                    if (delta < min_delta) {
                         closest = i;
                         min_delta = delta;
                     }
@@ -234,119 +210,111 @@
     return 0;
 }
 
-int ph_ToggleFullScreen(_THIS, int on)
+int
+ph_ToggleFullScreen (_THIS, int on)
 {
     return -1;
 }
 
-int ph_EnterFullScreen(_THIS, SDL_Surface* screen, int fmode)
+int
+ph_EnterFullScreen (_THIS, SDL_Surface * screen, int fmode)
 {
     PgDisplaySettings_t settings;
     int mode;
-    char* refreshrate;
+    char *refreshrate;
     int refreshratenum;
 
-    if (!currently_fullscreen)
-    {
+    if (!currently_fullscreen) {
         /* Get the video mode and set it */
-        if (screen->flags & SDL_ANYFORMAT)
-        {
-            if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
-            {
-                SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
+        if (screen->flags & SDL_ANYFORMAT) {
+            if ((mode =
+                 get_mode_any_format (screen->w, screen->h,
+                                      screen->format->BitsPerPixel)) == 0) {
+                SDL_SetError
+                    ("ph_EnterFullScreen(): can't find appropriate video mode !\n");
                 return 0;
             }
-        }
-        else
-        {
-            if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
-            {
-                SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
+        } else {
+            if ((mode =
+                 ph_GetVideoMode (screen->w, screen->h,
+                                  screen->format->BitsPerPixel)) == 0) {
+                SDL_SetError
+                    ("ph_EnterFullScreen(): can't find appropriate video mode !\n");
                 return 0;
             }
-            if (PgGetVideoModeInfo(mode, &mode_info) < 0)
-            {
-                SDL_SetError("ph_EnterFullScreen(): can't get video mode capabilities !\n");
+            if (PgGetVideoModeInfo (mode, &mode_info) < 0) {
+                SDL_SetError
+                    ("ph_EnterFullScreen(): can't get video mode capabilities !\n");
                 return 0;
             }
-            if (mode_info.height != screen->h)
-            {
-               if ((mode_info.height==480) && (screen->h==400))
-               {
-                  videomode_emulatemode=1;
-               }
-            }
-            else
-            {
-               videomode_emulatemode=0;
+            if (mode_info.height != screen->h) {
+                if ((mode_info.height == 480) && (screen->h == 400)) {
+                    videomode_emulatemode = 1;
+                }
+            } else {
+                videomode_emulatemode = 0;
             }
         }
 
         /* save old video mode caps */
-        PgGetVideoMode(&settings);
-        old_video_mode=settings.mode;
-        old_refresh_rate=settings.refresh;
+        PgGetVideoMode (&settings);
+        old_video_mode = settings.mode;
+        old_refresh_rate = settings.refresh;
 
         /* setup new video mode */
         settings.mode = mode;
         settings.refresh = 0;
         settings.flags = 0;
 
-        refreshrate=SDL_getenv("SDL_PHOTON_FULLSCREEN_REFRESH");
-        if (refreshrate!=NULL)
-        {
-           if (SDL_sscanf(refreshrate, "%d", &refreshratenum)==1)
-           {
-               settings.refresh = refreshratenum;
-           }
+        refreshrate = SDL_getenv ("SDL_PHOTON_FULLSCREEN_REFRESH");
+        if (refreshrate != NULL) {
+            if (SDL_sscanf (refreshrate, "%d", &refreshratenum) == 1) {
+                settings.refresh = refreshratenum;
+            }
         }
 
-        if (PgSetVideoMode(&settings) < 0)
-        {
-            SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
+        if (PgSetVideoMode (&settings) < 0) {
+            SDL_SetError
+                ("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
             return 0;
         }
 
-        if (this->screen)
-        {
-            if (this->screen->flags & SDL_INTERNALOPENGL)
-            {
+        if (this->screen) {
+            if (this->screen->flags & SDL_INTERNALOPENGL) {
 #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
-                return 0; /* 6.3.0 */
+                return 0;       /* 6.3.0 */
 #endif
             }
         }
 
-        if (fmode==0)
-        {
-            if (OCImage.direct_context==NULL)
-            {
-                OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
-                if (!OCImage.direct_context)
-                {
-                    SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
-                    ph_LeaveFullScreen(this);
+        if (fmode == 0) {
+            if (OCImage.direct_context == NULL) {
+                OCImage.direct_context =
+                    (PdDirectContext_t *) PdCreateDirectContext ();
+                if (!OCImage.direct_context) {
+                    SDL_SetError
+                        ("ph_EnterFullScreen(): Can't create direct context !\n");
+                    ph_LeaveFullScreen (this);
                     return 0;
                 }
             }
-            OCImage.oldDC=PdDirectStart(OCImage.direct_context);
+            OCImage.oldDC = PdDirectStart (OCImage.direct_context);
         }
 
         currently_fullscreen = 1;
     }
-    PgFlush();
+    PgFlush ();
 
     return 1;
 }
 
-int ph_LeaveFullScreen(_THIS)
+int
+ph_LeaveFullScreen (_THIS)
 {
     PgDisplaySettings_t oldmode_settings;
-       
-    if (currently_fullscreen)
-    {
-        if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL))
-        {
+
+    if (currently_fullscreen) {
+        if ((this->screen) && (this->screen->flags & SDL_INTERNALOPENGL)) {
 #if !SDL_VIDEO_OPENGL || (_NTO_VERSION < 630)
             return 0;
 #endif
@@ -354,37 +322,36 @@
 
         /* release routines starts here */
         {
-            if (OCImage.direct_context)
-            {
-                PdDirectStop(OCImage.direct_context);
-                PdReleaseDirectContext(OCImage.direct_context);
-                OCImage.direct_context=NULL;
+            if (OCImage.direct_context) {
+                PdDirectStop (OCImage.direct_context);
+                PdReleaseDirectContext (OCImage.direct_context);
+                OCImage.direct_context = NULL;
             }
-            if (OCImage.oldDC)
-            {
-                PhDCSetCurrent(OCImage.oldDC);
-                OCImage.oldDC=NULL;
+            if (OCImage.oldDC) {
+                PhDCSetCurrent (OCImage.oldDC);
+                OCImage.oldDC = NULL;
             }
 
-            currently_fullscreen=0;
+            currently_fullscreen = 0;
 
             /* Restore old video mode */
-            if (old_video_mode != -1)
-            {
+            if (old_video_mode != -1) {
                 oldmode_settings.mode = (unsigned short) old_video_mode;
                 oldmode_settings.refresh = (unsigned short) old_refresh_rate;
                 oldmode_settings.flags = 0;
-                
-                if (PgSetVideoMode(&oldmode_settings) < 0)
-                {
-                    SDL_SetError("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n");
+
+                if (PgSetVideoMode (&oldmode_settings) < 0) {
+                    SDL_SetError
+                        ("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n");
                     return 0;
                 }
             }
 
-            old_video_mode=-1;
-            old_refresh_rate=-1;
+            old_video_mode = -1;
+            old_refresh_rate = -1;
         }
     }
     return 1;
 }
+
+/* vi: set ts=4 sw=4 expandtab: */