1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#include <QApplication>
#include <QImage>
#include <QPixmap>
#include <QX11Info>
#include <QPainter>
#include <QString>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xrender.h>
#include <X11/extensions/XShm.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "utils.h"
#include "surface.h"
#include "renderops.h"
int win_w = 320;
int win_h = 320;
Display *disp = NULL;
Window win;
RenderOp all_render_ops[] = {
{"PictOpClear", PictOpClear, 1},
{"PictOpSrc", PictOpSrc, 1},
{"PictOpDst", PictOpDst, 1},
{"PictOpOver", PictOpOver, 1},
{"PictOpOverReverse", PictOpOverReverse, 1},
{"PictOpIn", PictOpIn, 1},
{"PictOpInReverse", PictOpInReverse, 1},
{"PictOpOut", PictOpOut, 1},
{"PictOpOutReverse", PictOpOutReverse, 1},
{"PictOpAtop", PictOpAtop, 1},
{"PictOpAtopReverse", PictOpAtopReverse, 1},
{"PictOpXor", PictOpXor, 1},
{"PictOpAdd", PictOpAdd, 1},
{"PictOpSaturate", PictOpSaturate, 1},
{"PictOpDisjointClear", PictOpDisjointClear, 1},
{"PictOpDisjointSrc", PictOpDisjointSrc, 0},
{"PictOpDisjointDst", PictOpDisjointDst, 0},
{"PictOpDisjointOver", PictOpDisjointOver, 0},
{"PictOpDisjointOverReverse", PictOpDisjointOverReverse, 0},
{"PictOpDisjointIn", PictOpDisjointIn, 0},
{"PictOpDisjointInReverse", PictOpDisjointInReverse, 0},
{"PictOpDisjointOut", PictOpDisjointOut, 0},
{"PictOpDisjointOutReverse", PictOpDisjointOutReverse, 0},
{"PictOpDisjointAtop", PictOpDisjointAtop, 0},
{"PictOpDisjointAtopReverse", PictOpDisjointAtopReverse, 0},
{"PictOpDisjointXor", PictOpDisjointXor, 0},
{"PictOpConjointClear", PictOpConjointClear, 0},
{"PictOpConjointSrc", PictOpConjointSrc, 0},
{"PictOpConjointDst", PictOpConjointDst, 0},
{"PictOpConjointOver", PictOpConjointOver, 0},
{"PictOpConjointOverReverse", PictOpConjointOverReverse, 0},
{"PictOpConjointIn", PictOpConjointIn, 0},
{"PictOpConjointInReverse", PictOpConjointInReverse, 0},
{"PictOpConjointOut", PictOpConjointOut, 0},
{"PictOpConjointOutReverse", PictOpConjointOutReverse, 0},
{"PictOpConjointAtop", PictOpConjointAtop, 0},
{"PictOpConjointAtopReverse", PictOpConjointAtopReverse, 0},
{"PictOpConjointXor", PictOpConjointXor, 0},
{NULL, 0, 0}
};
XRenderSurf *surf_win = NULL;
void
test_oper(int op, XRenderSurf *src, XRenderSurf *mask, XRenderSurf *dst)
{
int x, y;
x = rand() % (surf_win->w - (src->w/2));
y = rand() % (surf_win->h - (src->h/2));
xrender_surf_blend(disp, op, src, mask, dst,
0, 0, 0, 0, x, y, src->w, src->h);
}
void
main_loop(void)
{
RenderOp current_op;
/* printf query filters */
printf("Available XRENDER filters:\n");
{
int i;
XFilters *flt;
flt = XRenderQueryFilters(disp, win);
for (i = 0; i < flt->nfilter; ++i)
printf("\t%s\n", flt->filter[i]);
}
/* setup */
surf_win = xrender_surf_adopt(disp, win, DefaultVisual(disp, DefaultScreen(disp)), win_w, win_h);
populate_from_file(disp, surf_win, ":/res/images/bg1.jpg");
// Create a background tile pixmap
QPixmap bg( 40, 40 );
QPainter p( &bg );
p.fillRect( bg.rect(), QColor( 90, 90, 90 ) );
p.fillRect( QRect(0,0,20,20), QColor( 200, 200, 200 ) );
p.fillRect( QRect(20,20,20,20), QColor( 200, 200, 200 ) );
p.end();
// Change the repeat setting for the bg pixmap so it tiles, and clear the window with it
XRenderPictureAttributes pa;
pa.repeat = true;
XRenderChangePicture(disp, bg.x11PictureHandle(), CPRepeat, &pa );
XRenderComposite(disp, PictOpSrc, bg.x11PictureHandle(), None,
surf_win->pic, 0, 0, 0, 0, 0, 0, win_w, win_h);
XFlush(disp);
int i = 0;
current_op = all_render_ops[i++];
int numberOfScenarios = 0;
TestScenario *scenarios = create_test_scenarios(disp, win, win_w, win_h, &numberOfScenarios);
while (current_op.name)
{
printf("Test: %s\n", current_op.name);
for (int j = 0; j < numberOfScenarios; ++j) {
time_test(scenarios[j].name, test_oper, ¤t_op,
scenarios[j].src, scenarios[j].mask, scenarios[j].dst);
}
current_op = all_render_ops[i++];
XSync(disp, False);
// Change the repeat setting for the bg pixmap so it tiles, and clear the window with it
XRenderPictureAttributes pa;
pa.repeat = true;
XRenderChangePicture(disp, bg.x11PictureHandle(), CPRepeat, &pa );
XRenderComposite(disp, PictOpSrc, bg.x11PictureHandle(), None,
surf_win->pic, 0, 0, 0, 0, 0, 0, win_w, win_h);
srand(7);
}
XSync(disp, False);
}
int
main(int argc, char **argv)
{
QApplication app(argc, argv);
disp = QX11Info::display();
if (!disp)
{
printf("ERROR: Cannot connect to display!\n");
exit(-1);
}
setup_window();
main_loop();
return 0;
}
|