Bug Summary

File:randr/rrscreen.c
Location:line 936, column 9
Description:Value stored to 'time' is never read

Annotated Source Code

1/*
2 * Copyright © 2006 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include "randrstr.h"
24
25static CARD16
26 RR10CurrentSizeID(ScreenPtr pScreen);
27
28/*
29 * Edit connection information block so that new clients
30 * see the current screen size on connect
31 */
32static void
33RREditConnectionInfo(ScreenPtr pScreen)
34{
35 xConnSetup *connSetup;
36 char *vendor;
37 xPixmapFormat *formats;
38 xWindowRoot *root;
39 xDepth *depth;
40 xVisualType *visual;
41 int screen = 0;
42 int d;
43
44 connSetup = (xConnSetup *) ConnectionInfo;
45 vendor = (char *) connSetup + sizeof(xConnSetup);
46 formats = (xPixmapFormat *) ((char *) vendor +
47 pad_to_int32(connSetup->nbytesVendor));
48 root = (xWindowRoot *) ((char *) formats +
49 sizeof(xPixmapFormat) *
50 screenInfo.numPixmapFormats);
51 while (screen != pScreen->myNum) {
52 depth = (xDepth *) ((char *) root + sizeof(xWindowRoot));
53 for (d = 0; d < root->nDepths; d++) {
54 visual = (xVisualType *) ((char *) depth + sizeof(xDepth));
55 depth = (xDepth *) ((char *) visual +
56 depth->nVisuals * sizeof(xVisualType));
57 }
58 root = (xWindowRoot *) ((char *) depth);
59 screen++;
60 }
61 root->pixWidth = pScreen->width;
62 root->pixHeight = pScreen->height;
63 root->mmWidth = pScreen->mmWidth;
64 root->mmHeight = pScreen->mmHeight;
65}
66
67void
68RRSendConfigNotify(ScreenPtr pScreen)
69{
70 WindowPtr pWin = pScreen->root;
71 xEvent event = {
72 .u.configureNotify.window = pWin->drawable.id,
73 .u.configureNotify.aboveSibling = None0L,
74 .u.configureNotify.x = 0,
75 .u.configureNotify.y = 0,
76
77 /* XXX xinerama stuff ? */
78
79 .u.configureNotify.width = pWin->drawable.width,
80 .u.configureNotify.height = pWin->drawable.height,
81 .u.configureNotify.borderWidth = wBorderWidth(pWin)((int) (pWin)->borderWidth),
82 .u.configureNotify.override = pWin->overrideRedirect
83 };
84 event.u.u.type = ConfigureNotify22;
85 DeliverEvents(pWin, &event, 1, NullWindow((WindowPtr) 0));
86}
87
88void
89RRDeliverScreenEvent(ClientPtr client, WindowPtr pWin, ScreenPtr pScreen)
90{
91 rrScrPriv(pScreen)rrScrPrivPtr pScrPriv = ((rrScrPrivPtr)dixLookupPrivate(&
(pScreen)->devPrivates, (&rrPrivKeyRec)))
;
92 RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL((void*)0);
93 WindowPtr pRoot = pScreen->root;
94
95 xRRScreenChangeNotifyEvent se = {
96 .type = RRScreenChangeNotify0 + RREventBase,
97 .rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_01),
98 .timestamp = pScrPriv->lastSetTime.milliseconds,
99 .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
100 .root = pRoot->drawable.id,
101 .window = pWin->drawable.id,
102 .subpixelOrder = PictureGetSubpixelOrder(pScreen),
103
104 .sizeID = RR10CurrentSizeID(pScreen)
105 };
106
107 if (se.rotation & (RR_Rotate_902 | RR_Rotate_2708)) {
108 se.widthInPixels = pScreen->height;
109 se.heightInPixels = pScreen->width;
110 se.widthInMillimeters = pScreen->mmHeight;
111 se.heightInMillimeters = pScreen->mmWidth;
112 }
113 else {
114 se.widthInPixels = pScreen->width;
115 se.heightInPixels = pScreen->height;
116 se.widthInMillimeters = pScreen->mmWidth;
117 se.heightInMillimeters = pScreen->mmHeight;
118 }
119
120 WriteEventsToClient(client, 1, (xEvent *) &se);
121}
122
123/*
124 * Notify the extension that the screen size has been changed.
125 * The driver is responsible for calling this whenever it has changed
126 * the size of the screen
127 */
128void
129RRScreenSizeNotify(ScreenPtr pScreen)
130{
131 rrScrPriv(pScreen)rrScrPrivPtr pScrPriv = ((rrScrPrivPtr)dixLookupPrivate(&
(pScreen)->devPrivates, (&rrPrivKeyRec)))
;
132 /*
133 * Deliver ConfigureNotify events when root changes
134 * pixel size
135 */
136 if (pScrPriv->width == pScreen->width &&
137 pScrPriv->height == pScreen->height &&
138 pScrPriv->mmWidth == pScreen->mmWidth &&
139 pScrPriv->mmHeight == pScreen->mmHeight)
140 return;
141
142 pScrPriv->width = pScreen->width;
143 pScrPriv->height = pScreen->height;
144 pScrPriv->mmWidth = pScreen->mmWidth;
145 pScrPriv->mmHeight = pScreen->mmHeight;
146 RRSetChanged(pScreen);
147/* pScrPriv->sizeChanged = TRUE; */
148
149 RRTellChanged(pScreen);
150 RRSendConfigNotify(pScreen);
151 RREditConnectionInfo(pScreen);
152
153 RRPointerScreenConfigured(pScreen);
154 /*
155 * Fix pointer bounds and location
156 */
157 ScreenRestructured(pScreen);
158}
159
160/*
161 * Request that the screen be resized
162 */
163Bool
164RRScreenSizeSet(ScreenPtr pScreen,
165 CARD16 width, CARD16 height, CARD32 mmWidth, CARD32 mmHeight)
166{
167 rrScrPriv(pScreen)rrScrPrivPtr pScrPriv = ((rrScrPrivPtr)dixLookupPrivate(&
(pScreen)->devPrivates, (&rrPrivKeyRec)))
;
168
169#if RANDR_12_INTERFACE1
170 if (pScrPriv->rrScreenSetSize) {
171 return (*pScrPriv->rrScreenSetSize) (pScreen,
172 width, height, mmWidth, mmHeight);
173 }
174#endif
175#if RANDR_10_INTERFACE1
176 if (pScrPriv->rrSetConfig) {
177 return TRUE1; /* can't set size separately */
178 }
179#endif
180 return FALSE0;
181}
182
183/*
184 * Retrieve valid screen size range
185 */
186int
187ProcRRGetScreenSizeRange(ClientPtr client)
188{
189 REQUEST(xRRGetScreenSizeRangeReq)xRRGetScreenSizeRangeReq *stuff = (xRRGetScreenSizeRangeReq *
)client->requestBuffer
;
190 xRRGetScreenSizeRangeReply rep;
191 WindowPtr pWin;
192 ScreenPtr pScreen;
193 rrScrPrivPtr pScrPriv;
194 int rc;
195
196 REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq)if ((sizeof(xRRGetScreenSizeRangeReq) >> 2) != client->
req_len) return(16)
;
197 rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4));
198 if (rc != Success0)
199 return rc;
200
201 pScreen = pWin->drawable.pScreen;
202 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
203
204 rep = (xRRGetScreenSizeRangeReply) {
205 .type = X_Reply1,
206 .pad = 0,
207 .sequenceNumber = client->sequence,
208 .length = 0
209 };
210
211 if (pScrPriv) {
212 if (!RRGetInfo(pScreen, FALSE0))
213 return BadAlloc11;
214 rep.minWidth = pScrPriv->minWidth;
215 rep.minHeight = pScrPriv->minHeight;
216 rep.maxWidth = pScrPriv->maxWidth;
217 rep.maxHeight = pScrPriv->maxHeight;
218 }
219 else {
220 rep.maxWidth = rep.minWidth = pScreen->width;
221 rep.maxHeight = rep.minHeight = pScreen->height;
222 }
223 if (client->swapped) {
224 swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber
) & 1) && ((uintptr_t)(&rep.sequenceNumber) &
1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber
)); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); }
while (0)
;
225 swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.length) & 3) && ((uintptr_t
)(&rep.length) & 3) == 0) *(&rep.length) = lswapl
(*(&rep.length)); else swap_uint32((uint32_t *)(&rep.
length)); } while (0)
;
226 swaps(&rep.minWidth)do { if (sizeof(*(&rep.minWidth)) != 2) wrong_size(); if (
__builtin_constant_p((uintptr_t)(&rep.minWidth) & 1) &&
((uintptr_t)(&rep.minWidth) & 1) == 0) *(&rep.minWidth
) = lswaps(*(&rep.minWidth)); else swap_uint16((uint16_t *
)(&rep.minWidth)); } while (0)
;
227 swaps(&rep.minHeight)do { if (sizeof(*(&rep.minHeight)) != 2) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.minHeight) & 1
) && ((uintptr_t)(&rep.minHeight) & 1) == 0) *
(&rep.minHeight) = lswaps(*(&rep.minHeight)); else swap_uint16
((uint16_t *)(&rep.minHeight)); } while (0)
;
228 swaps(&rep.maxWidth)do { if (sizeof(*(&rep.maxWidth)) != 2) wrong_size(); if (
__builtin_constant_p((uintptr_t)(&rep.maxWidth) & 1) &&
((uintptr_t)(&rep.maxWidth) & 1) == 0) *(&rep.maxWidth
) = lswaps(*(&rep.maxWidth)); else swap_uint16((uint16_t *
)(&rep.maxWidth)); } while (0)
;
229 swaps(&rep.maxHeight)do { if (sizeof(*(&rep.maxHeight)) != 2) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.maxHeight) & 1
) && ((uintptr_t)(&rep.maxHeight) & 1) == 0) *
(&rep.maxHeight) = lswaps(*(&rep.maxHeight)); else swap_uint16
((uint16_t *)(&rep.maxHeight)); } while (0)
;
230 }
231 WriteToClient(client, sizeof(xRRGetScreenSizeRangeReply), &rep);
232 return Success0;
233}
234
235int
236ProcRRSetScreenSize(ClientPtr client)
237{
238 REQUEST(xRRSetScreenSizeReq)xRRSetScreenSizeReq *stuff = (xRRSetScreenSizeReq *)client->
requestBuffer
;
239 WindowPtr pWin;
240 ScreenPtr pScreen;
241 rrScrPrivPtr pScrPriv;
242 int i, rc;
243
244 REQUEST_SIZE_MATCH(xRRSetScreenSizeReq)if ((sizeof(xRRSetScreenSizeReq) >> 2) != client->req_len
) return(16)
;
245 rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4));
246 if (rc != Success0)
247 return rc;
248
249 pScreen = pWin->drawable.pScreen;
250 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
251 if (!pScrPriv)
252 return BadMatch8;
253
254 if (stuff->width < pScrPriv->minWidth || pScrPriv->maxWidth < stuff->width) {
255 client->errorValue = stuff->width;
256 return BadValue2;
257 }
258 if (stuff->height < pScrPriv->minHeight ||
259 pScrPriv->maxHeight < stuff->height) {
260 client->errorValue = stuff->height;
261 return BadValue2;
262 }
263 for (i = 0; i < pScrPriv->numCrtcs; i++) {
264 RRCrtcPtr crtc = pScrPriv->crtcs[i];
265 RRModePtr mode = crtc->mode;
266
267 if (mode) {
268 int source_width = mode->mode.width;
269 int source_height = mode->mode.height;
270 Rotation rotation = crtc->rotation;
271
272 if (rotation == RR_Rotate_902 || rotation == RR_Rotate_2708) {
273 source_width = mode->mode.height;
274 source_height = mode->mode.width;
275 }
276
277 if (crtc->x + source_width > stuff->width ||
278 crtc->y + source_height > stuff->height)
279 return BadMatch8;
280 }
281 }
282 if (stuff->widthInMillimeters == 0 || stuff->heightInMillimeters == 0) {
283 client->errorValue = 0;
284 return BadValue2;
285 }
286 if (!RRScreenSizeSet(pScreen,
287 stuff->width, stuff->height,
288 stuff->widthInMillimeters,
289 stuff->heightInMillimeters)) {
290 return BadMatch8;
291 }
292 return Success0;
293}
294
295
296#define update_totals(gpuscreen, pScrPriv)do { total_crtcs += pScrPriv->numCrtcs; total_outputs += pScrPriv
->numOutputs; modes = RRModesForScreen(gpuscreen, &num_modes
); if (!modes) return 11; for (j = 0; j < num_modes; j++) total_name_len
+= modes[j]->mode.nameLength; total_modes += num_modes; free
(modes); } while(0)
do { \
297 total_crtcs += pScrPriv->numCrtcs; \
298 total_outputs += pScrPriv->numOutputs; \
299 modes = RRModesForScreen(gpuscreen, &num_modes); \
300 if (!modes) \
301 return BadAlloc11; \
302 for (j = 0; j < num_modes; j++) \
303 total_name_len += modes[j]->mode.nameLength; \
304 total_modes += num_modes; \
305 free(modes); \
306} while(0)
307
308static inline void swap_modeinfos(xRRModeInfo *modeinfos, int i)
309{
310 swapl(&modeinfos[i].id)do { if (sizeof(*(&modeinfos[i].id)) != 4) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&modeinfos[i].id) &
3) && ((uintptr_t)(&modeinfos[i].id) & 3) ==
0) *(&modeinfos[i].id) = lswapl(*(&modeinfos[i].id))
; else swap_uint32((uint32_t *)(&modeinfos[i].id)); } while
(0)
;
311 swaps(&modeinfos[i].width)do { if (sizeof(*(&modeinfos[i].width)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].width
) & 1) && ((uintptr_t)(&modeinfos[i].width) &
1) == 0) *(&modeinfos[i].width) = lswaps(*(&modeinfos
[i].width)); else swap_uint16((uint16_t *)(&modeinfos[i].
width)); } while (0)
;
312 swaps(&modeinfos[i].height)do { if (sizeof(*(&modeinfos[i].height)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].height
) & 1) && ((uintptr_t)(&modeinfos[i].height) &
1) == 0) *(&modeinfos[i].height) = lswaps(*(&modeinfos
[i].height)); else swap_uint16((uint16_t *)(&modeinfos[i]
.height)); } while (0)
;
313 swapl(&modeinfos[i].dotClock)do { if (sizeof(*(&modeinfos[i].dotClock)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].dotClock
) & 3) && ((uintptr_t)(&modeinfos[i].dotClock
) & 3) == 0) *(&modeinfos[i].dotClock) = lswapl(*(&
modeinfos[i].dotClock)); else swap_uint32((uint32_t *)(&modeinfos
[i].dotClock)); } while (0)
;
314 swaps(&modeinfos[i].hSyncStart)do { if (sizeof(*(&modeinfos[i].hSyncStart)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hSyncStart
) & 1) && ((uintptr_t)(&modeinfos[i].hSyncStart
) & 1) == 0) *(&modeinfos[i].hSyncStart) = lswaps(*(&
modeinfos[i].hSyncStart)); else swap_uint16((uint16_t *)(&
modeinfos[i].hSyncStart)); } while (0)
;
315 swaps(&modeinfos[i].hSyncEnd)do { if (sizeof(*(&modeinfos[i].hSyncEnd)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hSyncEnd
) & 1) && ((uintptr_t)(&modeinfos[i].hSyncEnd
) & 1) == 0) *(&modeinfos[i].hSyncEnd) = lswaps(*(&
modeinfos[i].hSyncEnd)); else swap_uint16((uint16_t *)(&modeinfos
[i].hSyncEnd)); } while (0)
;
316 swaps(&modeinfos[i].hTotal)do { if (sizeof(*(&modeinfos[i].hTotal)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hTotal
) & 1) && ((uintptr_t)(&modeinfos[i].hTotal) &
1) == 0) *(&modeinfos[i].hTotal) = lswaps(*(&modeinfos
[i].hTotal)); else swap_uint16((uint16_t *)(&modeinfos[i]
.hTotal)); } while (0)
;
317 swaps(&modeinfos[i].hSkew)do { if (sizeof(*(&modeinfos[i].hSkew)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hSkew
) & 1) && ((uintptr_t)(&modeinfos[i].hSkew) &
1) == 0) *(&modeinfos[i].hSkew) = lswaps(*(&modeinfos
[i].hSkew)); else swap_uint16((uint16_t *)(&modeinfos[i].
hSkew)); } while (0)
;
318 swaps(&modeinfos[i].vSyncStart)do { if (sizeof(*(&modeinfos[i].vSyncStart)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].vSyncStart
) & 1) && ((uintptr_t)(&modeinfos[i].vSyncStart
) & 1) == 0) *(&modeinfos[i].vSyncStart) = lswaps(*(&
modeinfos[i].vSyncStart)); else swap_uint16((uint16_t *)(&
modeinfos[i].vSyncStart)); } while (0)
;
319 swaps(&modeinfos[i].vSyncEnd)do { if (sizeof(*(&modeinfos[i].vSyncEnd)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].vSyncEnd
) & 1) && ((uintptr_t)(&modeinfos[i].vSyncEnd
) & 1) == 0) *(&modeinfos[i].vSyncEnd) = lswaps(*(&
modeinfos[i].vSyncEnd)); else swap_uint16((uint16_t *)(&modeinfos
[i].vSyncEnd)); } while (0)
;
320 swaps(&modeinfos[i].vTotal)do { if (sizeof(*(&modeinfos[i].vTotal)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].vTotal
) & 1) && ((uintptr_t)(&modeinfos[i].vTotal) &
1) == 0) *(&modeinfos[i].vTotal) = lswaps(*(&modeinfos
[i].vTotal)); else swap_uint16((uint16_t *)(&modeinfos[i]
.vTotal)); } while (0)
;
321 swaps(&modeinfos[i].nameLength)do { if (sizeof(*(&modeinfos[i].nameLength)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].nameLength
) & 1) && ((uintptr_t)(&modeinfos[i].nameLength
) & 1) == 0) *(&modeinfos[i].nameLength) = lswaps(*(&
modeinfos[i].nameLength)); else swap_uint16((uint16_t *)(&
modeinfos[i].nameLength)); } while (0)
;
322 swapl(&modeinfos[i].modeFlags)do { if (sizeof(*(&modeinfos[i].modeFlags)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].modeFlags
) & 3) && ((uintptr_t)(&modeinfos[i].modeFlags
) & 3) == 0) *(&modeinfos[i].modeFlags) = lswapl(*(&
modeinfos[i].modeFlags)); else swap_uint32((uint32_t *)(&
modeinfos[i].modeFlags)); } while (0)
;
323}
324
325#define update_arrays(gpuscreen, pScrPriv, primary_crtc, has_primary)do { for (j = 0; j < pScrPriv->numCrtcs; j++) { if (has_primary
&& primary_crtc == pScrPriv->crtcs[j]) { has_primary
= 0; continue; } crtcs[crtc_count] = pScrPriv->crtcs[j]->
id; if (client->swapped) do { if (sizeof(*(&crtcs[crtc_count
])) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(
&crtcs[crtc_count]) & 3) && ((uintptr_t)(&
crtcs[crtc_count]) & 3) == 0) *(&crtcs[crtc_count]) =
lswapl(*(&crtcs[crtc_count])); else swap_uint32((uint32_t
*)(&crtcs[crtc_count])); } while (0); crtc_count++; } for
(j = 0; j < pScrPriv->numOutputs; j++) { outputs[output_count
] = pScrPriv->outputs[j]->id; if (client->swapped) do
{ if (sizeof(*(&outputs[output_count])) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&outputs[output_count
]) & 3) && ((uintptr_t)(&outputs[output_count
]) & 3) == 0) *(&outputs[output_count]) = lswapl(*(&
outputs[output_count])); else swap_uint32((uint32_t *)(&outputs
[output_count])); } while (0); output_count++; } { RRModePtr mode
; modes = RRModesForScreen(gpuscreen, &num_modes); for (j
= 0; j < num_modes; j++) { mode = modes[j]; modeinfos[mode_count
] = mode->mode; if (client->swapped) { swap_modeinfos(modeinfos
, mode_count); } __builtin___memcpy_chk (names, mode->name
, mode->mode.nameLength, __builtin_object_size (names, 0))
; names += mode->mode.nameLength; mode_count++; } free(modes
); } } while (0)
do { \
326 for (j = 0; j < pScrPriv->numCrtcs; j++) { \
327 if (has_primary && \
328 primary_crtc == pScrPriv->crtcs[j]) { \
329 has_primary = 0; \
330 continue; \
331 }\
332 crtcs[crtc_count] = pScrPriv->crtcs[j]->id; \
333 if (client->swapped) \
334 swapl(&crtcs[crtc_count])do { if (sizeof(*(&crtcs[crtc_count])) != 4) wrong_size()
; if (__builtin_constant_p((uintptr_t)(&crtcs[crtc_count]
) & 3) && ((uintptr_t)(&crtcs[crtc_count]) &
3) == 0) *(&crtcs[crtc_count]) = lswapl(*(&crtcs[crtc_count
])); else swap_uint32((uint32_t *)(&crtcs[crtc_count])); }
while (0)
; \
335 crtc_count++; \
336 } \
337 for (j = 0; j < pScrPriv->numOutputs; j++) { \
338 outputs[output_count] = pScrPriv->outputs[j]->id; \
339 if (client->swapped) \
340 swapl(&outputs[output_count])do { if (sizeof(*(&outputs[output_count])) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&outputs[output_count
]) & 3) && ((uintptr_t)(&outputs[output_count
]) & 3) == 0) *(&outputs[output_count]) = lswapl(*(&
outputs[output_count])); else swap_uint32((uint32_t *)(&outputs
[output_count])); } while (0)
; \
341 output_count++; \
342 } \
343 { \
344 RRModePtr mode; \
345 modes = RRModesForScreen(gpuscreen, &num_modes); \
346 for (j = 0; j < num_modes; j++) { \
347 mode = modes[j]; \
348 modeinfos[mode_count] = mode->mode; \
349 if (client->swapped) { \
350 swap_modeinfos(modeinfos, mode_count); \
351 } \
352 memcpy(names, mode->name, mode->mode.nameLength)__builtin___memcpy_chk (names, mode->name, mode->mode.nameLength
, __builtin_object_size (names, 0))
; \
353 names += mode->mode.nameLength; \
354 mode_count++; \
355 } \
356 free(modes); \
357 } \
358 } while (0)
359
360static int
361rrGetMultiScreenResources(ClientPtr client, Bool query, ScreenPtr pScreen)
362{
363 int j;
364 int total_crtcs, total_outputs, total_modes, total_name_len;
365 int crtc_count, output_count, mode_count;
366 ScreenPtr iter;
367 rrScrPrivPtr pScrPriv;
368 int num_modes;
369 RRModePtr *modes;
370 xRRGetScreenResourcesReply rep;
371 unsigned long extraLen;
372 CARD8 *extra;
373 RRCrtc *crtcs;
374 RRCrtcPtr primary_crtc = NULL((void*)0);
375 RROutput *outputs;
376 xRRModeInfo *modeinfos;
377 CARD8 *names;
378 int has_primary = 0;
379
380 /* we need to iterate all the GPU masters and all their output slaves */
381 total_crtcs = 0;
382 total_outputs = 0;
383 total_modes = 0;
384 total_name_len = 0;
385
386 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
387
388 if (query && pScrPriv)
389 if (!RRGetInfo(pScreen, query))
390 return BadAlloc11;
391
392 update_totals(pScreen, pScrPriv)do { total_crtcs += pScrPriv->numCrtcs; total_outputs += pScrPriv
->numOutputs; modes = RRModesForScreen(pScreen, &num_modes
); if (!modes) return 11; for (j = 0; j < num_modes; j++) total_name_len
+= modes[j]->mode.nameLength; total_modes += num_modes; free
(modes); } while(0)
;
393
394 xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head)for (iter = (typeof(*iter) *)((char *)((&pScreen->output_slave_list
)->next) - __builtin_offsetof(typeof(*iter), output_head))
; &iter->output_head != (&pScreen->output_slave_list
); iter = (typeof(*iter) *)((char *)(iter->output_head.next
) - __builtin_offsetof(typeof(*iter), output_head)))
{
395 pScrPriv = rrGetScrPriv(iter)((rrScrPrivPtr)dixLookupPrivate(&(iter)->devPrivates, (
&rrPrivKeyRec)))
;
396
397 if (query)
398 if (!RRGetInfo(iter, query))
399 return BadAlloc11;
400 update_totals(iter, pScrPriv)do { total_crtcs += pScrPriv->numCrtcs; total_outputs += pScrPriv
->numOutputs; modes = RRModesForScreen(iter, &num_modes
); if (!modes) return 11; for (j = 0; j < num_modes; j++) total_name_len
+= modes[j]->mode.nameLength; total_modes += num_modes; free
(modes); } while(0)
;
401 }
402
403 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
404 rep = (xRRGetScreenResourcesReply) {
405 .type = X_Reply1,
406 .sequenceNumber = client->sequence,
407 .length = 0,
408 .timestamp = pScrPriv->lastSetTime.milliseconds,
409 .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
410 .nCrtcs = total_crtcs,
411 .nOutputs = total_outputs,
412 .nModes = total_modes,
413 .nbytesNames = total_name_len
414 };
415
416 rep.length = (total_crtcs + total_outputs + total_modes * bytes_to_int32(SIZEOF(xRRModeInfo)32) +
417 bytes_to_int32(rep.nbytesNames));
418
419 extraLen = rep.length << 2;
420 if (extraLen) {
421 extra = malloc(extraLen);
422 if (!extra) {
423 return BadAlloc11;
424 }
425 }
426 else
427 extra = NULL((void*)0);
428
429 crtcs = (RRCrtc *)extra;
430 outputs = (RROutput *)(crtcs + total_crtcs);
431 modeinfos = (xRRModeInfo *)(outputs + total_outputs);
432 names = (CARD8 *)(modeinfos + total_modes);
433
434 crtc_count = 0;
435 output_count = 0;
436 mode_count = 0;
437
438 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
439 if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) {
440 has_primary = 1;
441 primary_crtc = pScrPriv->primaryOutput->crtc;
442 crtcs[0] = pScrPriv->primaryOutput->crtc->id;
443 if (client->swapped)
444 swapl(&crtcs[0])do { if (sizeof(*(&crtcs[0])) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&crtcs[0]) & 3) && ((uintptr_t)(
&crtcs[0]) & 3) == 0) *(&crtcs[0]) = lswapl(*(&
crtcs[0])); else swap_uint32((uint32_t *)(&crtcs[0])); } while
(0)
;
445 crtc_count = 1;
446 }
447 update_arrays(pScreen, pScrPriv, primary_crtc, has_primary)do { for (j = 0; j < pScrPriv->numCrtcs; j++) { if (has_primary
&& primary_crtc == pScrPriv->crtcs[j]) { has_primary
= 0; continue; } crtcs[crtc_count] = pScrPriv->crtcs[j]->
id; if (client->swapped) do { if (sizeof(*(&crtcs[crtc_count
])) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(
&crtcs[crtc_count]) & 3) && ((uintptr_t)(&
crtcs[crtc_count]) & 3) == 0) *(&crtcs[crtc_count]) =
lswapl(*(&crtcs[crtc_count])); else swap_uint32((uint32_t
*)(&crtcs[crtc_count])); } while (0); crtc_count++; } for
(j = 0; j < pScrPriv->numOutputs; j++) { outputs[output_count
] = pScrPriv->outputs[j]->id; if (client->swapped) do
{ if (sizeof(*(&outputs[output_count])) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&outputs[output_count
]) & 3) && ((uintptr_t)(&outputs[output_count
]) & 3) == 0) *(&outputs[output_count]) = lswapl(*(&
outputs[output_count])); else swap_uint32((uint32_t *)(&outputs
[output_count])); } while (0); output_count++; } { RRModePtr mode
; modes = RRModesForScreen(pScreen, &num_modes); for (j =
0; j < num_modes; j++) { mode = modes[j]; modeinfos[mode_count
] = mode->mode; if (client->swapped) { swap_modeinfos(modeinfos
, mode_count); } __builtin___memcpy_chk (names, mode->name
, mode->mode.nameLength, __builtin_object_size (names, 0))
; names += mode->mode.nameLength; mode_count++; } free(modes
); } } while (0)
;
448
449 xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head)for (iter = (typeof(*iter) *)((char *)((&pScreen->output_slave_list
)->next) - __builtin_offsetof(typeof(*iter), output_head))
; &iter->output_head != (&pScreen->output_slave_list
); iter = (typeof(*iter) *)((char *)(iter->output_head.next
) - __builtin_offsetof(typeof(*iter), output_head)))
{
450 pScrPriv = rrGetScrPriv(iter)((rrScrPrivPtr)dixLookupPrivate(&(iter)->devPrivates, (
&rrPrivKeyRec)))
;
451
452 update_arrays(iter, pScrPriv, primary_crtc, has_primary)do { for (j = 0; j < pScrPriv->numCrtcs; j++) { if (has_primary
&& primary_crtc == pScrPriv->crtcs[j]) { has_primary
= 0; continue; } crtcs[crtc_count] = pScrPriv->crtcs[j]->
id; if (client->swapped) do { if (sizeof(*(&crtcs[crtc_count
])) != 4) wrong_size(); if (__builtin_constant_p((uintptr_t)(
&crtcs[crtc_count]) & 3) && ((uintptr_t)(&
crtcs[crtc_count]) & 3) == 0) *(&crtcs[crtc_count]) =
lswapl(*(&crtcs[crtc_count])); else swap_uint32((uint32_t
*)(&crtcs[crtc_count])); } while (0); crtc_count++; } for
(j = 0; j < pScrPriv->numOutputs; j++) { outputs[output_count
] = pScrPriv->outputs[j]->id; if (client->swapped) do
{ if (sizeof(*(&outputs[output_count])) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&outputs[output_count
]) & 3) && ((uintptr_t)(&outputs[output_count
]) & 3) == 0) *(&outputs[output_count]) = lswapl(*(&
outputs[output_count])); else swap_uint32((uint32_t *)(&outputs
[output_count])); } while (0); output_count++; } { RRModePtr mode
; modes = RRModesForScreen(iter, &num_modes); for (j = 0;
j < num_modes; j++) { mode = modes[j]; modeinfos[mode_count
] = mode->mode; if (client->swapped) { swap_modeinfos(modeinfos
, mode_count); } __builtin___memcpy_chk (names, mode->name
, mode->mode.nameLength, __builtin_object_size (names, 0))
; names += mode->mode.nameLength; mode_count++; } free(modes
); } } while (0)
;
453 }
454
455 assert(bytes_to_int32((char *) names - (char *) extra) == rep.length)(__builtin_expect(!(bytes_to_int32((char *) names - (char *) extra
) == rep.length), 0) ? __assert_rtn(__func__, "rrscreen.c", 455
, "bytes_to_int32((char *) names - (char *) extra) == rep.length"
) : (void)0)
;
456 if (client->swapped) {
457 swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber
) & 1) && ((uintptr_t)(&rep.sequenceNumber) &
1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber
)); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); }
while (0)
;
458 swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.length) & 3) && ((uintptr_t
)(&rep.length) & 3) == 0) *(&rep.length) = lswapl
(*(&rep.length)); else swap_uint32((uint32_t *)(&rep.
length)); } while (0)
;
459 swapl(&rep.timestamp)do { if (sizeof(*(&rep.timestamp)) != 4) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.timestamp) & 3
) && ((uintptr_t)(&rep.timestamp) & 3) == 0) *
(&rep.timestamp) = lswapl(*(&rep.timestamp)); else swap_uint32
((uint32_t *)(&rep.timestamp)); } while (0)
;
460 swapl(&rep.configTimestamp)do { if (sizeof(*(&rep.configTimestamp)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&rep.configTimestamp
) & 3) && ((uintptr_t)(&rep.configTimestamp) &
3) == 0) *(&rep.configTimestamp) = lswapl(*(&rep.configTimestamp
)); else swap_uint32((uint32_t *)(&rep.configTimestamp));
} while (0)
;
461 swaps(&rep.nCrtcs)do { if (sizeof(*(&rep.nCrtcs)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.nCrtcs) & 1) && ((uintptr_t
)(&rep.nCrtcs) & 1) == 0) *(&rep.nCrtcs) = lswaps
(*(&rep.nCrtcs)); else swap_uint16((uint16_t *)(&rep.
nCrtcs)); } while (0)
;
462 swaps(&rep.nOutputs)do { if (sizeof(*(&rep.nOutputs)) != 2) wrong_size(); if (
__builtin_constant_p((uintptr_t)(&rep.nOutputs) & 1) &&
((uintptr_t)(&rep.nOutputs) & 1) == 0) *(&rep.nOutputs
) = lswaps(*(&rep.nOutputs)); else swap_uint16((uint16_t *
)(&rep.nOutputs)); } while (0)
;
463 swaps(&rep.nModes)do { if (sizeof(*(&rep.nModes)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.nModes) & 1) && ((uintptr_t
)(&rep.nModes) & 1) == 0) *(&rep.nModes) = lswaps
(*(&rep.nModes)); else swap_uint16((uint16_t *)(&rep.
nModes)); } while (0)
;
464 swaps(&rep.nbytesNames)do { if (sizeof(*(&rep.nbytesNames)) != 2) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.nbytesNames) &
1) && ((uintptr_t)(&rep.nbytesNames) & 1) ==
0) *(&rep.nbytesNames) = lswaps(*(&rep.nbytesNames))
; else swap_uint16((uint16_t *)(&rep.nbytesNames)); } while
(0)
;
465 }
466 WriteToClient(client, sizeof(xRRGetScreenResourcesReply), &rep);
467 if (extraLen) {
468 WriteToClient(client, extraLen, extra);
469 free(extra);
470 }
471 return Success0;
472}
473
474static int
475rrGetScreenResources(ClientPtr client, Bool query)
476{
477 REQUEST(xRRGetScreenResourcesReq)xRRGetScreenResourcesReq *stuff = (xRRGetScreenResourcesReq *
)client->requestBuffer
;
478 xRRGetScreenResourcesReply rep;
479 WindowPtr pWin;
480 ScreenPtr pScreen;
481 rrScrPrivPtr pScrPriv;
482 CARD8 *extra;
483 unsigned long extraLen;
484 int i, rc, has_primary = 0;
485 RRCrtc *crtcs;
486 RROutput *outputs;
487 xRRModeInfo *modeinfos;
488 CARD8 *names;
489
490 REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq)if ((sizeof(xRRGetScreenResourcesReq) >> 2) != client->
req_len) return(16)
;
491 rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4));
492 if (rc != Success0)
493 return rc;
494
495 pScreen = pWin->drawable.pScreen;
496 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
497
498 if (query && pScrPriv)
499 if (!RRGetInfo(pScreen, query))
500 return BadAlloc11;
501
502 if (!xorg_list_is_empty(&pScreen->output_slave_list))
503 return rrGetMultiScreenResources(client, query, pScreen);
504
505 if (!pScrPriv) {
506 rep = (xRRGetScreenResourcesReply) {
507 .type = X_Reply1,
508 .sequenceNumber = client->sequence,
509 .length = 0,
510 .timestamp = currentTime.milliseconds,
511 .configTimestamp = currentTime.milliseconds,
512 .nCrtcs = 0,
513 .nOutputs = 0,
514 .nModes = 0,
515 .nbytesNames = 0
516 };
517 extra = NULL((void*)0);
518 extraLen = 0;
519 }
520 else {
521 RRModePtr *modes;
522 int num_modes;
523
524 modes = RRModesForScreen(pScreen, &num_modes);
525 if (!modes)
526 return BadAlloc11;
527
528 rep = (xRRGetScreenResourcesReply) {
529 .type = X_Reply1,
530 .sequenceNumber = client->sequence,
531 .length = 0,
532 .timestamp = pScrPriv->lastSetTime.milliseconds,
533 .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
534 .nCrtcs = pScrPriv->numCrtcs,
535 .nOutputs = pScrPriv->numOutputs,
536 .nModes = num_modes,
537 .nbytesNames = 0
538 };
539
540
541 for (i = 0; i < num_modes; i++)
542 rep.nbytesNames += modes[i]->mode.nameLength;
543
544 rep.length = (pScrPriv->numCrtcs +
545 pScrPriv->numOutputs +
546 num_modes * bytes_to_int32(SIZEOF(xRRModeInfo)32) +
547 bytes_to_int32(rep.nbytesNames));
548
549 extraLen = rep.length << 2;
550 if (extraLen) {
551 extra = malloc(extraLen);
552 if (!extra) {
553 free(modes);
554 return BadAlloc11;
555 }
556 }
557 else
558 extra = NULL((void*)0);
559
560 crtcs = (RRCrtc *) extra;
561 outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
562 modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs);
563 names = (CARD8 *) (modeinfos + num_modes);
564
565 if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) {
566 has_primary = 1;
567 crtcs[0] = pScrPriv->primaryOutput->crtc->id;
568 if (client->swapped)
569 swapl(&crtcs[0])do { if (sizeof(*(&crtcs[0])) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&crtcs[0]) & 3) && ((uintptr_t)(
&crtcs[0]) & 3) == 0) *(&crtcs[0]) = lswapl(*(&
crtcs[0])); else swap_uint32((uint32_t *)(&crtcs[0])); } while
(0)
;
570 }
571
572 for (i = 0; i < pScrPriv->numCrtcs; i++) {
573 if (has_primary &&
574 pScrPriv->primaryOutput->crtc == pScrPriv->crtcs[i]) {
575 has_primary = 0;
576 continue;
577 }
578 crtcs[i + has_primary] = pScrPriv->crtcs[i]->id;
579 if (client->swapped)
580 swapl(&crtcs[i + has_primary])do { if (sizeof(*(&crtcs[i + has_primary])) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&crtcs[i + has_primary
]) & 3) && ((uintptr_t)(&crtcs[i + has_primary
]) & 3) == 0) *(&crtcs[i + has_primary]) = lswapl(*(&
crtcs[i + has_primary])); else swap_uint32((uint32_t *)(&
crtcs[i + has_primary])); } while (0)
;
581 }
582
583 for (i = 0; i < pScrPriv->numOutputs; i++) {
584 outputs[i] = pScrPriv->outputs[i]->id;
585 if (client->swapped)
586 swapl(&outputs[i])do { if (sizeof(*(&outputs[i])) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&outputs[i]) & 3) && ((uintptr_t
)(&outputs[i]) & 3) == 0) *(&outputs[i]) = lswapl
(*(&outputs[i])); else swap_uint32((uint32_t *)(&outputs
[i])); } while (0)
;
587 }
588
589 for (i = 0; i < num_modes; i++) {
590 RRModePtr mode = modes[i];
591
592 modeinfos[i] = mode->mode;
593 if (client->swapped) {
594 swapl(&modeinfos[i].id)do { if (sizeof(*(&modeinfos[i].id)) != 4) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&modeinfos[i].id) &
3) && ((uintptr_t)(&modeinfos[i].id) & 3) ==
0) *(&modeinfos[i].id) = lswapl(*(&modeinfos[i].id))
; else swap_uint32((uint32_t *)(&modeinfos[i].id)); } while
(0)
;
595 swaps(&modeinfos[i].width)do { if (sizeof(*(&modeinfos[i].width)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].width
) & 1) && ((uintptr_t)(&modeinfos[i].width) &
1) == 0) *(&modeinfos[i].width) = lswaps(*(&modeinfos
[i].width)); else swap_uint16((uint16_t *)(&modeinfos[i].
width)); } while (0)
;
596 swaps(&modeinfos[i].height)do { if (sizeof(*(&modeinfos[i].height)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].height
) & 1) && ((uintptr_t)(&modeinfos[i].height) &
1) == 0) *(&modeinfos[i].height) = lswaps(*(&modeinfos
[i].height)); else swap_uint16((uint16_t *)(&modeinfos[i]
.height)); } while (0)
;
597 swapl(&modeinfos[i].dotClock)do { if (sizeof(*(&modeinfos[i].dotClock)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].dotClock
) & 3) && ((uintptr_t)(&modeinfos[i].dotClock
) & 3) == 0) *(&modeinfos[i].dotClock) = lswapl(*(&
modeinfos[i].dotClock)); else swap_uint32((uint32_t *)(&modeinfos
[i].dotClock)); } while (0)
;
598 swaps(&modeinfos[i].hSyncStart)do { if (sizeof(*(&modeinfos[i].hSyncStart)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hSyncStart
) & 1) && ((uintptr_t)(&modeinfos[i].hSyncStart
) & 1) == 0) *(&modeinfos[i].hSyncStart) = lswaps(*(&
modeinfos[i].hSyncStart)); else swap_uint16((uint16_t *)(&
modeinfos[i].hSyncStart)); } while (0)
;
599 swaps(&modeinfos[i].hSyncEnd)do { if (sizeof(*(&modeinfos[i].hSyncEnd)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hSyncEnd
) & 1) && ((uintptr_t)(&modeinfos[i].hSyncEnd
) & 1) == 0) *(&modeinfos[i].hSyncEnd) = lswaps(*(&
modeinfos[i].hSyncEnd)); else swap_uint16((uint16_t *)(&modeinfos
[i].hSyncEnd)); } while (0)
;
600 swaps(&modeinfos[i].hTotal)do { if (sizeof(*(&modeinfos[i].hTotal)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hTotal
) & 1) && ((uintptr_t)(&modeinfos[i].hTotal) &
1) == 0) *(&modeinfos[i].hTotal) = lswaps(*(&modeinfos
[i].hTotal)); else swap_uint16((uint16_t *)(&modeinfos[i]
.hTotal)); } while (0)
;
601 swaps(&modeinfos[i].hSkew)do { if (sizeof(*(&modeinfos[i].hSkew)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].hSkew
) & 1) && ((uintptr_t)(&modeinfos[i].hSkew) &
1) == 0) *(&modeinfos[i].hSkew) = lswaps(*(&modeinfos
[i].hSkew)); else swap_uint16((uint16_t *)(&modeinfos[i].
hSkew)); } while (0)
;
602 swaps(&modeinfos[i].vSyncStart)do { if (sizeof(*(&modeinfos[i].vSyncStart)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].vSyncStart
) & 1) && ((uintptr_t)(&modeinfos[i].vSyncStart
) & 1) == 0) *(&modeinfos[i].vSyncStart) = lswaps(*(&
modeinfos[i].vSyncStart)); else swap_uint16((uint16_t *)(&
modeinfos[i].vSyncStart)); } while (0)
;
603 swaps(&modeinfos[i].vSyncEnd)do { if (sizeof(*(&modeinfos[i].vSyncEnd)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].vSyncEnd
) & 1) && ((uintptr_t)(&modeinfos[i].vSyncEnd
) & 1) == 0) *(&modeinfos[i].vSyncEnd) = lswaps(*(&
modeinfos[i].vSyncEnd)); else swap_uint16((uint16_t *)(&modeinfos
[i].vSyncEnd)); } while (0)
;
604 swaps(&modeinfos[i].vTotal)do { if (sizeof(*(&modeinfos[i].vTotal)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].vTotal
) & 1) && ((uintptr_t)(&modeinfos[i].vTotal) &
1) == 0) *(&modeinfos[i].vTotal) = lswaps(*(&modeinfos
[i].vTotal)); else swap_uint16((uint16_t *)(&modeinfos[i]
.vTotal)); } while (0)
;
605 swaps(&modeinfos[i].nameLength)do { if (sizeof(*(&modeinfos[i].nameLength)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].nameLength
) & 1) && ((uintptr_t)(&modeinfos[i].nameLength
) & 1) == 0) *(&modeinfos[i].nameLength) = lswaps(*(&
modeinfos[i].nameLength)); else swap_uint16((uint16_t *)(&
modeinfos[i].nameLength)); } while (0)
;
606 swapl(&modeinfos[i].modeFlags)do { if (sizeof(*(&modeinfos[i].modeFlags)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&modeinfos[i].modeFlags
) & 3) && ((uintptr_t)(&modeinfos[i].modeFlags
) & 3) == 0) *(&modeinfos[i].modeFlags) = lswapl(*(&
modeinfos[i].modeFlags)); else swap_uint32((uint32_t *)(&
modeinfos[i].modeFlags)); } while (0)
;
607 }
608 memcpy(names, mode->name, mode->mode.nameLength)__builtin___memcpy_chk (names, mode->name, mode->mode.nameLength
, __builtin_object_size (names, 0))
;
609 names += mode->mode.nameLength;
610 }
611 free(modes);
612 assert(bytes_to_int32((char *) names - (char *) extra) == rep.length)(__builtin_expect(!(bytes_to_int32((char *) names - (char *) extra
) == rep.length), 0) ? __assert_rtn(__func__, "rrscreen.c", 612
, "bytes_to_int32((char *) names - (char *) extra) == rep.length"
) : (void)0)
;
613 }
614
615 if (client->swapped) {
616 swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber
) & 1) && ((uintptr_t)(&rep.sequenceNumber) &
1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber
)); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); }
while (0)
;
617 swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.length) & 3) && ((uintptr_t
)(&rep.length) & 3) == 0) *(&rep.length) = lswapl
(*(&rep.length)); else swap_uint32((uint32_t *)(&rep.
length)); } while (0)
;
618 swapl(&rep.timestamp)do { if (sizeof(*(&rep.timestamp)) != 4) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.timestamp) & 3
) && ((uintptr_t)(&rep.timestamp) & 3) == 0) *
(&rep.timestamp) = lswapl(*(&rep.timestamp)); else swap_uint32
((uint32_t *)(&rep.timestamp)); } while (0)
;
619 swapl(&rep.configTimestamp)do { if (sizeof(*(&rep.configTimestamp)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&rep.configTimestamp
) & 3) && ((uintptr_t)(&rep.configTimestamp) &
3) == 0) *(&rep.configTimestamp) = lswapl(*(&rep.configTimestamp
)); else swap_uint32((uint32_t *)(&rep.configTimestamp));
} while (0)
;
620 swaps(&rep.nCrtcs)do { if (sizeof(*(&rep.nCrtcs)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.nCrtcs) & 1) && ((uintptr_t
)(&rep.nCrtcs) & 1) == 0) *(&rep.nCrtcs) = lswaps
(*(&rep.nCrtcs)); else swap_uint16((uint16_t *)(&rep.
nCrtcs)); } while (0)
;
621 swaps(&rep.nOutputs)do { if (sizeof(*(&rep.nOutputs)) != 2) wrong_size(); if (
__builtin_constant_p((uintptr_t)(&rep.nOutputs) & 1) &&
((uintptr_t)(&rep.nOutputs) & 1) == 0) *(&rep.nOutputs
) = lswaps(*(&rep.nOutputs)); else swap_uint16((uint16_t *
)(&rep.nOutputs)); } while (0)
;
622 swaps(&rep.nModes)do { if (sizeof(*(&rep.nModes)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.nModes) & 1) && ((uintptr_t
)(&rep.nModes) & 1) == 0) *(&rep.nModes) = lswaps
(*(&rep.nModes)); else swap_uint16((uint16_t *)(&rep.
nModes)); } while (0)
;
623 swaps(&rep.nbytesNames)do { if (sizeof(*(&rep.nbytesNames)) != 2) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.nbytesNames) &
1) && ((uintptr_t)(&rep.nbytesNames) & 1) ==
0) *(&rep.nbytesNames) = lswaps(*(&rep.nbytesNames))
; else swap_uint16((uint16_t *)(&rep.nbytesNames)); } while
(0)
;
624 }
625 WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep);
626 if (extraLen) {
627 WriteToClient(client, extraLen, (char *) extra);
628 free(extra);
629 }
630 return Success0;
631}
632
633int
634ProcRRGetScreenResources(ClientPtr client)
635{
636 return rrGetScreenResources(client, TRUE1);
637}
638
639int
640ProcRRGetScreenResourcesCurrent(ClientPtr client)
641{
642 return rrGetScreenResources(client, FALSE0);
643}
644
645typedef struct _RR10Data {
646 RRScreenSizePtr sizes;
647 int nsize;
648 int nrefresh;
649 int size;
650 CARD16 refresh;
651} RR10DataRec, *RR10DataPtr;
652
653/*
654 * Convert 1.2 monitor data into 1.0 screen data
655 */
656static RR10DataPtr
657RR10GetData(ScreenPtr pScreen, RROutputPtr output)
658{
659 RR10DataPtr data;
660 RRScreenSizePtr size;
661 int nmode = output->numModes + output->numUserModes;
662 int o, os, l, r;
663 RRScreenRatePtr refresh;
664 CARD16 vRefresh;
665 RRModePtr mode;
666 Bool *used;
667
668 /* Make sure there is plenty of space for any combination */
669 data = malloc(sizeof(RR10DataRec) +
670 sizeof(RRScreenSize) * nmode +
671 sizeof(RRScreenRate) * nmode + sizeof(Bool) * nmode);
672 if (!data)
673 return NULL((void*)0);
674 size = (RRScreenSizePtr) (data + 1);
675 refresh = (RRScreenRatePtr) (size + nmode);
676 used = (Bool *) (refresh + nmode);
677 memset(used, '\0', sizeof(Bool) * nmode)__builtin___memset_chk (used, '\0', sizeof(Bool) * nmode, __builtin_object_size
(used, 0))
;
678 data->sizes = size;
679 data->nsize = 0;
680 data->nrefresh = 0;
681 data->size = 0;
682 data->refresh = 0;
683
684 /*
685 * find modes not yet listed
686 */
687 for (o = 0; o < output->numModes + output->numUserModes; o++) {
688 if (used[o])
689 continue;
690
691 if (o < output->numModes)
692 mode = output->modes[o];
693 else
694 mode = output->userModes[o - output->numModes];
695
696 l = data->nsize;
697 size[l].id = data->nsize;
698 size[l].width = mode->mode.width;
699 size[l].height = mode->mode.height;
700 if (output->mmWidth && output->mmHeight) {
701 size[l].mmWidth = output->mmWidth;
702 size[l].mmHeight = output->mmHeight;
703 }
704 else {
705 size[l].mmWidth = pScreen->mmWidth;
706 size[l].mmHeight = pScreen->mmHeight;
707 }
708 size[l].nRates = 0;
709 size[l].pRates = &refresh[data->nrefresh];
710 data->nsize++;
711
712 /*
713 * Find all modes with matching size
714 */
715 for (os = o; os < output->numModes + output->numUserModes; os++) {
716 if (os < output->numModes)
717 mode = output->modes[os];
718 else
719 mode = output->userModes[os - output->numModes];
720 if (mode->mode.width == size[l].width &&
721 mode->mode.height == size[l].height) {
722 vRefresh = RRVerticalRefresh(&mode->mode);
723 used[os] = TRUE1;
724
725 for (r = 0; r < size[l].nRates; r++)
726 if (vRefresh == size[l].pRates[r].rate)
727 break;
728 if (r == size[l].nRates) {
729 size[l].pRates[r].rate = vRefresh;
730 size[l].pRates[r].mode = mode;
731 size[l].nRates++;
732 data->nrefresh++;
733 }
734 if (mode == output->crtc->mode) {
735 data->size = l;
736 data->refresh = vRefresh;
737 }
738 }
739 }
740 }
741 return data;
742}
743
744int
745ProcRRGetScreenInfo(ClientPtr client)
746{
747 REQUEST(xRRGetScreenInfoReq)xRRGetScreenInfoReq *stuff = (xRRGetScreenInfoReq *)client->
requestBuffer
;
748 xRRGetScreenInfoReply rep;
749 WindowPtr pWin;
750 int rc;
751 ScreenPtr pScreen;
752 rrScrPrivPtr pScrPriv;
753 CARD8 *extra;
754 unsigned long extraLen;
755 RROutputPtr output;
756
757 REQUEST_SIZE_MATCH(xRRGetScreenInfoReq)if ((sizeof(xRRGetScreenInfoReq) >> 2) != client->req_len
) return(16)
;
758 rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4));
759 if (rc != Success0)
760 return rc;
761
762 pScreen = pWin->drawable.pScreen;
763 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
764
765 if (pScrPriv)
766 if (!RRGetInfo(pScreen, TRUE1))
767 return BadAlloc11;
768
769 output = RRFirstOutput(pScreen);
770
771 if (!pScrPriv || !output) {
772 rep = (xRRGetScreenInfoReply) {
773 .type = X_Reply1,
774 .setOfRotations = RR_Rotate_01,
775 .sequenceNumber = client->sequence,
776 .length = 0,
777 .root = pWin->drawable.pScreen->root->drawable.id,
778 .timestamp = currentTime.milliseconds,
779 .configTimestamp = currentTime.milliseconds,
780 .nSizes = 0,
781 .sizeID = 0,
782 .rotation = RR_Rotate_01,
783 .rate = 0,
784 .nrateEnts = 0
785 };
786 extra = 0;
787 extraLen = 0;
788 }
789 else {
790 int i, j;
791 xScreenSizes *size;
792 CARD16 *rates;
793 CARD8 *data8;
794 Bool has_rate = RRClientKnowsRates(client);
795 RR10DataPtr pData;
796 RRScreenSizePtr pSize;
797
798 pData = RR10GetData(pScreen, output);
799 if (!pData)
800 return BadAlloc11;
801
802 rep = (xRRGetScreenInfoReply) {
803 .type = X_Reply1,
804 .setOfRotations = output->crtc->rotations,
805 .sequenceNumber = client->sequence,
806 .length = 0,
807 .root = pWin->drawable.pScreen->root->drawable.id,
808 .timestamp = pScrPriv->lastSetTime.milliseconds,
809 .configTimestamp = pScrPriv->lastConfigTime.milliseconds,
810 .rotation = output->crtc->rotation,
811 .nSizes = pData->nsize,
812 .nrateEnts = pData->nrefresh + pData->nsize,
813 .sizeID = pData->size,
814 .rate = pData->refresh
815 };
816
817 extraLen = rep.nSizes * sizeof(xScreenSizes);
818 if (has_rate)
819 extraLen += rep.nrateEnts * sizeof(CARD16);
820
821 if (extraLen) {
822 extra = (CARD8 *) malloc(extraLen);
823 if (!extra) {
824 free(pData);
825 return BadAlloc11;
826 }
827 }
828 else
829 extra = NULL((void*)0);
830
831 /*
832 * First comes the size information
833 */
834 size = (xScreenSizes *) extra;
835 rates = (CARD16 *) (size + rep.nSizes);
836 for (i = 0; i < pData->nsize; i++) {
837 pSize = &pData->sizes[i];
838 size->widthInPixels = pSize->width;
839 size->heightInPixels = pSize->height;
840 size->widthInMillimeters = pSize->mmWidth;
841 size->heightInMillimeters = pSize->mmHeight;
842 if (client->swapped) {
843 swaps(&size->widthInPixels)do { if (sizeof(*(&size->widthInPixels)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&size->widthInPixels
) & 1) && ((uintptr_t)(&size->widthInPixels
) & 1) == 0) *(&size->widthInPixels) = lswaps(*(&
size->widthInPixels)); else swap_uint16((uint16_t *)(&
size->widthInPixels)); } while (0)
;
844 swaps(&size->heightInPixels)do { if (sizeof(*(&size->heightInPixels)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&size->heightInPixels
) & 1) && ((uintptr_t)(&size->heightInPixels
) & 1) == 0) *(&size->heightInPixels) = lswaps(*(&
size->heightInPixels)); else swap_uint16((uint16_t *)(&
size->heightInPixels)); } while (0)
;
845 swaps(&size->widthInMillimeters)do { if (sizeof(*(&size->widthInMillimeters)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&size->widthInMillimeters
) & 1) && ((uintptr_t)(&size->widthInMillimeters
) & 1) == 0) *(&size->widthInMillimeters) = lswaps
(*(&size->widthInMillimeters)); else swap_uint16((uint16_t
*)(&size->widthInMillimeters)); } while (0)
;
846 swaps(&size->heightInMillimeters)do { if (sizeof(*(&size->heightInMillimeters)) != 2) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&size->heightInMillimeters
) & 1) && ((uintptr_t)(&size->heightInMillimeters
) & 1) == 0) *(&size->heightInMillimeters) = lswaps
(*(&size->heightInMillimeters)); else swap_uint16((uint16_t
*)(&size->heightInMillimeters)); } while (0)
;
847 }
848 size++;
849 if (has_rate) {
850 *rates = pSize->nRates;
851 if (client->swapped) {
852 swaps(rates)do { if (sizeof(*(rates)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(rates) & 1) && ((uintptr_t)(rates) &
1) == 0) *(rates) = lswaps(*(rates)); else swap_uint16((uint16_t
*)(rates)); } while (0)
;
853 }
854 rates++;
855 for (j = 0; j < pSize->nRates; j++) {
856 *rates = pSize->pRates[j].rate;
857 if (client->swapped) {
858 swaps(rates)do { if (sizeof(*(rates)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(rates) & 1) && ((uintptr_t)(rates) &
1) == 0) *(rates) = lswaps(*(rates)); else swap_uint16((uint16_t
*)(rates)); } while (0)
;
859 }
860 rates++;
861 }
862 }
863 }
864 free(pData);
865
866 data8 = (CARD8 *) rates;
867
868 if (data8 - (CARD8 *) extra != extraLen)
869 FatalError("RRGetScreenInfo bad extra len %ld != %ld\n",
870 (unsigned long) (data8 - (CARD8 *) extra), extraLen);
871 rep.length = bytes_to_int32(extraLen);
872 }
873 if (client->swapped) {
874 swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber
) & 1) && ((uintptr_t)(&rep.sequenceNumber) &
1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber
)); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); }
while (0)
;
875 swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.length) & 3) && ((uintptr_t
)(&rep.length) & 3) == 0) *(&rep.length) = lswapl
(*(&rep.length)); else swap_uint32((uint32_t *)(&rep.
length)); } while (0)
;
876 swapl(&rep.timestamp)do { if (sizeof(*(&rep.timestamp)) != 4) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.timestamp) & 3
) && ((uintptr_t)(&rep.timestamp) & 3) == 0) *
(&rep.timestamp) = lswapl(*(&rep.timestamp)); else swap_uint32
((uint32_t *)(&rep.timestamp)); } while (0)
;
877 swapl(&rep.configTimestamp)do { if (sizeof(*(&rep.configTimestamp)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&rep.configTimestamp
) & 3) && ((uintptr_t)(&rep.configTimestamp) &
3) == 0) *(&rep.configTimestamp) = lswapl(*(&rep.configTimestamp
)); else swap_uint32((uint32_t *)(&rep.configTimestamp));
} while (0)
;
878 swaps(&rep.rotation)do { if (sizeof(*(&rep.rotation)) != 2) wrong_size(); if (
__builtin_constant_p((uintptr_t)(&rep.rotation) & 1) &&
((uintptr_t)(&rep.rotation) & 1) == 0) *(&rep.rotation
) = lswaps(*(&rep.rotation)); else swap_uint16((uint16_t *
)(&rep.rotation)); } while (0)
;
879 swaps(&rep.nSizes)do { if (sizeof(*(&rep.nSizes)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.nSizes) & 1) && ((uintptr_t
)(&rep.nSizes) & 1) == 0) *(&rep.nSizes) = lswaps
(*(&rep.nSizes)); else swap_uint16((uint16_t *)(&rep.
nSizes)); } while (0)
;
880 swaps(&rep.sizeID)do { if (sizeof(*(&rep.sizeID)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.sizeID) & 1) && ((uintptr_t
)(&rep.sizeID) & 1) == 0) *(&rep.sizeID) = lswaps
(*(&rep.sizeID)); else swap_uint16((uint16_t *)(&rep.
sizeID)); } while (0)
;
881 swaps(&rep.rate)do { if (sizeof(*(&rep.rate)) != 2) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.rate) & 1) && ((uintptr_t)(
&rep.rate) & 1) == 0) *(&rep.rate) = lswaps(*(&
rep.rate)); else swap_uint16((uint16_t *)(&rep.rate)); } while
(0)
;
882 swaps(&rep.nrateEnts)do { if (sizeof(*(&rep.nrateEnts)) != 2) wrong_size(); if
(__builtin_constant_p((uintptr_t)(&rep.nrateEnts) & 1
) && ((uintptr_t)(&rep.nrateEnts) & 1) == 0) *
(&rep.nrateEnts) = lswaps(*(&rep.nrateEnts)); else swap_uint16
((uint16_t *)(&rep.nrateEnts)); } while (0)
;
883 }
884 WriteToClient(client, sizeof(xRRGetScreenInfoReply), &rep);
885 if (extraLen) {
886 WriteToClient(client, extraLen, extra);
887 free(extra);
888 }
889 return Success0;
890}
891
892int
893ProcRRSetScreenConfig(ClientPtr client)
894{
895 REQUEST(xRRSetScreenConfigReq)xRRSetScreenConfigReq *stuff = (xRRSetScreenConfigReq *)client
->requestBuffer
;
896 xRRSetScreenConfigReply rep;
897 DrawablePtr pDraw;
898 int rc;
899 ScreenPtr pScreen;
900 rrScrPrivPtr pScrPriv;
901 TimeStamp time;
902 int i;
903 Rotation rotation;
904 int rate;
905 Bool has_rate;
906 CARD8 status;
907 RROutputPtr output;
908 RRCrtcPtr crtc;
909 RRModePtr mode;
910 RR10DataPtr pData = NULL((void*)0);
911 RRScreenSizePtr pSize;
912 int width, height;
913
914 UpdateCurrentTime();
915
916 if (RRClientKnowsRates(client)) {
917 REQUEST_SIZE_MATCH(xRRSetScreenConfigReq)if ((sizeof(xRRSetScreenConfigReq) >> 2) != client->
req_len) return(16)
;
918 has_rate = TRUE1;
919 }
920 else {
921 REQUEST_SIZE_MATCH(xRR1_0SetScreenConfigReq)if ((sizeof(xRR1_0SetScreenConfigReq) >> 2) != client->
req_len) return(16)
;
922 has_rate = FALSE0;
923 }
924
925 rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess(1<<1));
926 if (rc != Success0)
927 return rc;
928
929 pScreen = pDraw->pScreen;
930
931 pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates
, (&rrPrivKeyRec)))
;
932
933 time = ClientTimeToServerTime(stuff->timestamp);
934
935 if (!pScrPriv) {
936 time = currentTime;
Value stored to 'time' is never read
937 status = RRSetConfigFailed3;
938 goto sendReply;
939 }
940 if (!RRGetInfo(pScreen, FALSE0))
941 return BadAlloc11;
942
943 output = RRFirstOutput(pScreen);
944 if (!output) {
945 time = currentTime;
946 status = RRSetConfigFailed3;
947 goto sendReply;
948 }
949
950 crtc = output->crtc;
951
952 /*
953 * If the client's config timestamp is not the same as the last config
954 * timestamp, then the config information isn't up-to-date and
955 * can't even be validated.
956 *
957 * Note that the client only knows about the milliseconds part of the
958 * timestamp, so using CompareTimeStamps here would cause randr to suddenly
959 * stop working after several hours have passed (freedesktop bug #6502).
960 */
961 if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) {
962 status = RRSetConfigInvalidConfigTime1;
963 goto sendReply;
964 }
965
966 pData = RR10GetData(pScreen, output);
967 if (!pData)
968 return BadAlloc11;
969
970 if (stuff->sizeID >= pData->nsize) {
971 /*
972 * Invalid size ID
973 */
974 client->errorValue = stuff->sizeID;
975 free(pData);
976 return BadValue2;
977 }
978 pSize = &pData->sizes[stuff->sizeID];
979
980 /*
981 * Validate requested rotation
982 */
983 rotation = (Rotation) stuff->rotation;
984
985 /* test the rotation bits only! */
986 switch (rotation & 0xf) {
987 case RR_Rotate_01:
988 case RR_Rotate_902:
989 case RR_Rotate_1804:
990 case RR_Rotate_2708:
991 break;
992 default:
993 /*
994 * Invalid rotation
995 */
996 client->errorValue = stuff->rotation;
997 free(pData);
998 return BadValue2;
999 }
1000
1001 if ((~crtc->rotations) & rotation) {
1002 /*
1003 * requested rotation or reflection not supported by screen
1004 */
1005 client->errorValue = stuff->rotation;
1006 free(pData);
1007 return BadMatch8;
1008 }
1009
1010 /*
1011 * Validate requested refresh
1012 */
1013 if (has_rate)
1014 rate = (int) stuff->rate;
1015 else
1016 rate = 0;
1017
1018 if (rate) {
1019 for (i = 0; i < pSize->nRates; i++) {
1020 if (pSize->pRates[i].rate == rate)
1021 break;
1022 }
1023 if (i == pSize->nRates) {
1024 /*
1025 * Invalid rate
1026 */
1027 client->errorValue = rate;
1028 free(pData);
1029 return BadValue2;
1030 }
1031 mode = pSize->pRates[i].mode;
1032 }
1033 else
1034 mode = pSize->pRates[0].mode;
1035
1036 /*
1037 * Make sure the requested set-time is not older than
1038 * the last set-time
1039 */
1040 if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) {
1041 status = RRSetConfigInvalidTime2;
1042 goto sendReply;
1043 }
1044
1045 /*
1046 * If the screen size is changing, adjust all of the other outputs
1047 * to fit the new size, mirroring as much as possible
1048 */
1049 width = mode->mode.width;
1050 height = mode->mode.height;
1051 if (width < pScrPriv->minWidth || pScrPriv->maxWidth < width) {
1052 client->errorValue = width;
1053 free(pData);
1054 return BadValue2;
1055 }
1056 if (height < pScrPriv->minHeight || pScrPriv->maxHeight < height) {
1057 client->errorValue = height;
1058 free(pData);
1059 return BadValue2;
1060 }
1061
1062 if (rotation & (RR_Rotate_902 | RR_Rotate_2708)) {
1063 width = mode->mode.height;
1064 height = mode->mode.width;
1065 }
1066
1067 if (width != pScreen->width || height != pScreen->height) {
1068 int c;
1069
1070 for (c = 0; c < pScrPriv->numCrtcs; c++) {
1071 if (!RRCrtcSet(pScrPriv->crtcs[c], NULL((void*)0), 0, 0, RR_Rotate_01,
1072 0, NULL((void*)0))) {
1073 status = RRSetConfigFailed3;
1074 /* XXX recover from failure */
1075 goto sendReply;
1076 }
1077 }
1078 if (!RRScreenSizeSet(pScreen, width, height,
1079 pScreen->mmWidth, pScreen->mmHeight)) {
1080 status = RRSetConfigFailed3;
1081 /* XXX recover from failure */
1082 goto sendReply;
1083 }
1084 }
1085
1086 if (!RRCrtcSet(crtc, mode, 0, 0, stuff->rotation, 1, &output))
1087 status = RRSetConfigFailed3;
1088 else {
1089 pScrPriv->lastSetTime = time;
1090 status = RRSetConfigSuccess0;
1091 }
1092
1093 /*
1094 * XXX Configure other crtcs to mirror as much as possible
1095 */
1096
1097 sendReply:
1098
1099 free(pData);
1100
1101 rep = (xRRSetScreenConfigReply) {
1102 .type = X_Reply1,
1103 .status = status,
1104 .sequenceNumber = client->sequence,
1105 .length = 0,
1106
1107 .newTimestamp = pScrPriv->lastSetTime.milliseconds,
1108 .newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds,
1109 .root = pDraw->pScreen->root->drawable.id,
1110 /* .subpixelOrder = ?? */
1111 };
1112
1113 if (client->swapped) {
1114 swaps(&rep.sequenceNumber)do { if (sizeof(*(&rep.sequenceNumber)) != 2) wrong_size(
); if (__builtin_constant_p((uintptr_t)(&rep.sequenceNumber
) & 1) && ((uintptr_t)(&rep.sequenceNumber) &
1) == 0) *(&rep.sequenceNumber) = lswaps(*(&rep.sequenceNumber
)); else swap_uint16((uint16_t *)(&rep.sequenceNumber)); }
while (0)
;
1115 swapl(&rep.length)do { if (sizeof(*(&rep.length)) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.length) & 3) && ((uintptr_t
)(&rep.length) & 3) == 0) *(&rep.length) = lswapl
(*(&rep.length)); else swap_uint32((uint32_t *)(&rep.
length)); } while (0)
;
1116 swapl(&rep.newTimestamp)do { if (sizeof(*(&rep.newTimestamp)) != 4) wrong_size();
if (__builtin_constant_p((uintptr_t)(&rep.newTimestamp) &
3) && ((uintptr_t)(&rep.newTimestamp) & 3) ==
0) *(&rep.newTimestamp) = lswapl(*(&rep.newTimestamp
)); else swap_uint32((uint32_t *)(&rep.newTimestamp)); } while
(0)
;
1117 swapl(&rep.newConfigTimestamp)do { if (sizeof(*(&rep.newConfigTimestamp)) != 4) wrong_size
(); if (__builtin_constant_p((uintptr_t)(&rep.newConfigTimestamp
) & 3) && ((uintptr_t)(&rep.newConfigTimestamp
) & 3) == 0) *(&rep.newConfigTimestamp) = lswapl(*(&
rep.newConfigTimestamp)); else swap_uint32((uint32_t *)(&
rep.newConfigTimestamp)); } while (0)
;
1118 swapl(&rep.root)do { if (sizeof(*(&rep.root)) != 4) wrong_size(); if (__builtin_constant_p
((uintptr_t)(&rep.root) & 3) && ((uintptr_t)(
&rep.root) & 3) == 0) *(&rep.root) = lswapl(*(&
rep.root)); else swap_uint32((uint32_t *)(&rep.root)); } while
(0)
;
1119 }
1120 WriteToClient(client, sizeof(xRRSetScreenConfigReply), &rep);
1121
1122 return Success0;
1123}
1124
1125static CARD16
1126RR10CurrentSizeID(ScreenPtr pScreen)
1127{
1128 CARD16 sizeID = 0xffff;
1129 RROutputPtr output = RRFirstOutput(pScreen);
1130
1131 if (output) {
1132 RR10DataPtr data = RR10GetData(pScreen, output);
1133
1134 if (data) {
1135 int i;
1136
1137 for (i = 0; i < data->nsize; i++)
1138 if (data->sizes[i].width == pScreen->width &&
1139 data->sizes[i].height == pScreen->height) {
1140 sizeID = (CARD16) i;
1141 break;
1142 }
1143 free(data);
1144 }
1145 }
1146 return sizeID;
1147}