[Mesa-dev] [PATCH 1/2] egl-util: Adds probe_front_pixel_rgb function

Brian Paul brianp at vmware.com
Thu Sep 20 07:34:02 PDT 2012


On 09/20/2012 07:21 AM, Robert Bragg wrote:
> This adds an egl_probe_front_pixel_rgb function that is analogous to
> piglit_probe_pixel_rgba except it probes the front buffer instead of
> probing the back buffer.
> ---
>   tests/egl/egl-util.c |   30 ++++++++++++++++++++++++++++++
>   tests/egl/egl-util.h |    4 ++++
>   2 files changed, 34 insertions(+), 0 deletions(-)
>
> diff --git a/tests/egl/egl-util.c b/tests/egl/egl-util.c
> index 20cd699..e26add4 100644
> --- a/tests/egl/egl-util.c
> +++ b/tests/egl/egl-util.c
> @@ -37,6 +37,36 @@ static int automatic;
>
>   int depth;
>
> +int
> +egl_probe_front_pixel_rgb(struct egl_state *state,
> +			  int x, int y, const float *expected)
> +{
> +	XImage *ximage = XGetImage(state->dpy, state->win,
> +				   x, state->height - y - 1, 1, 1, AllPlanes, ZPixmap);
> +	unsigned long pixel = XGetPixel(ximage, 0, 0);
> +	uint8_t *probe = (uint8_t *)&pixel;
> +	int pass = 1;
> +
> +	XDestroyImage(ximage);
> +
> +	/* NB: XGetPixel returns a normalized BGRA, byte per
> +	 * component, pixel format */

Is that always true?  Don't you need to examine the window's 
XVisualInfo's red/green/blue_mask vales to determine the position of 
the components in the ulong?

In any case, 8-bit BGRA can probably be safely assumed for now.


> +	if (probe[2] != expected[0]*255 ||
> +	    probe[1] != expected[1]*255 ||
> +	    probe[0] != expected[2]*255) {
> +		pass = 0;
> +	}

The other pixel probing functions in piglit use "fabs(probe - 
expected) < piglit_tolerance" when comparing actual/expected values. 
Shouldn't you do that here too?


> +
> +	if (pass)
> +		return 1;
> +
> +	printf("Front Buffer Probe at (%i,%i)\n", x, y);
> +	printf("  Expected: %f %f %f %f\n", expected[0], expected[1], expected[2], expected[3]);
> +	printf("  Observed: %f %f %f %f\n", probe[0]/255.0, probe[1]/255.0, probe[2]/255.0, probe[3]/255.0);
> +
> +	return 0;
> +}
> +
>   void
>   egl_init_test(struct egl_test *test)
>   {
> diff --git a/tests/egl/egl-util.h b/tests/egl/egl-util.h
> index 87c2db3..e1caa94 100644
> --- a/tests/egl/egl-util.h
> +++ b/tests/egl/egl-util.h
> @@ -62,4 +62,8 @@ egl_util_create_pixmap(struct egl_state *state,
>
>   int egl_util_run(const struct egl_test *test, int argc, char *argv[]);
>
> +int
> +egl_probe_front_pixel_rgb(struct egl_state *state,
> +			  int x, int y, const float *expected);
> +
>   #endif

-Brian


More information about the mesa-dev mailing list