simple-shm: render meaningful diagnostics
authorPekka Paalanen <ppaalanen@gmail.com>
Thu, 26 Apr 2012 12:14:50 +0000 (15:14 +0300)
committerPekka Paalanen <ppaalanen@gmail.com>
Thu, 26 Apr 2012 12:42:05 +0000 (15:42 +0300)
Previously, simple-shm was rendering an image that looked like stride
gone wrong somewhere, and was quite confusing if you did not know it was
supposed to look like that.

Replace the drawing code. Two circles, inner and outer, now delimit
three co-centric areas. The outmost area from surface borders to outer
circle contains horizontal gradients that move (animate) to the left.
The area between outer and inner circles contains vertical gradients
that move upwards. The center disc has circular gradients moving towards
the center.

The circles are not ellipses.

Diagnostics:
The X-channel is manipulated so, that if a compositor takes the XRGB
image, and uses the X channel as alpha instead of ignoring it, the whole
image will be crossed out by two lines that either quickly saturate to
white or show through with additive blending. Does not work on black
background.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
clients/simple-shm.c

index d1fe0c6..65c0eae 100644 (file)
@@ -130,21 +130,56 @@ destroy_window(struct window *window)
        free(window);
 }
 
+static void
+paint_pixels(void *image, int width, int height, uint32_t time)
+{
+       const int halfh = height / 2;
+       const int halfw = width / 2;
+       int ir, or;
+       uint32_t *pixel = image;
+       int y;
+
+       /* squared radii thresholds */
+       or = (halfw < halfh ? halfw : halfh) - 8;
+       ir = or - 32;
+       or *= or;
+       ir *= ir;
+
+       for (y = 0; y < height; y++) {
+               int x;
+               int y2 = (y - halfh) * (y - halfh);
+
+               for (x = 0; x < width; x++) {
+                       uint32_t v;
+
+                       /* squared distance from center */
+                       int r2 = (x - halfw) * (x - halfw) + y2;
+
+                       if (r2 < ir)
+                               v = (r2 / 32 + time / 64) * 0x0080401;
+                       else if (r2 < or)
+                               v = (y + time / 32) * 0x0080401;
+                       else
+                               v = (x + time / 16) * 0x0080401;
+                       v &= 0x00ffffff;
+
+                       /* cross if compositor uses X from XRGB as alpha */
+                       if (abs(x - y) > 6 && abs(x + y - height) > 6)
+                               v |= 0xff000000;
+
+                       *pixel++ = v;
+               }
+       }
+}
+
 static const struct wl_callback_listener frame_listener;
 
 static void
 redraw(void *data, struct wl_callback *callback, uint32_t time)
 {
        struct window *window = data;
-       uint32_t *p;
-       int i, end, offset;
-
-       p = window->shm_data;
-       end = window->width * window->height;
-       offset = time >> 4;
-       for (i = 0; i < end; i++)
-               p[i] = (i + offset) * 0x0080401;
 
+       paint_pixels(window->shm_data, window->width, window->height, time);
        wl_surface_attach(window->surface, window->buffer, 0, 0);
        wl_surface_damage(window->surface,
                          0, 0, window->width, window->height);