changeset 2874:36e312e0fac0

indent
author Sam Lantinga <slouken@libsdl.org>
date Tue, 16 Dec 2008 17:44:10 +0000
parents b33e38aaa027
children 91a7e08cd238
files src/video/x11/SDL_x11modes.c src/video/x11/SDL_x11modes.h src/video/x11/SDL_x11render.c
diffstat 3 files changed, 107 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11modes.c	Tue Dec 16 17:41:03 2008 +0000
+++ b/src/video/x11/SDL_x11modes.c	Tue Dec 16 17:44:10 2008 +0000
@@ -62,7 +62,7 @@
 }
 
 static Uint32
-X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo)
+X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
 {
     if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
         int bpp;
@@ -162,7 +162,7 @@
 
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
 static SDL_bool
-CheckXinerama(Display *display, int *major, int *minor)
+CheckXinerama(Display * display, int *major, int *minor)
 {
     const char *env;
 
@@ -176,8 +176,8 @@
     }
 
     /* Query the extension version */
-    if (!SDL_NAME(XineramaQueryExtension)(display, major, minor) ||
-        !SDL_NAME(XineramaIsActive)(display)) {
+    if (!SDL_NAME(XineramaQueryExtension) (display, major, minor) ||
+        !SDL_NAME(XineramaIsActive) (display)) {
         return SDL_FALSE;
     }
     return SDL_TRUE;
@@ -186,7 +186,7 @@
 
 #if SDL_VIDEO_DRIVER_X11_XRANDR
 static SDL_bool
-CheckXRandR(Display *display, int *major, int *minor)
+CheckXRandR(Display * display, int *major, int *minor)
 {
     const char *env;
 
@@ -213,7 +213,7 @@
 
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
 static SDL_bool
-CheckVidMode(Display *display, int *major, int *minor)
+CheckVidMode(Display * display, int *major, int *minor)
 {
     const char *env;
 
@@ -225,24 +225,25 @@
     if (env && !SDL_atoi(env)) {
         return SDL_FALSE;
     }
-    
+
     /* Query the extension version */
     vm_error = -1;
-    if (!SDL_NAME(XF86VidModeQueryExtension)(display, &vm_event, &vm_error) ||
-        !SDL_NAME(XF86VidModeQueryVersion)(display, major, minor)) {
+    if (!SDL_NAME(XF86VidModeQueryExtension) (display, &vm_event, &vm_error)
+        || !SDL_NAME(XF86VidModeQueryVersion) (display, major, minor)) {
         return SDL_FALSE;
     }
     return SDL_TRUE;
 }
 
-Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
+Bool SDL_NAME(XF86VidModeGetModeInfo) (Display * dpy, int scr,
+                                       SDL_NAME(XF86VidModeModeInfo) * info)
 {
     Bool retval;
     int dotclock;
     SDL_NAME(XF86VidModeModeLine) l;
     SDL_zerop(info);
     SDL_zero(l);
-    retval = SDL_NAME(XF86VidModeGetModeLine)(dpy, scr, &dotclock, &l);
+    retval = SDL_NAME(XF86VidModeGetModeLine) (dpy, scr, &dotclock, &l);
     info->dotclock = dotclock;
     info->hdisplay = l.hdisplay;
     info->hsyncstart = l.hsyncstart;
@@ -260,30 +261,38 @@
 }
 
 static int
-calculate_rate(SDL_NAME(XF86VidModeModeInfo) *info)
+calculate_rate(SDL_NAME(XF86VidModeModeInfo) * info)
 {
-    return (info->htotal && info->vtotal) ? (1000 * info->dotclock / (info->htotal * info->vtotal)) : 0;
+    return (info->htotal
+            && info->vtotal) ? (1000 * info->dotclock / (info->htotal *
+                                                         info->vtotal)) : 0;
 }
 
 static void
-save_mode(Display *display, SDL_DisplayData *data)
+save_mode(Display * display, SDL_DisplayData * data)
 {
-    SDL_NAME(XF86VidModeGetModeInfo)(display, data->screen, &data->saved_mode);
-    SDL_NAME(XF86VidModeGetViewPort)(display, data->screen, &data->saved_view.x,&data->saved_view.y);
+    SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen,
+                                      &data->saved_mode);
+    SDL_NAME(XF86VidModeGetViewPort) (display, data->screen,
+                                      &data->saved_view.x,
+                                      &data->saved_view.y);
 }
 
 static void
-restore_mode(Display *display, SDL_DisplayData *data)
+restore_mode(Display * display, SDL_DisplayData * data)
 {
     SDL_NAME(XF86VidModeModeInfo) mode;
 
-    if (SDL_NAME(XF86VidModeGetModeInfo)(display, data->screen, &mode)) {
+    if (SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, &mode)) {
         if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) {
-            SDL_NAME(XF86VidModeSwitchToMode)(display, data->screen, &data->saved_mode);
+            SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen,
+                                               &data->saved_mode);
         }
     }
     if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) {
-        SDL_NAME(XF86VidModeSetViewPort)(display, data->screen, data->saved_view.x, data->saved_view.y);
+        SDL_NAME(XF86VidModeSetViewPort) (display, data->screen,
+                                          data->saved_view.x,
+                                          data->saved_view.y);
     }
 }
 #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
@@ -296,7 +305,7 @@
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
     int xinerama_major, xinerama_minor;
     int screens;
-    SDL_NAME(XineramaScreenInfo) *xinerama;
+    SDL_NAME(XineramaScreenInfo) * xinerama;
 #endif
 #if SDL_VIDEO_DRIVER_X11_XRANDR
     int xrandr_major, xrandr_minor;
@@ -307,7 +316,7 @@
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
     int vm_major, vm_minor;
     int nmodes;
-    SDL_NAME(XF86VidModeModeInfo) **modes;
+    SDL_NAME(XF86VidModeModeInfo) ** modes;
 #endif
     int screen_w;
     int screen_h;
@@ -334,18 +343,19 @@
 #ifdef X11MODES_DEBUG
         printf("X11 detected Xinerama:\n");
 #endif
-        xinerama = SDL_NAME(XineramaQueryScreens)(display, &screens);
+        xinerama = SDL_NAME(XineramaQueryScreens) (display, &screens);
         if (xinerama) {
             int i;
             for (i = 0; i < screens; i++) {
 #ifdef X11MODES_DEBUG
                 printf("xinerama %d: %dx%d+%d+%d\n",
-                    xinerama[i].screen_number,
-                    xinerama[i].width, xinerama[i].height,
-                    xinerama[i].x_org, xinerama[i].y_org);
+                       xinerama[i].screen_number,
+                       xinerama[i].width, xinerama[i].height,
+                       xinerama[i].x_org, xinerama[i].y_org);
 #endif
                 if (xinerama[i].screen_number == data->screen) {
-                    data->use_xinerama = xinerama_major * 100 + xinerama_minor;
+                    data->use_xinerama =
+                        xinerama_major * 100 + xinerama_minor;
                     data->xinerama_info = xinerama[i];
                 }
             }
@@ -374,7 +384,8 @@
 #if SDL_VIDEO_DRIVER_X11_XRANDR
     /* XRandR */
     /* require at least XRandR v1.0 (arbitrary) */
-    if (CheckXRandR(display, &xrandr_major, &xrandr_minor) && xrandr_major >= 1) {
+    if (CheckXRandR(display, &xrandr_major, &xrandr_minor)
+        && xrandr_major >= 1) {
 #ifdef X11MODES_DEBUG
         fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
                 xrandr_major, xrandr_minor);
@@ -382,14 +393,15 @@
 
         /* save the screen configuration since we must reference it
            each time we toggle modes.
-        */
-        data->screen_config = XRRGetScreenInfo(display, RootWindow(display, data->screen));
+         */
+        data->screen_config =
+            XRRGetScreenInfo(display, RootWindow(display, data->screen));
 
         /* retrieve the list of resolution */
         sizes = XRRConfigSizes(data->screen_config, &nsizes);
         if (nsizes > 0) {
             int i, j;
-            for ( i=0; i < nsizes; i++) {
+            for (i = 0; i < nsizes; i++) {
                 mode.w = sizes[i].width;
                 mode.h = sizes[i].height;
 
@@ -397,7 +409,8 @@
                 for (j = 0; j < nrates; ++j) {
                     mode.refresh_rate = rates[j];
 #ifdef X11MODES_DEBUG
-                    fprintf(stderr, "XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n",
+                    fprintf(stderr,
+                            "XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n",
                             i, j, mode.w, mode.h, mode.refresh_rate);
 #endif
                     SDL_AddDisplayMode(_this->current_display, &mode);
@@ -405,7 +418,9 @@
             }
 
             data->use_xrandr = xrandr_major * 100 + xrandr_minor;
-            data->saved_size = XRRConfigCurrentConfiguration(data->screen_config, &data->saved_rotation);
+            data->saved_size =
+                XRRConfigCurrentConfiguration(data->screen_config,
+                                              &data->saved_rotation);
             data->saved_rate = XRRConfigCurrentRate(data->screen_config);
         }
     }
@@ -418,16 +433,16 @@
         (!data->use_xinerama || data->xinerama_info.screen_number == 0) &&
 #endif
         CheckVidMode(display, &vm_major, &vm_minor) &&
-        SDL_NAME(XF86VidModeGetAllModeLines)(display, data->screen, &nmodes, &modes) )
-    {
+        SDL_NAME(XF86VidModeGetAllModeLines) (display, data->screen, &nmodes,
+                                              &modes)) {
         int i;
 
 #ifdef X11MODES_DEBUG
         printf("VidMode modes: (unsorted)\n");
         for (i = 0; i < nmodes; ++i) {
             printf("Mode %d: %d x %d @ %d\n", i,
-                    modes[i]->hdisplay, modes[i]->vdisplay,
-                    calculate_rate(modes[i]));
+                   modes[i]->hdisplay, modes[i]->vdisplay,
+                   calculate_rate(modes[i]));
         }
 #endif
         for (i = 0; i < nmodes; ++i) {
@@ -448,8 +463,7 @@
         mode.h = screen_h;
         mode.refresh_rate = 0;
         SDL_AddDisplayMode(_this->current_display, &mode);
-    } 
-
+    }
 #ifdef X11MODES_DEBUG
     if (data->use_xinerama) {
         printf("Xinerama is enabled\n");
@@ -466,24 +480,29 @@
 }
 
 static void
-get_real_resolution(Display *display, SDL_DisplayData *data, int *w, int *h, int *rate)
+get_real_resolution(Display * display, SDL_DisplayData * data, int *w, int *h,
+                    int *rate)
 {
 #if SDL_VIDEO_DRIVER_X11_XRANDR
     if (data->use_xrandr) {
         int nsizes;
         XRRScreenSize *sizes;
-        
+
         sizes = XRRConfigSizes(data->screen_config, &nsizes);
         if (nsizes > 0) {
             int cur_size;
             Rotation cur_rotation;
 
-            cur_size = XRRConfigCurrentConfiguration(data->screen_config, &cur_rotation);
+            cur_size =
+                XRRConfigCurrentConfiguration(data->screen_config,
+                                              &cur_rotation);
             *w = sizes[cur_size].width;
             *h = sizes[cur_size].height;
             *rate = XRRConfigCurrentRate(data->screen_config);
 #ifdef X11MODES_DEBUG
-            fprintf(stderr, "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n", *w, *h, *rate);
+            fprintf(stderr,
+                    "XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n",
+                    *w, *h, *rate);
 #endif
             return;
         }
@@ -494,7 +513,7 @@
     if (data->use_vidmode) {
         SDL_NAME(XF86VidModeModeInfo) mode;
 
-        if (SDL_NAME(XF86VidModeGetModeInfo)(display, data->screen, &mode)) {
+        if (SDL_NAME(XF86VidModeGetModeInfo) (display, data->screen, &mode)) {
             *w = mode.hdisplay;
             *h = mode.vdisplay;
             *rate = calculate_rate(&mode);
@@ -518,7 +537,8 @@
 }
 
 static void
-set_best_resolution(Display *display, SDL_DisplayData *data, int w, int h, int rate)
+set_best_resolution(Display * display, SDL_DisplayData * data, int w, int h,
+                    int rate)
 {
     int real_w, real_h, real_rate;
 
@@ -527,7 +547,6 @@
     if (w == real_w && h == real_h && (!rate || rate == real_rate)) {
         return;
     }
-
 #if SDL_VIDEO_DRIVER_X11_XRANDR
     if (data->use_xrandr) {
 #ifdef X11MODES_DEBUG
@@ -553,7 +572,8 @@
             }
             if (best == -1 ||
                 (sizes[i].width < sizes[best].width) ||
-                (sizes[i].width == sizes[best].width && sizes[i].height < sizes[best].height)) {
+                (sizes[i].width == sizes[best].width
+                 && sizes[i].height < sizes[best].height)) {
                 best = i;
             }
         }
@@ -572,12 +592,15 @@
                         best_rate = rates[i];
                     }
                 } else {
-                    if (SDL_abs(rates[i]-rate) < SDL_abs(best_rate-rate)) {
+                    if (SDL_abs(rates[i] - rate) < SDL_abs(best_rate - rate)) {
                         best_rate = rates[i];
                     }
                 }
             }
-            XRRSetScreenConfigAndRate(display, data->screen_config, RootWindow(display, data->screen), best, data->saved_rotation, best_rate, CurrentTime);
+            XRRSetScreenConfigAndRate(display, data->screen_config,
+                                      RootWindow(display, data->screen), best,
+                                      data->saved_rotation, best_rate,
+                                      CurrentTime);
         }
         return;
     }
@@ -585,11 +608,12 @@
 
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
     if (data->use_vidmode) {
-        SDL_NAME(XF86VidModeModeInfo) **modes;
+        SDL_NAME(XF86VidModeModeInfo) ** modes;
         int i, nmodes;
         int best;
 
-        if (SDL_NAME(XF86VidModeGetAllModeLines)(display,data->screen,&nmodes,&modes)) {
+        if (SDL_NAME(XF86VidModeGetAllModeLines)
+            (display, data->screen, &nmodes, &modes)) {
             best = -1;
             for (i = 0; i < nmodes; ++i) {
                 if (modes[i]->hdisplay < w || modes[i]->vdisplay < h) {
@@ -597,7 +621,8 @@
                 }
                 if (best == -1 ||
                     (modes[i]->hdisplay < modes[best]->hdisplay) ||
-                    (modes[i]->hdisplay == modes[best]->hdisplay && modes[i]->vdisplay < modes[best]->vdisplay)) {
+                    (modes[i]->hdisplay == modes[best]->hdisplay
+                     && modes[i]->vdisplay < modes[best]->vdisplay)) {
                     best = i;
                     continue;
                 }
@@ -605,11 +630,13 @@
                     (modes[i]->vdisplay == modes[best]->vdisplay)) {
                     if (!rate) {
                         /* Higher is better, right? */
-                        if (calculate_rate(modes[i]) > calculate_rate(modes[best])) {
+                        if (calculate_rate(modes[i]) >
+                            calculate_rate(modes[best])) {
                             best = i;
                         }
                     } else {
-                        if (SDL_abs(calculate_rate(modes[i])-rate) < SDL_abs(calculate_rate(modes[best])-rate)) {
+                        if (SDL_abs(calculate_rate(modes[i]) - rate) <
+                            SDL_abs(calculate_rate(modes[best]) - rate)) {
                             best = i;
                         }
                     }
@@ -618,10 +645,11 @@
             if (best >= 0) {
 #ifdef X11MODES_DEBUG
                 printf("Best Mode %d: %d x %d @ %d\n", best,
-                        modes[best]->hdisplay, modes[best]->vdisplay,
-                        calculate_rate(modes[best]));
+                       modes[best]->hdisplay, modes[best]->vdisplay,
+                       calculate_rate(modes[best]));
 #endif
-                SDL_NAME(XF86VidModeSwitchToMode)(display, data->screen, modes[best]);
+                SDL_NAME(XF86VidModeSwitchToMode) (display, data->screen,
+                                                   modes[best]);
             }
             XFree(modes);
         }
--- a/src/video/x11/SDL_x11modes.h	Tue Dec 16 17:41:03 2008 +0000
+++ b/src/video/x11/SDL_x11modes.h	Tue Dec 16 17:44:10 2008 +0000
@@ -35,7 +35,7 @@
     int use_vidmode;
 
 #if SDL_VIDEO_DRIVER_X11_XINERAMA
-    SDL_NAME(XineramaScreenInfo) xinerama_info;
+      SDL_NAME(XineramaScreenInfo) xinerama_info;
 #endif
 #if SDL_VIDEO_DRIVER_X11_XRANDR
     XRRScreenConfiguration *screen_config;
@@ -44,8 +44,9 @@
     short saved_rate;
 #endif
 #if SDL_VIDEO_DRIVER_X11_VIDMODE
-    SDL_NAME(XF86VidModeModeInfo) saved_mode;
-    struct {
+      SDL_NAME(XF86VidModeModeInfo) saved_mode;
+    struct
+    {
         int x, y;
     } saved_view;
 #endif
--- a/src/video/x11/SDL_x11render.c	Tue Dec 16 17:41:03 2008 +0000
+++ b/src/video/x11/SDL_x11render.c	Tue Dec 16 17:44:10 2008 +0000
@@ -236,7 +236,9 @@
     data->current_pixmap = 0;
 
     /* Get the format of the window */
-    if (!SDL_PixelFormatEnumToMasks(display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
+    if (!SDL_PixelFormatEnumToMasks
+        (display->current_mode.format, &bpp, &Rmask, &Gmask, &Bmask,
+         &Amask)) {
         SDL_SetError("Unknown display format");
         X11_DestroyRenderer(renderer);
         return NULL;
@@ -325,7 +327,7 @@
     } else {
         /* The image/pixmap depth must be the same as the window or you
            get a BadMatch error when trying to putimage or copyarea.
-        */
+         */
         if (texture->format != display->current_mode.format) {
             SDL_SetError("Texture format doesn't match window format");
             return -1;
@@ -364,7 +366,9 @@
             data->pixels = shminfo->shmaddr;
 
             data->image =
-                XShmCreateImage(renderdata->display, renderdata->visual, renderdata->depth, ZPixmap, shminfo->shmaddr, shminfo, texture->w, texture->h);
+                XShmCreateImage(renderdata->display, renderdata->visual,
+                                renderdata->depth, ZPixmap, shminfo->shmaddr,
+                                shminfo, texture->w, texture->h);
             if (!data->image) {
                 XShmDetach(renderdata->display, shminfo);
                 XSync(renderdata->display, False);
@@ -386,7 +390,11 @@
             }
 
             data->image =
-                XCreateImage(renderdata->display, renderdata->visual, renderdata->depth, ZPixmap, 0, data->pixels, texture->w, texture->h, SDL_BYTESPERPIXEL(data->format) * 8, data->pitch);
+                XCreateImage(renderdata->display, renderdata->visual,
+                             renderdata->depth, ZPixmap, 0, data->pixels,
+                             texture->w, texture->h,
+                             SDL_BYTESPERPIXEL(data->format) * 8,
+                             data->pitch);
             if (!data->image) {
                 X11_DestroyTexture(renderer, texture);
                 SDL_SetError("XCreateImage() failed");
@@ -404,7 +412,10 @@
         }
 
         data->image =
-            XCreateImage(renderdata->display, renderdata->visual, renderdata->depth, ZPixmap, 0, NULL, texture->w, texture->h, SDL_BYTESPERPIXEL(data->format) * 8, data->pitch);
+            XCreateImage(renderdata->display, renderdata->visual,
+                         renderdata->depth, ZPixmap, 0, NULL, texture->w,
+                         texture->h, SDL_BYTESPERPIXEL(data->format) * 8,
+                         data->pitch);
         if (!data->image) {
             X11_DestroyTexture(renderer, texture);
             SDL_SetError("XCreateImage() failed");
@@ -606,8 +617,8 @@
             }
 
             image =
-                XCreateImage(data->display, data->visual, data->depth, ZPixmap,
-                             0, pixels, dstrect->w, dstrect->h,
+                XCreateImage(data->display, data->visual, data->depth,
+                             ZPixmap, 0, pixels, dstrect->w, dstrect->h,
                              SDL_BYTESPERPIXEL(texturedata->format) * 8,
                              pitch);
             if (!image) {