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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* Copyright © 2011 Dave Airlie
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting documentation, and
* that the name of the copyright holders not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. The copyright holders make no representations
* about the suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <limits.h>
#include <stdio.h>
#include <X11/Xlib.h>
/* we need to be able to manipulate the Display structure on events */
#include <X11/Xlibint.h>
#include <X11/extensions/render.h>
#include <X11/extensions/Xrender.h>
#include "Xrandrint.h"
XRRProviderResources *
XRRGetProviderResources(Display *dpy, Window window)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRGetProvidersReply rep;
xRRGetProvidersReq *req;
XRRProviderResources *xrpr;
long nbytes, nbytesRead;
int rbytes;
RRCheckExtension (dpy, info, NULL);
LockDisplay (dpy);
GetReq(RRGetProviders, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRGetProviders;
req->window = window;
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
{
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
if (rep.length < INT_MAX >> 2) {
nbytes = (long) rep.length << 2;
nbytesRead = (long) (rep.nProviders * 4);
rbytes = (sizeof(XRRProviderResources) + rep.nProviders *
sizeof(RRProvider));
xrpr = Xmalloc(rbytes);
} else {
nbytes = 0;
nbytesRead = 0;
rbytes = 0;
xrpr = NULL;
}
if (xrpr == NULL) {
_XEatDataWords (dpy, rep.length);
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
xrpr->timestamp = rep.timestamp;
xrpr->nproviders = rep.nProviders;
xrpr->providers = (RRProvider *)(xrpr + 1);
_XRead32(dpy, (long *) xrpr->providers, rep.nProviders << 2);
if (nbytes > nbytesRead)
_XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
UnlockDisplay (dpy);
SyncHandle();
return (XRRProviderResources *) xrpr;
}
void
XRRFreeProviderResources(XRRProviderResources *provider_resources)
{
free(provider_resources);
}
XRRProviderInfo *
XRRGetProviderInfo(Display *dpy, XRRScreenResources *resources, RRProvider provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRGetProviderInfoReply rep;
xRRGetProviderInfoReq *req;
int nbytes, nbytesRead, rbytes;
XRRProviderInfo *xpi;
RRCheckExtension (dpy, info, NULL);
LockDisplay (dpy);
GetReq (RRGetProviderInfo, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRGetProviderInfo;
req->provider = provider;
req->configTimestamp = resources->configTimestamp;
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
{
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
if (rep.length > INT_MAX >> 2)
{
_XEatDataWords (dpy, rep.length);
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
nbytes = ((long) rep.length << 2);
nbytesRead = (long)(rep.nCrtcs * 4 +
rep.nOutputs * 4 +
rep.nAssociatedProviders * 8 +
((rep.nameLength + 3) & ~3));
rbytes = (sizeof(XRRProviderInfo) +
rep.nCrtcs * sizeof(RRCrtc) +
rep.nOutputs * sizeof(RROutput) +
rep.nAssociatedProviders * (sizeof(RRProvider) + sizeof(unsigned int))+
rep.nameLength + 1);
xpi = Xmalloc(rbytes);
if (xpi == NULL) {
_XEatDataWords (dpy, rep.length);
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
xpi->capabilities = rep.capabilities;
xpi->ncrtcs = rep.nCrtcs;
xpi->noutputs = rep.nOutputs;
xpi->nassociatedproviders = rep.nAssociatedProviders;
xpi->crtcs = (RRCrtc *)(xpi + 1);
xpi->outputs = (RROutput *)(xpi->crtcs + rep.nCrtcs);
xpi->associated_providers = (RRProvider *)(xpi->outputs + rep.nOutputs);
xpi->associated_capability = (unsigned int *)(xpi->associated_providers + rep.nAssociatedProviders);
xpi->name = (char *)(xpi->associated_capability + rep.nAssociatedProviders);
_XRead32(dpy, (long *) xpi->crtcs, rep.nCrtcs << 2);
_XRead32(dpy, (long *) xpi->outputs, rep.nOutputs << 2);
_XRead32(dpy, (long *) xpi->associated_providers, rep.nAssociatedProviders << 2);
/*
* _XRead32 reads a series of 32-bit values from the protocol and writes
* them out as a series of "long int" values, but associated_capability
* is defined as unsigned int *, so that won't work for this array.
* Instead we assume for now that "unsigned int" is also 32-bits, so
* the values can be read without any conversion.
*/
_XRead(dpy, (char *) xpi->associated_capability,
rep.nAssociatedProviders << 2);
_XReadPad(dpy, xpi->name, rep.nameLength);
xpi->name[rep.nameLength] = '\0';
/*
* Skip any extra data
*/
if (nbytes > nbytesRead)
_XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
UnlockDisplay (dpy);
SyncHandle ();
return (XRRProviderInfo *) xpi;
}
void
XRRFreeProviderInfo(XRRProviderInfo *provider)
{
free(provider);
}
int
XRRSetProviderOutputSource(Display *dpy, XID provider,
XID source_provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetProviderOutputSourceReq *req;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRSetProviderOutputSource, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetProviderOutputSource;
req->provider = provider;
req->source_provider = source_provider;
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
int
XRRSetProviderOffloadSink(Display *dpy, XID provider,
XID sink_provider)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRSetProviderOffloadSinkReq *req;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRSetProviderOffloadSink, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRSetProviderOffloadSink;
req->provider = provider;
req->sink_provider = sink_provider;
UnlockDisplay (dpy);
SyncHandle ();
return 0;
}
|