overlay: Take a snapshot on SIGUSR1
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 20 Aug 2013 18:24:33 +0000 (19:24 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Tue, 20 Aug 2013 20:30:56 +0000 (21:30 +0100)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
overlay/overlay.c

index 0968fd7..9212360 100644 (file)
@@ -8,6 +8,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <signal.h>
 
 #include "overlay.h"
 #include "chart.h"
@@ -556,6 +557,13 @@ static void show_gem_objects(struct overlay_context *ctx, struct overlay_gem_obj
        }
 }
 
+static int take_snapshot;
+
+static void signal_snapshot(int sig)
+{
+       take_snapshot = sig;
+}
+
 int main(int argc, char **argv)
 {
        struct overlay_context ctx;
@@ -566,6 +574,8 @@ int main(int argc, char **argv)
                return 0;
        }
 
+       signal(SIGUSR1, signal_snapshot);
+
        ctx.width = 640;
        ctx.height = 236;
        ctx.surface = x11_overlay_create(POS_TOP_RIGHT, &ctx.width, &ctx.height);
@@ -609,6 +619,13 @@ int main(int argc, char **argv)
                cairo_destroy(ctx.cr);
 
                overlay_show(ctx.surface);
+
+               if (take_snapshot) {
+                       char buf[80];
+                       sprintf(buf, "overlay-snapshot-%d.png", i-1);
+                       cairo_surface_write_to_png(ctx.surface, buf);
+                       take_snapshot = 0;
+               }
        }
 
        return 0;