Track whether cliplists have changed and avoid computation when not. Shrink

shadows. Speed up shadow construction a bit by using memset. Eliminate
    useless INTERVAL code. Use XSync after paint_all to gather more events
    per update.
This commit is contained in:
Keith Packard 2003-12-02 09:51:12 +00:00
parent 0963afc29c
commit 10d93f24f0
2 changed files with 86 additions and 69 deletions

View File

@ -1,3 +1,14 @@
2003-12-02 Keith Packard <keithp@keithp.com>
* xcompmgr.c: (sum_gaussian), (make_shadow), (root_tile),
(paint_all), (map_win), (unmap_win), (determine_mode),
(configure_win), (circulate_win), (main):
Track whether cliplists have changed and avoid computation when not.
Shrink shadows.
Speed up shadow construction a bit by using memset.
Eliminate useless INTERVAL code.
Use XSync after paint_all to gather more events per update.
2003-11-24 Matthew Hawn <hawnpawn@yahoo.com> 2003-11-24 Matthew Hawn <hawnpawn@yahoo.com>
reviewed by: Keith Packard <keithp@keithp.com> reviewed by: Keith Packard <keithp@keithp.com>

View File

@ -79,6 +79,7 @@ Picture transPicture;
Picture blackPicture; Picture blackPicture;
Picture rootTile; Picture rootTile;
XserverRegion allDamage; XserverRegion allDamage;
Bool clipChanged;
int root_height, root_width; int root_height, root_width;
@ -96,12 +97,13 @@ conv *gaussianMap;
#define WINDOW_ARGB 2 #define WINDOW_ARGB 2
#define TRANS_OPACITY 0.75 #define TRANS_OPACITY 0.75
#define SHADOW_RADIUS 15 #define SHADOW_RADIUS 8
#define SHADOW_OPACITY 0.75 #define SHADOW_OPACITY 0.75
#define SHADOW_OFFSET_X (-SHADOW_RADIUS) #define SHADOW_OFFSET_X (-SHADOW_RADIUS * 3 / 2)
#define SHADOW_OFFSET_Y (-SHADOW_RADIUS) #define SHADOW_OFFSET_Y (-SHADOW_RADIUS * 2 / 2)
#define DEBUG 0 #define DEBUG_REPAINT 0
#define DEBUG_EVENTS 0
#define MONITOR_REPAINT 0 #define MONITOR_REPAINT 0
static double static double
@ -208,7 +210,7 @@ sum_gaussian (conv *map, double opacity, int x, int y, int width, int height)
if (v > 1) if (v > 1)
v = 1; v = 1;
return ((unsigned int) (v * opacity * 255.0)); return ((unsigned char) (v * opacity * 255.0));
} }
static XImage * static XImage *
@ -223,6 +225,7 @@ make_shadow (Display *dpy, double opacity, int width, int height)
int center = gsize / 2; int center = gsize / 2;
int x, y; int x, y;
unsigned char d; unsigned char d;
int x_diff;
data = malloc (swidth * sheight * sizeof (unsigned char)); data = malloc (swidth * sheight * sizeof (unsigned char));
ximage = XCreateImage (dpy, ximage = XCreateImage (dpy,
@ -236,6 +239,13 @@ make_shadow (Display *dpy, double opacity, int width, int height)
* Build the gaussian in sections * Build the gaussian in sections
*/ */
/*
* center (fill the complete data array)
*/
d = sum_gaussian (gaussianMap, opacity, center, center, width, height);
memset(data, d, sheight * swidth);
/* /*
* corners * corners
*/ */
@ -259,13 +269,21 @@ make_shadow (Display *dpy, double opacity, int width, int height)
/* /*
* top/bottom * top/bottom
*/ */
for (y = 0; y < ylimit; y++) x_diff = swidth - (gsize * 2);
if (x_diff > 0 && ylimit > 0)
{ {
d = sum_gaussian (gaussianMap, opacity, center, y - center, width, height); for (y = 0; y < ylimit; y++)
for (x = gsize; x < swidth - gsize; x++)
{ {
data[y * swidth + x] = d; d = sum_gaussian (gaussianMap, opacity, center, y - center, width, height);
data[(sheight - y - 1) * swidth + x] = d; memset (&data[y * swidth + gsize], d, x_diff);
memset (&data[(sheight - y - 1) * swidth + gsize], d, x_diff);
#if 0
for (x = gsize; x < swidth - gsize; x++)
{
data[y * swidth + x] = d;
data[(sheight - y - 1) * swidth + x] = d;
}
#endif
} }
} }
@ -350,6 +368,7 @@ root_tile (Display *dpy)
XRenderPictureAttributes pa; XRenderPictureAttributes pa;
int p; int p;
pixmap = None;
for (p = 0; backgroundProps[p]; p++) for (p = 0; backgroundProps[p]; p++)
{ {
if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False), if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False),
@ -363,7 +382,7 @@ root_tile (Display *dpy)
break; break;
} }
} }
if (!backgroundProps[p]) if (!pixmap)
{ {
pixmap = XCreatePixmap (dpy, root, 1, 1, DefaultDepth (dpy, scr)); pixmap = XCreatePixmap (dpy, root, 1, 1, DefaultDepth (dpy, scr));
fill = True; fill = True;
@ -489,7 +508,7 @@ paint_all (Display *dpy, XserverRegion region)
XRenderComposite (dpy, PictOpSrc, blackPicture, None, rootPicture, XRenderComposite (dpy, PictOpSrc, blackPicture, None, rootPicture,
0, 0, 0, 0, 0, 0, root_width, root_height); 0, 0, 0, 0, 0, 0, root_width, root_height);
#endif #endif
#if DEBUG #if DEBUG_REPAINT
printf ("paint:"); printf ("paint:");
#endif #endif
for (w = list; w; w = w->next) for (w = list; w; w = w->next)
@ -501,15 +520,31 @@ paint_all (Display *dpy, XserverRegion region)
continue; continue;
if (!w->picture) if (!w->picture)
continue; continue;
#if DEBUG #if DEBUG_REPAINT
printf (" 0x%x", w->id); printf (" 0x%x", w->id);
#endif #endif
if (w->borderSize) if (clipChanged)
XFixesDestroyRegion (dpy, w->borderSize); {
w->borderSize = border_size (dpy, w); if (w->borderSize)
if (w->extents) {
XFixesDestroyRegion (dpy, w->extents); XFixesDestroyRegion (dpy, w->borderSize);
w->extents = win_extents (dpy, w); w->borderSize = None;
}
if (w->extents)
{
XFixesDestroyRegion (dpy, w->extents);
w->extents = None;
}
if (w->borderClip)
{
XFixesDestroyRegion (dpy, w->borderClip);
w->borderClip = None;
}
}
if (!w->borderSize)
w->borderSize = border_size (dpy, w);
if (!w->extents)
w->extents = win_extents (dpy, w);
if (w->mode == WINDOW_SOLID) if (w->mode == WINDOW_SOLID)
{ {
XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region); XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
@ -521,13 +556,17 @@ paint_all (Display *dpy, XserverRegion region)
w->a.width, w->a.width,
w->a.height); w->a.height);
} }
w->borderClip = XFixesCreateRegion (dpy, 0, 0); if (!w->borderClip)
XFixesCopyRegion (dpy, w->borderClip, region); {
w->borderClip = XFixesCreateRegion (dpy, 0, 0);
XFixesCopyRegion (dpy, w->borderClip, region);
}
w->prev_trans = t; w->prev_trans = t;
t = w; t = w;
} }
#if DEBUG #if DEBUG_REPAINT
printf ("\n"); printf ("\n");
fflush (stdout);
#endif #endif
XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region); XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
paint_root (dpy); paint_root (dpy);
@ -618,6 +657,7 @@ map_win (Display *dpy, Window id, unsigned long sequence)
XSelectInput(dpy, id, PropertyChangeMask); XSelectInput(dpy, id, PropertyChangeMask);
w->damaged = 0; w->damaged = 0;
clipChanged = True;
} }
static void static void
@ -637,6 +677,7 @@ unmap_win (Display *dpy, Window id)
/* don't care about properties anymore */ /* don't care about properties anymore */
XSelectInput(dpy, id, 0); XSelectInput(dpy, id, 0);
clipChanged = True;
} }
@ -716,7 +757,7 @@ determine_mode(Display *dpy, win *w)
{ {
/* changed this as a lot of window managers set this for all top /* changed this as a lot of window managers set this for all top
level windows */ level windows */
mode = WINDOW_SOLID; mode = WINDOW_TRANS;
} }
else else
{ {
@ -866,6 +907,7 @@ configure_win (Display *dpy, XConfigureEvent *ce)
XFixesDestroyRegion (dpy, extents); XFixesDestroyRegion (dpy, extents);
add_damage (dpy, damage); add_damage (dpy, damage);
} }
clipChanged = True;
} }
static void static void
@ -879,6 +921,7 @@ circulate_win (Display *dpy, XCirculateEvent *ce)
else else
new_above = None; new_above = None;
restack_win (dpy, w, new_above); restack_win (dpy, w, new_above);
clipChanged = True;
} }
static void static void
@ -944,20 +987,6 @@ expose_root (Display *dpy, Window root, XRectangle *rects, int nrects)
add_damage (dpy, region); add_damage (dpy, region);
} }
#define INTERVAL 0
#if INTERVAL
static int
time_in_millis (void)
{
struct timeval tp;
gettimeofday (&tp, 0);
return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
}
#endif
#define INTERVAL 0
static int static int
ev_serial (XEvent *ev) ev_serial (XEvent *ev)
@ -1035,9 +1064,6 @@ main (int argc, char **argv)
int last_update; int last_update;
int now; int now;
int p; int p;
#if INTERVAL
int timeout;
#endif
dpy = XOpenDisplay (0); dpy = XOpenDisplay (0);
if (!dpy) if (!dpy)
@ -1046,6 +1072,9 @@ main (int argc, char **argv)
exit (1); exit (1);
} }
XSetErrorHandler (error); XSetErrorHandler (error);
#if 0
XSynchronize (dpy, 1);
#endif
scr = DefaultScreen (dpy); scr = DefaultScreen (dpy);
root = RootWindow (dpy, scr); root = RootWindow (dpy, scr);
@ -1100,6 +1129,7 @@ main (int argc, char **argv)
exit (1); exit (1);
} }
allDamage = None; allDamage = None;
clipChanged = True;
XGrabServer (dpy); XGrabServer (dpy);
XCompositeRedirectSubwindows (dpy, root, CompositeRedirectManual); XCompositeRedirectSubwindows (dpy, root, CompositeRedirectManual);
XSelectInput (dpy, root, XSelectInput (dpy, root,
@ -1113,22 +1143,12 @@ main (int argc, char **argv)
XFree (children); XFree (children);
XUngrabServer (dpy); XUngrabServer (dpy);
paint_all (dpy, None); paint_all (dpy, None);
#if INTERVAL
last_update = time_in_millis ();
#endif
for (;;) for (;;)
{ {
#if INTERVAL
int busy_start = 0;
#endif
/* dump_wins (); */ /* dump_wins (); */
do { do {
XNextEvent (dpy, &ev); XNextEvent (dpy, &ev);
#if INTERVAL #if DEBUG_EVENTS
if (!busy_start)
busy_start = time_in_millis();
#endif
#if DEBUG
printf ("event %10.10s serial 0x%08x window 0x%08x\n", printf ("event %10.10s serial 0x%08x window 0x%08x\n",
ev_name(&ev), ev_serial (&ev), ev_window (&ev)); ev_name(&ev), ev_serial (&ev), ev_window (&ev));
#endif #endif
@ -1226,28 +1246,14 @@ main (int argc, char **argv)
break; break;
} }
} while (QLength (dpy)); } while (QLength (dpy));
#if INTERVAL
now = time_in_millis ();
/* printf ("\t\tbusy %d\n", now - busy_start); */
timeout = INTERVAL - (now - last_update);
if (timeout > 0)
{
ufd.fd = ConnectionNumber (dpy);
ufd.events = POLLIN;
n = poll (&ufd, 1, timeout);
if (n > 0 && (ufd.revents & POLLIN) && XEventsQueued (dpy, QueuedAfterReading))
continue;
}
#endif
if (allDamage) if (allDamage)
{ {
#if INTERVAL static int paint;
int old_update = last_update;
last_update = time_in_millis();
/* printf ("delta %d\n", last_update - old_update); */
#endif
paint_all (dpy, allDamage); paint_all (dpy, allDamage);
paint++;
XSync (dpy, False);
allDamage = None; allDamage = None;
clipChanged = False;
} }
} }
} }