tests: move fill_color into helpers

There will be a new test program that wants to share this code.

No behavioral changes.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 5 years ago
parent 9c267e5b55
commit f26d17fe03
  1. 43
      tests/subsurface-shot-test.c
  2. 51
      tests/weston-test-client-helper.c
  3. 6
      tests/weston-test-client-helper.h

@ -82,39 +82,6 @@ get_subcompositor(struct client *client)
return sub; 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 static int
check_screen(struct client *client, check_screen(struct client *client,
const char *ref_image, const char *ref_image,
@ -137,7 +104,7 @@ surface_commit_color(struct client *client, struct wl_surface *surface,
struct buffer *buf; struct buffer *buf;
buf = create_shm_buffer_a8r8g8b8(client, width, height); 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_attach(surface, buf->proxy, 0, 0);
wl_surface_damage(surface, 0, 0, width, height); wl_surface_damage(surface, 0, 0, width, height);
wl_surface_commit(surface); wl_surface_commit(surface);
@ -160,10 +127,10 @@ TEST(subsurface_z_order)
pixman_color_t cyan; pixman_color_t cyan;
pixman_color_t green; pixman_color_t green;
color(&red, 255, 0, 0); color_rgb888(&red, 255, 0, 0);
color(&blue, 0, 0, 255); color_rgb888(&blue, 0, 0, 255);
color(&cyan, 0, 255, 255); color_rgb888(&cyan, 0, 255, 255);
color(&green, 0, 255, 0); color_rgb888(&green, 0, 255, 0);
client = create_client_and_test_surface(100, 50, 100, 100); client = create_client_and_test_surface(100, 50, 100, 100);
assert(client); assert(client);

@ -1,6 +1,7 @@
/* /*
* Copyright © 2012 Intel Corporation * 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 * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
@ -1848,3 +1849,51 @@ client_create_viewport(struct client *client)
return viewport; 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;
}

@ -278,4 +278,10 @@ bind_to_singleton_global(struct client *client,
struct wp_viewport * struct wp_viewport *
client_create_viewport(struct client *client); 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 #endif

Loading…
Cancel
Save