diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c index 7f42dbb9..4df9d3dc 100644 --- a/tests/subsurface-shot-test.c +++ b/tests/subsurface-shot-test.c @@ -82,39 +82,6 @@ get_subcompositor(struct client *client) return sub; } -static void -fill_color(pixman_image_t *image, pixman_color_t *color) -{ - pixman_image_t *solid; - int width; - int height; - - width = pixman_image_get_width(image); - height = pixman_image_get_height(image); - - solid = pixman_image_create_solid_fill(color); - pixman_image_composite32(PIXMAN_OP_SRC, - solid, /* src */ - NULL, /* mask */ - image, /* dst */ - 0, 0, /* src x,y */ - 0, 0, /* mask x,y */ - 0, 0, /* dst x,y */ - width, height); - pixman_image_unref(solid); -} - -static pixman_color_t * -color(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b) -{ - tmp->alpha = 65535; - tmp->red = (r << 8) + r; - tmp->green = (g << 8) + g; - tmp->blue = (b << 8) + b; - - return tmp; -} - static int check_screen(struct client *client, const char *ref_image, @@ -137,7 +104,7 @@ surface_commit_color(struct client *client, struct wl_surface *surface, struct buffer *buf; buf = create_shm_buffer_a8r8g8b8(client, width, height); - fill_color(buf->image, color); + fill_image_with_color(buf->image, color); wl_surface_attach(surface, buf->proxy, 0, 0); wl_surface_damage(surface, 0, 0, width, height); wl_surface_commit(surface); @@ -160,10 +127,10 @@ TEST(subsurface_z_order) pixman_color_t cyan; pixman_color_t green; - color(&red, 255, 0, 0); - color(&blue, 0, 0, 255); - color(&cyan, 0, 255, 255); - color(&green, 0, 255, 0); + color_rgb888(&red, 255, 0, 0); + color_rgb888(&blue, 0, 0, 255); + color_rgb888(&cyan, 0, 255, 255); + color_rgb888(&green, 0, 255, 0); client = create_client_and_test_surface(100, 50, 100, 100); assert(client); diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 8711cf0e..94b93eac 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -1,6 +1,7 @@ /* * Copyright © 2012 Intel Corporation - * Copyright 2017 Collabora, Ltd. + * Copyright © 2015 Samsung Electronics Co., Ltd + * Copyright 2016, 2017 Collabora, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -1848,3 +1849,51 @@ client_create_viewport(struct client *client) return viewport; } + +/** + * Fill the image with the given color + * + * \param image The image to write to. + * \param color The color to use. + */ +void +fill_image_with_color(pixman_image_t *image, pixman_color_t *color) +{ + pixman_image_t *solid; + int width; + int height; + + width = pixman_image_get_width(image); + height = pixman_image_get_height(image); + + solid = pixman_image_create_solid_fill(color); + pixman_image_composite32(PIXMAN_OP_SRC, + solid, /* src */ + NULL, /* mask */ + image, /* dst */ + 0, 0, /* src x,y */ + 0, 0, /* mask x,y */ + 0, 0, /* dst x,y */ + width, height); + pixman_image_unref(solid); +} + +/** + * Convert 8-bit RGB to opaque Pixman color + * + * \param tmp Pixman color struct to fill in. + * \param r Red value, 0 - 255. + * \param g Green value, 0 - 255. + * \param b Blue value, 0 - 255. + * \return tmp + */ +pixman_color_t * +color_rgb888(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b) +{ + tmp->alpha = 65535; + tmp->red = (r << 8) + r; + tmp->green = (g << 8) + g; + tmp->blue = (b << 8) + b; + + return tmp; +} diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index 417c62e4..bda330ea 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -278,4 +278,10 @@ bind_to_singleton_global(struct client *client, struct wp_viewport * client_create_viewport(struct client *client); +void +fill_image_with_color(pixman_image_t *image, pixman_color_t *color); + +pixman_color_t * +color_rgb888(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b); + #endif