X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fswirl.c;h=ae72820c6f9252dc2b8ce1f55d53875898df931d;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=7f3764f02a75f9b5de626cf7186e7ca6fdf407c5;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0;p=xscreensaver diff --git a/hacks/swirl.c b/hacks/swirl.c index 7f3764f0..ae72820c 100644 --- a/hacks/swirl.c +++ b/hacks/swirl.c @@ -1,7 +1,7 @@ /* -*- Mode: C; tab-width: 4 -*- * swirl --- swirly color-cycling patterns. */ -#if !defined( lint ) && !defined( SABER ) +#if 0 static const char sccsid[] = "@(#)swirl.c 4.00 97/01/01 xlockmore"; #endif @@ -19,33 +19,39 @@ static const char sccsid[] = "@(#)swirl.c 4.00 97/01/01 xlockmore"; * event will the author be liable for any lost revenue or profits or * other special, indirect and consequential damages. * - * 13-May-97: jwz@netscape.com: turned into a standalone program. - * 21-Apr-95: improved startup time for TrueColour displays - * (limited to 16bpp to save memory) S.Early - * 09-Jan-95: fixed colour maps (more colourful) and the image now spirals - * outwards from the centre with a fixed number of points drawn - * every iteration. Thanks to M.Dobie . - * 1994: written. Copyright (c) 1994 M.Dobie - * based on original code by R.Taylor + * 09-Oct-2016: dmo2118@gmail.com: Updated for new xshm.c. + * 13-May-1997: jwz@jwz.org: turned into a standalone program. + * 21-Apr-1995: improved startup time for TrueColour displays + * (limited to 16bpp to save memory) S.Early + * 09-Jan-1995: fixed colour maps (more colourful) and the image now spirals + * outwards from the centre with a fixed number of points drawn + * every iteration. Thanks to M.Dobie . + * 1994: written. Copyright (c) 1994 M.Dobie + * based on original code by R.Taylor */ #ifdef STANDALONE -# define PROGCLASS "Swirl" -# define HACK_INIT init_swirl -# define HACK_DRAW draw_swirl -# define swirl_opts xlockmore_opts # define DEFAULTS "*count: 5 \n" \ "*delay: 10000 \n" \ - "*ncolors: 200 \n" + "*ncolors: 200 \n" \ + "*useSHM: True \n" \ + "*fpsSolid: true \n" \ + "*ignoreRotation: True \n" \ + ".lowrez: True \n" \ + # define SMOOTH_COLORS # define WRITABLE_COLORS +# define release_swirl 0 +# define reshape_swirl 0 +# define swirl_handle_event 0 # include "xlockmore.h" /* from the xscreensaver distribution */ -# include +# include "xshm.h" #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ +# undef HAVE_XSHM_EXTENSION #endif /* !STANDALONE */ -ModeSpecOpt swirl_opts = { +ENTRYPOINT ModeSpecOpt swirl_opts = { 0, NULL, 0, NULL, NULL }; #include @@ -121,6 +127,7 @@ typedef struct swirl_data { /* image stuff */ unsigned char *image; /* image data */ XImage *ximage; + XShmSegmentInfo shm_info; /* colours stuff */ int colours; /* how many colours possible */ @@ -219,9 +226,7 @@ initialise_swirl(ModeInfo * mi, SWIRL_P swirl) #endif /* !STANDALONE */ -#ifdef STANDALONE -# define MI_COLORMAP MI_WIN_COLORMAP -#else /* !STANDALONE */ +#ifndef STANDALONE swirl->fg = MI_FG_COLOR(mi); swirl->bg = MI_BG_COLOR(mi); swirl->fgcol.pixel = swirl->fg; @@ -241,37 +246,16 @@ initialise_swirl(ModeInfo * mi, SWIRL_P swirl) * - swirl is the swirl data */ static void -initialise_image(Display * dpy, SWIRL_P swirl) +initialise_image(ModeInfo * mi, SWIRL_P swirl) { - unsigned int pad; - int bytes_per_line; - int image_depth = swirl->rdepth; - int data_depth = image_depth; - - /* On SGIs at least, using an XImage of depth 24 on a Visual of depth 24 - requires the XImage data to use 32 bits per pixel. I don't understand - how one is supposed to determine this -- maybe XListPixmapFormats? - But on systems that don't work this way, allocating 32 bpp instead of - 24 will be wasteful but non-fatal. -- jwz, 16-May-97. */ - if (data_depth >= 24 && data_depth < 32) - data_depth = 32; - - /* get the bitmap pad */ - pad = BitmapPad(dpy); - /* destroy the old image (destroy XImage and data) */ - if (swirl->ximage != NULL) - XDestroyImage(swirl->ximage); + Display *dpy = MI_DISPLAY(mi); - /* how many bytes per line? (bits rounded up to pad) */ - bytes_per_line = ((swirl->width * data_depth + pad - 1) / pad) * (pad / 8); + if (swirl->ximage != NULL) + destroy_xshm_image(dpy, swirl->ximage, &swirl->shm_info); - /* allocate space for the image */ - swirl->image = (unsigned char *) calloc(bytes_per_line * swirl->height, 1); - - /* create an ximage with this */ - swirl->ximage = XCreateImage(dpy, swirl->visual, image_depth, ZPixmap, - 0, (char *) swirl->image, swirl->width, - swirl->height, pad, bytes_per_line); + swirl->ximage = create_xshm_image(dpy, swirl->visual, swirl->rdepth, + ZPixmap, &swirl->shm_info, + swirl->width, swirl->height); } /****************************************************************/ @@ -1126,10 +1110,9 @@ draw_point(ModeInfo * mi, SWIRL_P swirl) draw_block(swirl->ximage, x, y, r, do_point(swirl, x, y)); /* update the screen */ -/* PURIFY 4.0.1 on SunOS4 and on Solaris 2 reports a 256 byte memory leak on * - the next line. */ - XPutImage(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), swirl->ximage, - x, y, x, y, r, r); + + put_xshm_image(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), swirl->ximage, + x, y, x, y, r, r, &swirl->shm_info); } /****************************************************************/ @@ -1239,28 +1222,18 @@ next_point(SWIRL_P swirl) * * - win is the window to draw in */ -void +ENTRYPOINT void init_swirl(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); SWIRL_P swirl; - /* does the swirls array exist? */ - if (swirls == NULL) { - int i; - - /* allocate an array, one entry for each screen */ - swirls = (SWIRL_P) calloc(ScreenCount(display), sizeof (SWIRL)); - - /* initialise them all */ - for (i = 0; i < ScreenCount(display); i++) - initialise_swirl(mi, &swirls[i]); - } - /* get a pointer to this swirl */ + MI_INIT (mi, swirls); swirl = &(swirls[MI_SCREEN(mi)]); - - /* get window parameters */ + initialise_swirl(mi, swirl); + + /* get window parameters */ swirl->win = window; swirl->width = MI_WIN_WIDTH(mi); swirl->height = MI_WIN_HEIGHT(mi); @@ -1272,7 +1245,7 @@ init_swirl(ModeInfo * mi) swirl->depth = 16; /* initialise image for speeding up drawing */ - initialise_image(display, swirl); + initialise_image(mi, swirl); /* clear the window (before setting the colourmap) */ XClearWindow(display, MI_WINDOW(mi)); @@ -1341,7 +1314,7 @@ init_swirl(ModeInfo * mi) * * - win is the window to draw in */ -void +ENTRYPOINT void draw_swirl(ModeInfo * mi) { SWIRL_P swirl = &(swirls[MI_SCREEN(mi)]); @@ -1352,118 +1325,112 @@ draw_swirl(ModeInfo * mi) if (swirl->drawing) { #ifdef STANDALONE if (mi->writable_p) - rotate_colors(MI_DISPLAY(mi), MI_COLORMAP(mi), + rotate_colors(mi->xgwa.screen, MI_COLORMAP(mi), swirl->rgb_values, swirl->colours, 1); #else /* !STANDALONE */ - /* rotate the colours */ - install_map(MI_DISPLAY(mi), swirl, swirl->dshift); + /* rotate the colours */ + install_map(MI_DISPLAY(mi), swirl, swirl->dshift); #endif /* !STANDALONE */ - /* draw a batch of points */ - swirl->batch_todo = BATCH_DRAW; - while ((swirl->batch_todo > 0) && swirl->drawing) { - /* draw a point */ - draw_point(mi, swirl); + /* draw a batch of points */ + swirl->batch_todo = BATCH_DRAW; + while ((swirl->batch_todo > 0) && swirl->drawing) { + /* draw a point */ + draw_point(mi, swirl); - /* move to the next point */ - next_point(swirl); + /* move to the next point */ + next_point(swirl); - /* done a point */ - swirl->batch_todo--; - } + /* done a point */ + swirl->batch_todo--; + } } else { #ifdef STANDALONE if (mi->writable_p) - rotate_colors(MI_DISPLAY(mi), MI_COLORMAP(mi), + rotate_colors(mi->xgwa.screen, MI_COLORMAP(mi), swirl->rgb_values, swirl->colours, 1); #else /* !STANDALONE */ - /* rotate the colours */ - install_map(MI_DISPLAY(mi), swirl, swirl->shift); + /* rotate the colours */ + install_map(MI_DISPLAY(mi), swirl, swirl->shift); #endif /* !STANDALONE */ - /* time for a higher resolution? */ - if (swirl->resolution > swirl->max_resolution) { - /* move to higher resolution */ - swirl->resolution--; - - /* calculate the pixel step for this resulution */ - swirl->r = (1 << (swirl->resolution - 1)); - - /* start drawing again */ - swirl->drawing = True; - - /* start in the middle of the screen */ - swirl->x = (swirl->width - swirl->r) / 2; - swirl->y = (swirl->height - swirl->r) / 2; - - /* initialise spiral drawing parameters */ - swirl->direction = DRAW_RIGHT; - swirl->dir_todo = 1; - swirl->dir_done = 0; - } else { - /* all done, decide when to restart */ - if (swirl->start_again == -1) { - /* start the counter */ - swirl->start_again = RESTART; - } else if (swirl->start_again == 0) { - /* reset the counter */ - swirl->start_again = -1; + /* time for a higher resolution? */ + if (swirl->resolution > swirl->max_resolution) { + /* move to higher resolution */ + swirl->resolution--; + + /* calculate the pixel step for this resulution */ + swirl->r = (1 << (swirl->resolution - 1)); + + /* start drawing again */ + swirl->drawing = True; + + /* start in the middle of the screen */ + swirl->x = (swirl->width - swirl->r) / 2; + swirl->y = (swirl->height - swirl->r) / 2; + + /* initialise spiral drawing parameters */ + swirl->direction = DRAW_RIGHT; + swirl->dir_todo = 1; + swirl->dir_done = 0; + } else { + /* all done, decide when to restart */ + if (swirl->start_again == -1) { + /* start the counter */ + swirl->start_again = RESTART; + } else if (swirl->start_again == 0) { + /* reset the counter */ + swirl->start_again = -1; #ifdef STANDALONE - /* Pick a new colormap! */ - XClearWindow (MI_DISPLAY(mi), MI_WINDOW(mi)); - free_colors (MI_DISPLAY(mi), MI_COLORMAP(mi), - mi->colors, mi->npixels); - make_smooth_colormap (MI_DISPLAY(mi), - MI_VISUAL(mi), - MI_COLORMAP(mi), - mi->colors, &mi->npixels, True, - &mi->writable_p, True); - swirl->colours = mi->npixels; + /* Pick a new colormap! */ + XClearWindow (MI_DISPLAY(mi), MI_WINDOW(mi)); + free_colors (mi->xgwa.screen, MI_COLORMAP(mi), + mi->colors, mi->npixels); + make_smooth_colormap (mi->xgwa.screen, MI_VISUAL(mi), + MI_COLORMAP(mi), + mi->colors, &mi->npixels, True, + &mi->writable_p, True); + swirl->colours = mi->npixels; #endif /* STANDALONE */ - /* start again */ - init_swirl(mi); - } else - /* decrement the counter */ - swirl->start_again--; - } + /* start again */ + init_swirl(mi); + } else + /* decrement the counter */ + swirl->start_again--; + } } } } /****************************************************************/ -void -release_swirl(ModeInfo * mi) +ENTRYPOINT void +free_swirl (ModeInfo * mi) { - /* does the swirls array exist? */ - if (swirls != NULL) { - int i; - - /* free them all */ - for (i = 0; i < MI_NUM_SCREENS(mi); i++) { - SWIRL_P swirl = &(swirls[i]); - - if (swirl->cmap != (Colormap) NULL) - XFreeColormap(MI_DISPLAY(mi), swirl->cmap); - if (swirl->rgb_values != NULL) - XFree((void *) swirl->rgb_values); - if (swirl->ximage != NULL) - XDestroyImage(swirl->ximage); - if (swirl->knots) - (void) free((void *) swirl->knots); - } - /* deallocate an array, one entry for each screen */ - (void) free((void *) swirls); - swirls = NULL; - } + SWIRL_P swirl = &(swirls[MI_SCREEN(mi)]); + +#ifndef STANDALONE + if (swirl->cmap != (Colormap) NULL) + XFreeColormap(MI_DISPLAY(mi), swirl->cmap); +#endif /* STANDALONE */ +#ifndef STANDALONE + if (swirl->rgb_values != NULL) + XFree((void *) swirl->rgb_values); +#endif /* !STANDALONE */ + if (swirl->ximage != NULL) + destroy_xshm_image(MI_DISPLAY(mi), swirl->ximage, + &swirl->shm_info); + if (swirl->knots) + (void) free((void *) swirl->knots); } /****************************************************************/ -void -refresh_swirl(ModeInfo * mi) +#ifndef STANDALONE +ENTRYPOINT void +refresh_swirl (ModeInfo * mi) { SWIRL_P swirl = &(swirls[MI_SCREEN(mi)]); @@ -1473,3 +1440,6 @@ refresh_swirl(ModeInfo * mi) swirl->drawing = False; } } +#endif + +XSCREENSAVER_MODULE ("Swirl", swirl)