altos/draw: Use damage for lco demo
authorKeith Packard <keithp@keithp.com>
Mon, 27 Feb 2023 22:39:03 +0000 (14:39 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 27 Feb 2023 22:39:39 +0000 (14:39 -0800)
Do some incremental drawing to demonstrate damage in action

Signed-off-by: Keith Packard <keithp@keithp.com>
src/draw/lco-test.c
src/draw/test-frame.c

index bb45e187cff14a4c2bec6bd384cbabc8161c89fb..74671de57f8bfe0cc2364f04a813bef43c5554da 100644 (file)
@@ -135,14 +135,18 @@ prev_box(void)
        box_number = max_box;
 }
 
+static bool redraw_all = true;
+
 void HandleExpose(Display *dpy, Window win, GC gc)
 {
        char    str[64];
        int     i;
        int     v;
+       int     last_box;
        int16_t b;
 
-       ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
+       if (redraw_all)
+               ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
 
        if (do_polys == 1)
                current_timeout = TIMEOUT;
@@ -150,13 +154,19 @@ void HandleExpose(Display *dpy, Window win, GC gc)
                current_timeout = 0;
        switch (do_polys) {
        case 1:
-               ao_logo(&fb, &logo_transform, &LOGO_FONT, 0x00000000, AO_COPY);
+               if (redraw_all)
+                       ao_logo(&fb, &logo_transform, &LOGO_FONT, 0x00000000, AO_COPY);
+               else
+                       ao_rect(&fb, 0, SCAN_Y, WIDTH, HEIGHT-SCAN_Y, 0xffffffff, AO_COPY);
                if (scan_number) {
                        ao_rect(&fb, SCAN_X, SCAN_Y, (int16_t) scan_number, SCAN_HEIGHT, 0x00000000, AO_COPY);
                        b = 0;
                        v = 0;
+                       last_box = 0;
                        for (i = scan_number; i > 1; i--) {
                                if (valid_box(i)) {
+                                       if (!last_box)
+                                               last_box = i;
                                        v++;
                                        if (v == MAX_VALID)
                                                break;
@@ -164,11 +174,12 @@ void HandleExpose(Display *dpy, Window win, GC gc)
                        }
                        for (; i <= scan_number; i++) {
                                if (valid_box(i)) {
-                                       sprintf(str, "%02d", i);
+                                       sprintf(str, "%02d%s", i, i == last_box ? "" : ",");
                                        ao_text(&fb, &TINY_FONT, 0 + FOUND_WIDTH * b, FOUND_Y, str, 0x00000000, AO_COPY);
                                        b++;
                                }
                        }
+                       redraw_all = false;
                }
                break;
        case 2:
@@ -221,6 +232,8 @@ void
 HandleKeyPress(Display *dpy, Window win, GC gc, XEvent *ev)
 {
        char    string[10];
+
+       redraw_all = true;
        if (XLookupString ((XKeyEvent *) ev, string, sizeof (string), 0, 0) >= 1) {
                switch (string[0]) {
                case 'q':
@@ -290,6 +303,7 @@ HandleTimeout(Display *dpy, Window win, GC gc)
                if (scan_number < 99)
                        scan_number++;
                else {
+                       redraw_all = true;
                        box_number = boxes[0];
                        pad_number = 1;
                        do_polys = 0;
index a90dfc74543593360590f0e2fa07435d48786f45..fc054738c711c51193b65a2489182e4e9e80b298 100644 (file)
@@ -44,7 +44,8 @@ static struct ao_bitmap fb = {
        .base = bits,
        .stride = STRIDE,
        .width = WIDTH,
-       .height = HEIGHT
+       .height = HEIGHT,
+       .damage = AO_BOX_INIT,
 };
 
 static XImage *shm_image;
@@ -83,11 +84,11 @@ DoDisplay(Display *dpy, Window win, GC gc)
        else
                image = nonshm_image;
 
-       scan = bits;
-       for (iy = 0; iy < HEIGHT; iy++) {
+       scan = bits + STRIDE * fb.damage.y1;
+       for (iy = fb.damage.y1; iy < fb.damage.y2; iy++) {
                w = scan;
                scan += STRIDE;
-               for (ix = 0; ix < WIDTH; ix += 32) {
+               for (ix = fb.damage.x1 & ~31; ix < fb.damage.x2; ix += 32) {
                        d = *w++;
                        for (ib = 0; ib < 32 && ix + ib < WIDTH; ib++) {
                                unsigned long p = d & 1 ? white : black;
@@ -105,4 +106,5 @@ DoDisplay(Display *dpy, Window win, GC gc)
                XShmPutImage(dpy, win, gc, image, 0, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, False);
        else
                XPutImage(dpy, win, gc, image, 0, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
+       ao_damage_set_empty(&fb);
 }