lowlevel-blt-bench.c revision 03b705cf
103b705cfSriastradh/*
203b705cfSriastradh * Copyright © 2009 Nokia Corporation
303b705cfSriastradh * Copyright © 2010 Movial Creative Technologies Oy
403b705cfSriastradh * Copyright © 2013 Intel Corporation
503b705cfSriastradh *
603b705cfSriastradh * Permission is hereby granted, free of charge, to any person obtaining a
703b705cfSriastradh * copy of this software and associated documentation files (the "Software"),
803b705cfSriastradh * to deal in the Software without restriction, including without limitation
903b705cfSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1003b705cfSriastradh * and/or sell copies of the Software, and to permit persons to whom the
1103b705cfSriastradh * Software is furnished to do so, subject to the following conditions:
1203b705cfSriastradh *
1303b705cfSriastradh * The above copyright notice and this permission notice (including the next
1403b705cfSriastradh * paragraph) shall be included in all copies or substantial portions of the
1503b705cfSriastradh * Software.
1603b705cfSriastradh *
1703b705cfSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1803b705cfSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1903b705cfSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2003b705cfSriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2103b705cfSriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2203b705cfSriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2303b705cfSriastradh * DEALINGS IN THE SOFTWARE.
2403b705cfSriastradh */
2503b705cfSriastradh
2603b705cfSriastradh#include <stdio.h>
2703b705cfSriastradh#include <stdlib.h>
2803b705cfSriastradh#include <string.h>
2903b705cfSriastradh#include <stdint.h>
3003b705cfSriastradh#include <stdbool.h>
3103b705cfSriastradh
3203b705cfSriastradh#include <X11/X.h>
3303b705cfSriastradh#include <X11/Xutil.h> /* for XDestroyImage */
3403b705cfSriastradh#include <pixman.h> /* for pixman blt functions */
3503b705cfSriastradh
3603b705cfSriastradh#include "test.h"
3703b705cfSriastradh
3803b705cfSriastradhstatic const struct format {
3903b705cfSriastradh	const char *name;
4003b705cfSriastradh	pixman_format_code_t pixman_format;
4103b705cfSriastradh} formats[] = {
4203b705cfSriastradh	{ "a8r8g8b8", PIXMAN_a8r8g8b8 },
4303b705cfSriastradh	{ "x8r8g8b8", PIXMAN_x8r8g8b8 },
4403b705cfSriastradh	{ "a8", PIXMAN_a8 },
4503b705cfSriastradh	{ "a4", PIXMAN_a4 },
4603b705cfSriastradh	{ "a1", PIXMAN_a1 },
4703b705cfSriastradh};
4803b705cfSriastradh
4903b705cfSriastradhstatic const struct op {
5003b705cfSriastradh	const char *name;
5103b705cfSriastradh} ops[] = {
5203b705cfSriastradh	[PictOpClear] = { "Clear" },
5303b705cfSriastradh	[PictOpSrc] = { "Src" },
5403b705cfSriastradh	[PictOpDst] = { "Dst" },
5503b705cfSriastradh	[PictOpOver] = { "Over" },
5603b705cfSriastradh	[PictOpOverReverse] = { "OverReverse" },
5703b705cfSriastradh	[PictOpIn] = { "In" },
5803b705cfSriastradh	[PictOpInReverse] = { "InReverse" },
5903b705cfSriastradh	[PictOpOut] = { "Out" },
6003b705cfSriastradh	[PictOpOutReverse] = { "OutReverse" },
6103b705cfSriastradh	[PictOpAtop] = { "Atop" },
6203b705cfSriastradh	[PictOpAtopReverse] = { "AtopReverse" },
6303b705cfSriastradh	[PictOpXor] = { "Xor" },
6403b705cfSriastradh	[PictOpAdd] = { "Add" },
6503b705cfSriastradh	[PictOpSaturate] = { "Saturate" },
6603b705cfSriastradh};
6703b705cfSriastradh
6803b705cfSriastradhstatic double _bench(struct test_display *t, enum target target_type,
6903b705cfSriastradh		     int op, int src_format,
7003b705cfSriastradh		     int loops)
7103b705cfSriastradh{
7203b705cfSriastradh	XRenderColor render_color = { 0x8000, 0x8000, 0x8000, 0x8000 };
7303b705cfSriastradh	struct test_target target;
7403b705cfSriastradh	Pixmap pixmap;
7503b705cfSriastradh	Picture picture;
7603b705cfSriastradh	struct timespec tv;
7703b705cfSriastradh	double elapsed;
7803b705cfSriastradh
7903b705cfSriastradh	test_target_create_render(t, target_type, &target);
8003b705cfSriastradh	XRenderFillRectangle(t->dpy, PictOpClear, target.picture, &render_color,
8103b705cfSriastradh			     0, 0, target.width, target.height);
8203b705cfSriastradh
8303b705cfSriastradh	pixmap = XCreatePixmap(t->dpy, t->root,
8403b705cfSriastradh			       target.width, target.height,
8503b705cfSriastradh			       PIXMAN_FORMAT_DEPTH(formats[src_format].pixman_format));
8603b705cfSriastradh
8703b705cfSriastradh	picture = XRenderCreatePicture(t->dpy, pixmap,
8803b705cfSriastradh				       XRenderFindStandardFormat(t->dpy, src_format),
8903b705cfSriastradh				       0, NULL);
9003b705cfSriastradh	XRenderFillRectangle(t->dpy, PictOpSrc, picture, &render_color,
9103b705cfSriastradh			     0, 0, target.width, target.height);
9203b705cfSriastradh
9303b705cfSriastradh	test_timer_start(t, &tv);
9403b705cfSriastradh	while (loops--)
9503b705cfSriastradh		XRenderComposite(t->dpy, op,
9603b705cfSriastradh				 picture, 0, target.picture,
9703b705cfSriastradh				 0, 0,
9803b705cfSriastradh				 0, 0,
9903b705cfSriastradh				 0, 0,
10003b705cfSriastradh				 target.width, target.height);
10103b705cfSriastradh	elapsed = test_timer_stop(t, &tv);
10203b705cfSriastradh
10303b705cfSriastradh	XRenderFreePicture(t->dpy, picture);
10403b705cfSriastradh	XFreePixmap(t->dpy, pixmap);
10503b705cfSriastradh	test_target_destroy_render(t, &target);
10603b705cfSriastradh
10703b705cfSriastradh	return elapsed;
10803b705cfSriastradh}
10903b705cfSriastradh
11003b705cfSriastradhstatic void bench(struct test *t, enum target target, int op, int sf)
11103b705cfSriastradh{
11203b705cfSriastradh	double real, ref;
11303b705cfSriastradh
11403b705cfSriastradh	ref = _bench(&t->ref, target, op, sf, 1000);
11503b705cfSriastradh	real = _bench(&t->real, target, op, sf, 1000);
11603b705cfSriastradh
11703b705cfSriastradh	fprintf (stdout, "Testing %s with %s: ref=%f, real=%f\n",
11803b705cfSriastradh		 formats[sf].name, ops[op].name, ref, real);
11903b705cfSriastradh}
12003b705cfSriastradh
12103b705cfSriastradhint main(int argc, char **argv)
12203b705cfSriastradh{
12303b705cfSriastradh	struct test test;
12403b705cfSriastradh	int op, sf;
12503b705cfSriastradh
12603b705cfSriastradh	test_init(&test, argc, argv);
12703b705cfSriastradh
12803b705cfSriastradh	for (op = 0; op < sizeof(ops)/sizeof(ops[0]); op++) {
12903b705cfSriastradh		for (sf = 0; sf < sizeof(formats)/sizeof(formats[0]); sf++)
13003b705cfSriastradh			bench(&test, ROOT, op, sf);
13103b705cfSriastradh		fprintf (stdout, "\n");
13203b705cfSriastradh	}
13303b705cfSriastradh
13403b705cfSriastradh	return 0;
13503b705cfSriastradh}
136