lowlevel-blt-bench.c revision 03b705cf
1/*
2 * Copyright © 2009 Nokia Corporation
3 * Copyright © 2010 Movial Creative Technologies Oy
4 * Copyright © 2013 Intel Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <stdint.h>
30#include <stdbool.h>
31
32#include <X11/X.h>
33#include <X11/Xutil.h> /* for XDestroyImage */
34#include <pixman.h> /* for pixman blt functions */
35
36#include "test.h"
37
38static const struct format {
39	const char *name;
40	pixman_format_code_t pixman_format;
41} formats[] = {
42	{ "a8r8g8b8", PIXMAN_a8r8g8b8 },
43	{ "x8r8g8b8", PIXMAN_x8r8g8b8 },
44	{ "a8", PIXMAN_a8 },
45	{ "a4", PIXMAN_a4 },
46	{ "a1", PIXMAN_a1 },
47};
48
49static const struct op {
50	const char *name;
51} ops[] = {
52	[PictOpClear] = { "Clear" },
53	[PictOpSrc] = { "Src" },
54	[PictOpDst] = { "Dst" },
55	[PictOpOver] = { "Over" },
56	[PictOpOverReverse] = { "OverReverse" },
57	[PictOpIn] = { "In" },
58	[PictOpInReverse] = { "InReverse" },
59	[PictOpOut] = { "Out" },
60	[PictOpOutReverse] = { "OutReverse" },
61	[PictOpAtop] = { "Atop" },
62	[PictOpAtopReverse] = { "AtopReverse" },
63	[PictOpXor] = { "Xor" },
64	[PictOpAdd] = { "Add" },
65	[PictOpSaturate] = { "Saturate" },
66};
67
68static double _bench(struct test_display *t, enum target target_type,
69		     int op, int src_format,
70		     int loops)
71{
72	XRenderColor render_color = { 0x8000, 0x8000, 0x8000, 0x8000 };
73	struct test_target target;
74	Pixmap pixmap;
75	Picture picture;
76	struct timespec tv;
77	double elapsed;
78
79	test_target_create_render(t, target_type, &target);
80	XRenderFillRectangle(t->dpy, PictOpClear, target.picture, &render_color,
81			     0, 0, target.width, target.height);
82
83	pixmap = XCreatePixmap(t->dpy, t->root,
84			       target.width, target.height,
85			       PIXMAN_FORMAT_DEPTH(formats[src_format].pixman_format));
86
87	picture = XRenderCreatePicture(t->dpy, pixmap,
88				       XRenderFindStandardFormat(t->dpy, src_format),
89				       0, NULL);
90	XRenderFillRectangle(t->dpy, PictOpSrc, picture, &render_color,
91			     0, 0, target.width, target.height);
92
93	test_timer_start(t, &tv);
94	while (loops--)
95		XRenderComposite(t->dpy, op,
96				 picture, 0, target.picture,
97				 0, 0,
98				 0, 0,
99				 0, 0,
100				 target.width, target.height);
101	elapsed = test_timer_stop(t, &tv);
102
103	XRenderFreePicture(t->dpy, picture);
104	XFreePixmap(t->dpy, pixmap);
105	test_target_destroy_render(t, &target);
106
107	return elapsed;
108}
109
110static void bench(struct test *t, enum target target, int op, int sf)
111{
112	double real, ref;
113
114	ref = _bench(&t->ref, target, op, sf, 1000);
115	real = _bench(&t->real, target, op, sf, 1000);
116
117	fprintf (stdout, "Testing %s with %s: ref=%f, real=%f\n",
118		 formats[sf].name, ops[op].name, ref, real);
119}
120
121int main(int argc, char **argv)
122{
123	struct test test;
124	int op, sf;
125
126	test_init(&test, argc, argv);
127
128	for (op = 0; op < sizeof(ops)/sizeof(ops[0]); op++) {
129		for (sf = 0; sf < sizeof(formats)/sizeof(formats[0]); sf++)
130			bench(&test, ROOT, op, sf);
131		fprintf (stdout, "\n");
132	}
133
134	return 0;
135}
136