X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fgrab-ximage.c;h=580633292a2a1be3a771376c189c088d91b8c096;hb=3f1091236d800c43a3124c44c7da54e53f205b13;hp=4fea33858b00f236d553597bc115f26fe7e8bb48;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/glx/grab-ximage.c b/hacks/glx/grab-ximage.c index 4fea3385..58063329 100644 --- a/hacks/glx/grab-ximage.c +++ b/hacks/glx/grab-ximage.c @@ -1,5 +1,5 @@ /* grab-ximage.c --- grab the screen to an XImage for use with OpenGL. - * xscreensaver, Copyright (c) 2001-2006 Jamie Zawinski + * xscreensaver, Copyright (c) 2001-2008 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -20,8 +20,9 @@ #ifdef HAVE_COCOA # include "jwxyz.h" -# include -# include +# ifndef HAVE_JWZGLES +# include +# endif #else # include # include @@ -30,6 +31,10 @@ # include /* for glXMakeCurrent() */ #endif +#ifdef HAVE_JWZGLES +# include "jwzgles.h" +#endif /* HAVE_JWZGLES */ + #include "grab-ximage.h" #include "grabscreen.h" #include "visual.h" @@ -141,11 +146,10 @@ convert_ximage_to_rgba32 (Screen *screen, XImage *image) unsigned int srpos=0, sgpos=0, sbpos=0; unsigned int srmsk=0, sgmsk=0, sbmsk=0; unsigned int srsiz=0, sgsiz=0, sbsiz=0; - int i; XColor *colors = 0; unsigned char spread_map[3][256]; - /* Note: height+2 in "to" to be to work around an array bounds overrun + /* Note: height+2 in "to" to work around an array bounds overrun in gluBuild2DMipmaps / gluScaleImage. */ XImage *from = image; @@ -193,6 +197,7 @@ convert_ximage_to_rgba32 (Screen *screen, XImage *image) if (colors == 0) /* truecolor */ { + int i; for (i = 0; i < 256; i++) { spread_map[0][i] = spread_bits (i, srsiz); @@ -201,6 +206,10 @@ convert_ximage_to_rgba32 (Screen *screen, XImage *image) } } + /* trying to track down an intermittent crash in ximage_putpixel_32 */ + if (to->width < from->width) abort(); + if (to->height < from->height) abort(); + for (y = 0; y < from->height; y++) for (x = 0; x < from->width; x++) { @@ -319,6 +328,9 @@ pixmap_to_gl_ximage (Screen *screen, Window window, Pixmap pixmap) XGetGeometry (dpy, pixmap, &root, &x, &y, &width, &height, &bw, &depth); } + if (width < 5 || height < 5) /* something's gone wrong somewhere... */ + return 0; + /* Convert the server-side Pixmap to a client-side GL-ordered XImage. */ # ifdef HAVE_XSHM_EXTENSION @@ -517,15 +529,11 @@ double_time (void) /* return the next larger power of 2. */ static int -to_pow2 (int i) +to_pow2 (int value) { - static const unsigned int pow2[] = { - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, - 2048, 4096, 8192, 16384, 32768, 65536 }; - int j; - for (j = 0; j < countof(pow2); j++) - if (pow2[j] >= i) return pow2[j]; - abort(); /* too big! */ + int i = 1; + while (i < value) i <<= 1; + return i; } @@ -580,7 +588,7 @@ ximage_to_texture (XImage *ximage, progname, ximage->width, ximage->height, tex_width, tex_height); - glTexImage2D (GL_TEXTURE_2D, 0, 3, tex_width, tex_height, 0, + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, tex_width, tex_height, 0, format, type, 0); err = glGetError();