diff options
author | philip <philip@FreeBSD.org> | 2007-02-21 12:27:12 +0000 |
---|---|---|
committer | philip <philip@FreeBSD.org> | 2007-02-21 12:27:12 +0000 |
commit | e0f499d1d4431d2e6df14594352d3b4828252d6f (patch) | |
tree | 8f2df30a1e9c79b8e09d7dc29d55cee093923b96 /sys/dev | |
parent | 74bf41b149bacbb9c41cd49e28a27658d11313c2 (diff) | |
download | FreeBSD-src-e0f499d1d4431d2e6df14594352d3b4828252d6f.zip FreeBSD-src-e0f499d1d4431d2e6df14594352d3b4828252d6f.tar.gz |
Optimize set_origin() use in some screensavers to stop them eating
cpu power when the origin hasn't changed.
PR: kern/100683
Submitted by: Gareth McCaughan <gareth -dot- mccaughan -at- pobox.com>
MFC after: 3 days
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/syscons/fire/fire_saver.c | 11 | ||||
-rw-r--r-- | sys/dev/syscons/logo/logo_saver.c | 13 | ||||
-rw-r--r-- | sys/dev/syscons/rain/rain_saver.c | 17 | ||||
-rw-r--r-- | sys/dev/syscons/warp/warp_saver.c | 11 |
4 files changed, 40 insertions, 12 deletions
diff --git a/sys/dev/syscons/fire/fire_saver.c b/sys/dev/syscons/fire/fire_saver.c index 0bc031c..de60a20 100644 --- a/sys/dev/syscons/fire/fire_saver.c +++ b/sys/dev/syscons/fire/fire_saver.c @@ -52,6 +52,12 @@ #define GREEN(n) ((n) * 3 + 1) #define BLUE(n) ((n) * 3 + 2) +#define SET_ORIGIN(adp, o) do { \ + int oo = o; \ + if (oo != last_origin) \ + set_origin(adp, last_origin = oo); \ + } while (0) + static u_char *buf; static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; @@ -63,6 +69,7 @@ fire_update(video_adapter_t *adp) { int x, y; int o, p; + int last_origin = -1; /* make a new bottom line */ for (x = 0, y = scrh; x < scrw; x++) @@ -87,12 +94,12 @@ fire_update(video_adapter_t *adp) p -= banksize; o += banksize; } - set_origin(adp, o); + SET_ORIGIN(adp, o); if (p + scrw < banksize) { bcopy(buf + y * scrw, vid + p, scrw); } else { bcopy(buf + y * scrw, vid + p, banksize - p); - set_origin(adp, o + banksize); + SET_ORIGIN(adp, o + banksize); bcopy(buf + y * scrw + (banksize - p), vid, scrw - (banksize - p)); p -= banksize; diff --git a/sys/dev/syscons/logo/logo_saver.c b/sys/dev/syscons/logo/logo_saver.c index 0a75886..20f2bdc 100644 --- a/sys/dev/syscons/logo/logo_saver.c +++ b/sys/dev/syscons/logo/logo_saver.c @@ -42,6 +42,12 @@ #define SAVER_NAME "logo_saver" +#define SET_ORIGIN(adp, o) do { \ + int oo = o; \ + if (oo != last_origin) \ + set_origin(adp, last_origin = oo); \ + } while (0) + extern unsigned int logo_w; extern unsigned int logo_h; extern unsigned char logo_pal[]; @@ -56,10 +62,11 @@ static void logo_blit(video_adapter_t *adp, int x, int y) { int d, l, o, p; + int last_origin = -1; for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize) o += banksize; - set_origin(adp, o); + SET_ORIGIN(adp, o); for (d = 0; d < logo_img_size; d += logo_w) { if (p + logo_w < banksize) { @@ -68,12 +75,12 @@ logo_blit(video_adapter_t *adp, int x, int y) } else if (p < banksize) { l = banksize - p; bcopy(logo_img + d, vid + p, l); - set_origin(adp, (o += banksize)); + SET_ORIGIN(adp, (o += banksize)); bcopy(logo_img + d + l, vid, logo_w - l); p += bpsl - banksize; } else { p -= banksize; - set_origin(adp, (o += banksize)); + SET_ORIGIN(adp, (o += banksize)); bcopy(logo_img + d, vid + p, logo_w); p += bpsl; } diff --git a/sys/dev/syscons/rain/rain_saver.c b/sys/dev/syscons/rain/rain_saver.c index 80e2212..3cdf980 100644 --- a/sys/dev/syscons/rain/rain_saver.c +++ b/sys/dev/syscons/rain/rain_saver.c @@ -51,6 +51,12 @@ #define GREEN(n) ((n) * 3 + 1) #define BLUE(n) ((n) * 3 + 2) +#define SET_ORIGIN(adp, o) do { \ + int oo = o; \ + if (oo != last_origin) \ + set_origin(adp, last_origin = oo); \ + } while (0) + static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; static u_char rain_pal[768]; @@ -73,6 +79,7 @@ rain_saver(video_adapter_t *adp, int blank) { int i, j, o, p, pl; u_char temp; + int last_origin = -1; if (blank) { /* switch to graphics mode */ @@ -87,18 +94,18 @@ rain_saver(video_adapter_t *adp, int blank) bpsl = adp->va_line_width; splx(pl); for (i = 0; i < bpsl*scrh; i += banksize) { - set_origin(adp, i); + SET_ORIGIN(adp, i); if ((bpsl * scrh - i) < banksize) bzero(vid, bpsl * scrh - i); else bzero(vid, banksize); } - set_origin(adp, 0); + SET_ORIGIN(adp, 0); for (i = 0, o = 0, p = 0; i < scrw; i += 2, p += 2) { if (p > banksize) { p -= banksize; o += banksize; - set_origin(adp, o); + SET_ORIGIN(adp, o); } vid[p] = 1 + (random() % MAX); } @@ -109,12 +116,12 @@ rain_saver(video_adapter_t *adp, int blank) p -= banksize; o += banksize; } - set_origin(adp, o); + SET_ORIGIN(adp, o); temp = (vid[p] < MAX) ? 1 + vid[p] : 1; if (p + bpsl < banksize) { vid[p + bpsl] = temp; } else { - set_origin(adp, o + banksize); + SET_ORIGIN(adp, o + banksize); vid[p + bpsl - banksize] = temp; } } diff --git a/sys/dev/syscons/warp/warp_saver.c b/sys/dev/syscons/warp/warp_saver.c index 050790d..aba2439 100644 --- a/sys/dev/syscons/warp/warp_saver.c +++ b/sys/dev/syscons/warp/warp_saver.c @@ -44,6 +44,12 @@ #define SPP 15 #define STARS (SPP * (1 + 2 + 4 + 8)) +#define SET_ORIGIN(adp, o) do { \ + int oo = o; \ + if (oo != last_origin) \ + set_origin(adp, last_origin = oo); \ + } while (0) + static u_char *vid; static int banksize, scrmode, bpsl, scrw, scrh; static int blanked; @@ -61,6 +67,7 @@ static void warp_update(video_adapter_t *adp) { int i, j, k, n, o, p; + int last_origin = -1; for (i = 1, k = 0, n = SPP*8; i < 5; i++, n /= 2) { for (j = 0; j < n; j++, k++) { @@ -70,7 +77,7 @@ warp_update(video_adapter_t *adp) p -= banksize; o += banksize; } - set_origin(adp, o); + SET_ORIGIN(adp, o); vid[p] = 0; star[k] += i; if (star[k] > scrw*scrh) @@ -81,7 +88,7 @@ warp_update(video_adapter_t *adp) p -= banksize; o += banksize; } - set_origin(adp, o); + SET_ORIGIN(adp, o); vid[p] = i; } } |