Refactor out the screenshot shm buffer creation code.

Signed-off-by: Bryce Harrington <[email protected]>
---
 tests/internal-screenshot-test.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/tests/internal-screenshot-test.c b/tests/internal-screenshot-test.c
index 7f1a690..3f8dcba 100644
--- a/tests/internal-screenshot-test.c
+++ b/tests/internal-screenshot-test.c
@@ -59,6 +59,33 @@ write_surface_as_png(const struct surface* weston_surface, 
const char *fname) {
        return true;
 }
 
+/** create_screenshot_surface()
+ *
+ *  Allocates and initializes a weston test surface for use in
+ *  storing a screenshot of the client's output.  Establishes a
+ *  shm backed wl_buffer for retrieving screenshot image data
+ *  from the server, sized to match the client's output display.
+ *
+ *  @returns stack allocated surface image, which should be
+ *  free'd when done using it.
+ */
+static struct surface*
+create_screenshot_surface(struct client *client) {
+       struct surface* screenshot;
+       screenshot = xzalloc(sizeof *screenshot);
+       if (screenshot == NULL)
+               return NULL;
+       screenshot->wl_buffer = create_shm_buffer(client,                       
                                      
+                                                 client->output->width,        
                                      
+                                                 client->output->height,       
                                      
+                                                 &screenshot->data);           
                                      
+       screenshot->height = client->output->height;                            
                                      
+       screenshot->width = client->output->width;                              
                                      
+       screenshot->stride = screenshot->width * 4;  /* FIXME bpp? */           
                                       
+
+       return screenshot;
+}
+
 TEST(internal_screenshot)
 {
        struct client *client;
@@ -79,18 +106,8 @@ TEST(internal_screenshot)
        printf("Client created\n");
 
        /* Create a surface to hold the screenshot */
-       screenshot = xzalloc(sizeof *screenshot);
+       screenshot = create_screenshot_surface(client);
        assert(screenshot);
-
-       /* Create and attach buffer to our surface */
-       screenshot->wl_buffer = create_shm_buffer(client,
-                                                 client->output->width,
-                                                 client->output->height,
-                                                 &screenshot->data);
-       screenshot->height = client->output->height;
-       screenshot->width = client->output->width;
-       assert(screenshot->wl_buffer);
-       screenshot->stride = screenshot->width * 4;  /* meh */
        printf("Screenshot buffer created and attached to surface\n");
 
        /* Take a snapshot.  Result will be in screenshot->wl_buffer. */
-- 
1.9.1

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to