+static void
+clear_rect(Display *display, Drawable d, int x, int y, int w, int h)
+{
+#if X11_RENDER_DEBUG
+ XRectangle r = { x, y, w, h };
+ XGCValues gcv;
+ GC gc;
+
+ gcv.foreground = 0xff0000;
+ gc = XCreateGC(display, d, GCForeground, &gcv);
+ XFillRectangles(display, d, gc, &r, 1);
+ XFreeGC(display, gc);
+
+ XFlush(display);
+ usleep(70000);
+#endif
+
+ XClearArea(display, d, x, y, w, h, 0);
+}
+
+/*
+ * Efficiently clear all the border tiles in the game area. The mask indicates
+ * which tiles need clearing, but for the border clear it is safe to wipe an
+ * entire row or column of the border using a single XClearArea.
+ */
+static void clear_border(Display *display, Drawable d, unsigned sz)
+{
+ clear_rect(display, d, 0, 0, -1, sz);
+ clear_rect(display, d, 0, 4*sz, -1, sz);
+ clear_rect(display, d, 0, 0, sz, -1);
+ clear_rect(display, d, 4*sz, 0, sz, -1);
+}
+