X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fswirl.c;h=5ea1598c54efe007530ea299307c6151fe22f471;hb=ce3185de9d9705e259f2b60dd4b5509007fa17d4;hp=7f3764f02a75f9b5de626cf7186e7ca6fdf407c5;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0;p=xscreensaver diff --git a/hacks/swirl.c b/hacks/swirl.c index 7f3764f0..5ea1598c 100644 --- a/hacks/swirl.c +++ b/hacks/swirl.c @@ -19,7 +19,7 @@ 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. + * 13-May-97: jwz@jwz.org: 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 @@ -36,13 +36,18 @@ static const char sccsid[] = "@(#)swirl.c 4.00 97/01/01 xlockmore"; # define swirl_opts xlockmore_opts # define DEFAULTS "*count: 5 \n" \ "*delay: 10000 \n" \ - "*ncolors: 200 \n" + "*ncolors: 200 \n" \ + "*useSHM: True \n" # define SMOOTH_COLORS # define WRITABLE_COLORS # include "xlockmore.h" /* from the xscreensaver distribution */ # include +# ifdef HAVE_XSHM_EXTENSION +# include "xshm.h" +# endif /* HAVE_XSHM_EXTENSION */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ +# undef HAVE_XSHM_EXTENSION #endif /* !STANDALONE */ ModeSpecOpt swirl_opts = { @@ -241,37 +246,33 @@ 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); - - /* how many bytes per line? (bits rounded up to pad) */ - bytes_per_line = ((swirl->width * data_depth + pad - 1) / pad) * (pad / 8); - - /* 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); + Display *dpy = MI_DISPLAY(mi); + + if (swirl->ximage != NULL) + XDestroyImage(swirl->ximage); + + swirl->ximage = 0; +#ifdef HAVE_XSHM_EXTENSION + if (mi->use_shm) + { + swirl->ximage = create_xshm_image(dpy, swirl->visual, swirl->rdepth, + ZPixmap, 0, &mi->shm_info, + swirl->width, swirl->height); + if (!swirl->ximage) + mi->use_shm = False; + } +#endif /* HAVE_XSHM_EXTENSION */ + + if (!swirl->ximage) + { + swirl->ximage = XCreateImage(dpy, swirl->visual, swirl->rdepth, ZPixmap, + 0, 0, swirl->width, swirl->height, + 8, 0); + swirl->ximage->data = swirl->image = + (char *) calloc(swirl->height, swirl->ximage->bytes_per_line); + } } /****************************************************************/ @@ -1126,10 +1127,17 @@ 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); + +#ifdef HAVE_XSHM_EXTENSION + if (mi->use_shm) + XShmPutImage(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), swirl->ximage, + x, y, x, y, r, r, False); + else +#endif /* !HAVE_XSHM_EXTENSION */ + /* 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); } /****************************************************************/ @@ -1272,7 +1280,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));