| File: | randr/rrscreen.c |
| Location: | line 839, column 33 |
| Description: | Access to field 'widthInPixels' results in a dereference of a null pointer (loaded from variable 'size') |
| 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 | ||||
| 25 | static 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 | */ | |||
| 32 | static void | |||
| 33 | RREditConnectionInfo(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 | ||||
| 67 | void | |||
| 68 | RRSendConfigNotify(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 | ||||
| 88 | void | |||
| 89 | RRDeliverScreenEvent(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 | */ | |||
| 128 | void | |||
| 129 | RRScreenSizeNotify(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 | */ | |||
| 163 | Bool | |||
| 164 | RRScreenSizeSet(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 | */ | |||
| 186 | int | |||
| 187 | ProcRRGetScreenSizeRange(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 | ||||
| 235 | int | |||
| 236 | ProcRRSetScreenSize(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 | ||||
| 308 | static 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 | ||||
| 360 | static int | |||
| 361 | rrGetMultiScreenResources(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 = ((void*)0), 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 + | |||
| 417 | total_modes * bytes_to_int32(SIZEOF(xRRModeInfo)32) + | |||
| 418 | bytes_to_int32(total_name_len)); | |||
| 419 | ||||
| 420 | extraLen = rep.length << 2; | |||
| 421 | if (extraLen) { | |||
| 422 | extra = malloc(extraLen); | |||
| 423 | if (!extra) { | |||
| 424 | return BadAlloc11; | |||
| 425 | } | |||
| 426 | } | |||
| 427 | else | |||
| 428 | extra = NULL((void*)0); | |||
| 429 | ||||
| 430 | crtcs = (RRCrtc *)extra; | |||
| 431 | outputs = (RROutput *)(crtcs + total_crtcs); | |||
| 432 | modeinfos = (xRRModeInfo *)(outputs + total_outputs); | |||
| 433 | names = (CARD8 *)(modeinfos + total_modes); | |||
| 434 | ||||
| 435 | crtc_count = 0; | |||
| 436 | output_count = 0; | |||
| 437 | mode_count = 0; | |||
| 438 | ||||
| 439 | pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates , (&rrPrivKeyRec))); | |||
| 440 | if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) { | |||
| 441 | has_primary = 1; | |||
| 442 | primary_crtc = pScrPriv->primaryOutput->crtc; | |||
| 443 | crtcs[0] = pScrPriv->primaryOutput->crtc->id; | |||
| 444 | if (client->swapped) | |||
| 445 | 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); | |||
| 446 | crtc_count = 1; | |||
| 447 | } | |||
| 448 | 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); | |||
| 449 | ||||
| 450 | xorg_list_for_each_entry(iter, &pScreen->output_slave_list, output_head)for (iter = ((void*)0), 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))) { | |||
| 451 | pScrPriv = rrGetScrPriv(iter)((rrScrPrivPtr)dixLookupPrivate(&(iter)->devPrivates, ( &rrPrivKeyRec))); | |||
| 452 | ||||
| 453 | 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); | |||
| 454 | } | |||
| 455 | ||||
| 456 | 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", 456 , "bytes_to_int32((char *) names - (char *) extra) == rep.length" ) : (void)0); | |||
| 457 | if (client->swapped) { | |||
| 458 | 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); | |||
| 459 | 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); | |||
| 460 | 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); | |||
| 461 | 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); | |||
| 462 | 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); | |||
| 463 | 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); | |||
| 464 | 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); | |||
| 465 | 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); | |||
| 466 | } | |||
| 467 | WriteToClient(client, sizeof(xRRGetScreenResourcesReply), &rep); | |||
| 468 | if (extraLen) { | |||
| 469 | WriteToClient(client, extraLen, extra); | |||
| 470 | free(extra); | |||
| 471 | } | |||
| 472 | return Success0; | |||
| 473 | } | |||
| 474 | ||||
| 475 | static int | |||
| 476 | rrGetScreenResources(ClientPtr client, Bool query) | |||
| 477 | { | |||
| 478 | REQUEST(xRRGetScreenResourcesReq)xRRGetScreenResourcesReq *stuff = (xRRGetScreenResourcesReq * )client->requestBuffer; | |||
| 479 | xRRGetScreenResourcesReply rep; | |||
| 480 | WindowPtr pWin; | |||
| 481 | ScreenPtr pScreen; | |||
| 482 | rrScrPrivPtr pScrPriv; | |||
| 483 | CARD8 *extra; | |||
| 484 | unsigned long extraLen; | |||
| 485 | int i, rc, has_primary = 0; | |||
| 486 | RRCrtc *crtcs; | |||
| 487 | RROutput *outputs; | |||
| 488 | xRRModeInfo *modeinfos; | |||
| 489 | CARD8 *names; | |||
| 490 | ||||
| 491 | REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq)if ((sizeof(xRRGetScreenResourcesReq) >> 2) != client-> req_len) return(16); | |||
| 492 | rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4)); | |||
| 493 | if (rc != Success0) | |||
| 494 | return rc; | |||
| 495 | ||||
| 496 | pScreen = pWin->drawable.pScreen; | |||
| 497 | pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates , (&rrPrivKeyRec))); | |||
| 498 | ||||
| 499 | if (query && pScrPriv) | |||
| 500 | if (!RRGetInfo(pScreen, query)) | |||
| 501 | return BadAlloc11; | |||
| 502 | ||||
| 503 | if (!xorg_list_is_empty(&pScreen->output_slave_list)) | |||
| 504 | return rrGetMultiScreenResources(client, query, pScreen); | |||
| 505 | ||||
| 506 | if (!pScrPriv) { | |||
| 507 | rep = (xRRGetScreenResourcesReply) { | |||
| 508 | .type = X_Reply1, | |||
| 509 | .sequenceNumber = client->sequence, | |||
| 510 | .length = 0, | |||
| 511 | .timestamp = currentTime.milliseconds, | |||
| 512 | .configTimestamp = currentTime.milliseconds, | |||
| 513 | .nCrtcs = 0, | |||
| 514 | .nOutputs = 0, | |||
| 515 | .nModes = 0, | |||
| 516 | .nbytesNames = 0 | |||
| 517 | }; | |||
| 518 | extra = NULL((void*)0); | |||
| 519 | extraLen = 0; | |||
| 520 | } | |||
| 521 | else { | |||
| 522 | RRModePtr *modes; | |||
| 523 | int num_modes; | |||
| 524 | ||||
| 525 | modes = RRModesForScreen(pScreen, &num_modes); | |||
| 526 | if (!modes) | |||
| 527 | return BadAlloc11; | |||
| 528 | ||||
| 529 | rep = (xRRGetScreenResourcesReply) { | |||
| 530 | .type = X_Reply1, | |||
| 531 | .sequenceNumber = client->sequence, | |||
| 532 | .length = 0, | |||
| 533 | .timestamp = pScrPriv->lastSetTime.milliseconds, | |||
| 534 | .configTimestamp = pScrPriv->lastConfigTime.milliseconds, | |||
| 535 | .nCrtcs = pScrPriv->numCrtcs, | |||
| 536 | .nOutputs = pScrPriv->numOutputs, | |||
| 537 | .nModes = num_modes, | |||
| 538 | .nbytesNames = 0 | |||
| 539 | }; | |||
| 540 | ||||
| 541 | ||||
| 542 | for (i = 0; i < num_modes; i++) | |||
| 543 | rep.nbytesNames += modes[i]->mode.nameLength; | |||
| 544 | ||||
| 545 | rep.length = (pScrPriv->numCrtcs + | |||
| 546 | pScrPriv->numOutputs + | |||
| 547 | num_modes * bytes_to_int32(SIZEOF(xRRModeInfo)32) + | |||
| 548 | bytes_to_int32(rep.nbytesNames)); | |||
| 549 | ||||
| 550 | extraLen = rep.length << 2; | |||
| 551 | if (extraLen) { | |||
| 552 | extra = malloc(extraLen); | |||
| 553 | if (!extra) { | |||
| 554 | free(modes); | |||
| 555 | return BadAlloc11; | |||
| 556 | } | |||
| 557 | } | |||
| 558 | else | |||
| 559 | extra = NULL((void*)0); | |||
| 560 | ||||
| 561 | crtcs = (RRCrtc *) extra; | |||
| 562 | outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs); | |||
| 563 | modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs); | |||
| 564 | names = (CARD8 *) (modeinfos + num_modes); | |||
| 565 | ||||
| 566 | if (pScrPriv->primaryOutput && pScrPriv->primaryOutput->crtc) { | |||
| 567 | has_primary = 1; | |||
| 568 | crtcs[0] = pScrPriv->primaryOutput->crtc->id; | |||
| 569 | if (client->swapped) | |||
| 570 | 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); | |||
| 571 | } | |||
| 572 | ||||
| 573 | for (i = 0; i < pScrPriv->numCrtcs; i++) { | |||
| 574 | if (has_primary && | |||
| 575 | pScrPriv->primaryOutput->crtc == pScrPriv->crtcs[i]) { | |||
| 576 | has_primary = 0; | |||
| 577 | continue; | |||
| 578 | } | |||
| 579 | crtcs[i + has_primary] = pScrPriv->crtcs[i]->id; | |||
| 580 | if (client->swapped) | |||
| 581 | 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); | |||
| 582 | } | |||
| 583 | ||||
| 584 | for (i = 0; i < pScrPriv->numOutputs; i++) { | |||
| 585 | outputs[i] = pScrPriv->outputs[i]->id; | |||
| 586 | if (client->swapped) | |||
| 587 | 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); | |||
| 588 | } | |||
| 589 | ||||
| 590 | for (i = 0; i < num_modes; i++) { | |||
| 591 | RRModePtr mode = modes[i]; | |||
| 592 | ||||
| 593 | modeinfos[i] = mode->mode; | |||
| 594 | if (client->swapped) { | |||
| 595 | 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); | |||
| 596 | 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); | |||
| 597 | 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); | |||
| 598 | 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); | |||
| 599 | 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); | |||
| 600 | 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); | |||
| 601 | 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); | |||
| 602 | 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); | |||
| 603 | 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); | |||
| 604 | 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); | |||
| 605 | 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); | |||
| 606 | 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); | |||
| 607 | 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); | |||
| 608 | } | |||
| 609 | memcpy(names, mode->name, mode->mode.nameLength)__builtin___memcpy_chk (names, mode->name, mode->mode.nameLength , __builtin_object_size (names, 0)); | |||
| 610 | names += mode->mode.nameLength; | |||
| 611 | } | |||
| 612 | free(modes); | |||
| 613 | 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", 613 , "bytes_to_int32((char *) names - (char *) extra) == rep.length" ) : (void)0); | |||
| 614 | } | |||
| 615 | ||||
| 616 | if (client->swapped) { | |||
| 617 | 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); | |||
| 618 | 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); | |||
| 619 | 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); | |||
| 620 | 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); | |||
| 621 | 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); | |||
| 622 | 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); | |||
| 623 | 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); | |||
| 624 | 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); | |||
| 625 | } | |||
| 626 | WriteToClient(client, sizeof(xRRGetScreenResourcesReply), (char *) &rep); | |||
| 627 | if (extraLen) { | |||
| 628 | WriteToClient(client, extraLen, (char *) extra); | |||
| 629 | free(extra); | |||
| 630 | } | |||
| 631 | return Success0; | |||
| 632 | } | |||
| 633 | ||||
| 634 | int | |||
| 635 | ProcRRGetScreenResources(ClientPtr client) | |||
| 636 | { | |||
| 637 | return rrGetScreenResources(client, TRUE1); | |||
| 638 | } | |||
| 639 | ||||
| 640 | int | |||
| 641 | ProcRRGetScreenResourcesCurrent(ClientPtr client) | |||
| 642 | { | |||
| 643 | return rrGetScreenResources(client, FALSE0); | |||
| 644 | } | |||
| 645 | ||||
| 646 | typedef struct _RR10Data { | |||
| 647 | RRScreenSizePtr sizes; | |||
| 648 | int nsize; | |||
| 649 | int nrefresh; | |||
| 650 | int size; | |||
| 651 | CARD16 refresh; | |||
| 652 | } RR10DataRec, *RR10DataPtr; | |||
| 653 | ||||
| 654 | /* | |||
| 655 | * Convert 1.2 monitor data into 1.0 screen data | |||
| 656 | */ | |||
| 657 | static RR10DataPtr | |||
| 658 | RR10GetData(ScreenPtr pScreen, RROutputPtr output) | |||
| 659 | { | |||
| 660 | RR10DataPtr data; | |||
| 661 | RRScreenSizePtr size; | |||
| 662 | int nmode = output->numModes + output->numUserModes; | |||
| 663 | int o, os, l, r; | |||
| 664 | RRScreenRatePtr refresh; | |||
| 665 | CARD16 vRefresh; | |||
| 666 | RRModePtr mode; | |||
| 667 | Bool *used; | |||
| 668 | ||||
| 669 | /* Make sure there is plenty of space for any combination */ | |||
| 670 | data = malloc(sizeof(RR10DataRec) + | |||
| 671 | sizeof(RRScreenSize) * nmode + | |||
| 672 | sizeof(RRScreenRate) * nmode + sizeof(Bool) * nmode); | |||
| 673 | if (!data) | |||
| 674 | return NULL((void*)0); | |||
| 675 | size = (RRScreenSizePtr) (data + 1); | |||
| 676 | refresh = (RRScreenRatePtr) (size + nmode); | |||
| 677 | used = (Bool *) (refresh + nmode); | |||
| 678 | memset(used, '\0', sizeof(Bool) * nmode)__builtin___memset_chk (used, '\0', sizeof(Bool) * nmode, __builtin_object_size (used, 0)); | |||
| 679 | data->sizes = size; | |||
| 680 | data->nsize = 0; | |||
| 681 | data->nrefresh = 0; | |||
| 682 | data->size = 0; | |||
| 683 | data->refresh = 0; | |||
| 684 | ||||
| 685 | /* | |||
| 686 | * find modes not yet listed | |||
| 687 | */ | |||
| 688 | for (o = 0; o < output->numModes + output->numUserModes; o++) { | |||
| 689 | if (used[o]) | |||
| 690 | continue; | |||
| 691 | ||||
| 692 | if (o < output->numModes) | |||
| 693 | mode = output->modes[o]; | |||
| 694 | else | |||
| 695 | mode = output->userModes[o - output->numModes]; | |||
| 696 | ||||
| 697 | l = data->nsize; | |||
| 698 | size[l].id = data->nsize; | |||
| 699 | size[l].width = mode->mode.width; | |||
| 700 | size[l].height = mode->mode.height; | |||
| 701 | if (output->mmWidth && output->mmHeight) { | |||
| 702 | size[l].mmWidth = output->mmWidth; | |||
| 703 | size[l].mmHeight = output->mmHeight; | |||
| 704 | } | |||
| 705 | else { | |||
| 706 | size[l].mmWidth = pScreen->mmWidth; | |||
| 707 | size[l].mmHeight = pScreen->mmHeight; | |||
| 708 | } | |||
| 709 | size[l].nRates = 0; | |||
| 710 | size[l].pRates = &refresh[data->nrefresh]; | |||
| 711 | data->nsize++; | |||
| 712 | ||||
| 713 | /* | |||
| 714 | * Find all modes with matching size | |||
| 715 | */ | |||
| 716 | for (os = o; os < output->numModes + output->numUserModes; os++) { | |||
| 717 | if (os < output->numModes) | |||
| 718 | mode = output->modes[os]; | |||
| 719 | else | |||
| 720 | mode = output->userModes[os - output->numModes]; | |||
| 721 | if (mode->mode.width == size[l].width && | |||
| 722 | mode->mode.height == size[l].height) { | |||
| 723 | vRefresh = RRVerticalRefresh(&mode->mode); | |||
| 724 | used[os] = TRUE1; | |||
| 725 | ||||
| 726 | for (r = 0; r < size[l].nRates; r++) | |||
| 727 | if (vRefresh == size[l].pRates[r].rate) | |||
| 728 | break; | |||
| 729 | if (r == size[l].nRates) { | |||
| 730 | size[l].pRates[r].rate = vRefresh; | |||
| 731 | size[l].pRates[r].mode = mode; | |||
| 732 | size[l].nRates++; | |||
| 733 | data->nrefresh++; | |||
| 734 | } | |||
| 735 | if (mode == output->crtc->mode) { | |||
| 736 | data->size = l; | |||
| 737 | data->refresh = vRefresh; | |||
| 738 | } | |||
| 739 | } | |||
| 740 | } | |||
| 741 | } | |||
| 742 | return data; | |||
| 743 | } | |||
| 744 | ||||
| 745 | int | |||
| 746 | ProcRRGetScreenInfo(ClientPtr client) | |||
| 747 | { | |||
| 748 | REQUEST(xRRGetScreenInfoReq)xRRGetScreenInfoReq *stuff = (xRRGetScreenInfoReq *)client-> requestBuffer; | |||
| 749 | xRRGetScreenInfoReply rep; | |||
| 750 | WindowPtr pWin; | |||
| 751 | int rc; | |||
| 752 | ScreenPtr pScreen; | |||
| 753 | rrScrPrivPtr pScrPriv; | |||
| 754 | CARD8 *extra; | |||
| 755 | unsigned long extraLen; | |||
| 756 | RROutputPtr output; | |||
| 757 | ||||
| 758 | REQUEST_SIZE_MATCH(xRRGetScreenInfoReq)if ((sizeof(xRRGetScreenInfoReq) >> 2) != client->req_len ) return(16); | |||
| 759 | rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4)); | |||
| 760 | if (rc != Success0) | |||
| ||||
| 761 | return rc; | |||
| 762 | ||||
| 763 | pScreen = pWin->drawable.pScreen; | |||
| 764 | pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates , (&rrPrivKeyRec))); | |||
| 765 | ||||
| 766 | if (pScrPriv) | |||
| 767 | if (!RRGetInfo(pScreen, TRUE1)) | |||
| 768 | return BadAlloc11; | |||
| 769 | ||||
| 770 | output = RRFirstOutput(pScreen); | |||
| 771 | ||||
| 772 | if (!pScrPriv || !output) { | |||
| 773 | rep = (xRRGetScreenInfoReply) { | |||
| 774 | .type = X_Reply1, | |||
| 775 | .setOfRotations = RR_Rotate_01, | |||
| 776 | .sequenceNumber = client->sequence, | |||
| 777 | .length = 0, | |||
| 778 | .root = pWin->drawable.pScreen->root->drawable.id, | |||
| 779 | .timestamp = currentTime.milliseconds, | |||
| 780 | .configTimestamp = currentTime.milliseconds, | |||
| 781 | .nSizes = 0, | |||
| 782 | .sizeID = 0, | |||
| 783 | .rotation = RR_Rotate_01, | |||
| 784 | .rate = 0, | |||
| 785 | .nrateEnts = 0 | |||
| 786 | }; | |||
| 787 | extra = 0; | |||
| 788 | extraLen = 0; | |||
| 789 | } | |||
| 790 | else { | |||
| 791 | int i, j; | |||
| 792 | xScreenSizes *size; | |||
| 793 | CARD16 *rates; | |||
| 794 | CARD8 *data8; | |||
| 795 | Bool has_rate = RRClientKnowsRates(client); | |||
| 796 | RR10DataPtr pData; | |||
| 797 | RRScreenSizePtr pSize; | |||
| 798 | ||||
| 799 | pData = RR10GetData(pScreen, output); | |||
| 800 | if (!pData) | |||
| 801 | return BadAlloc11; | |||
| 802 | ||||
| 803 | rep = (xRRGetScreenInfoReply) { | |||
| 804 | .type = X_Reply1, | |||
| 805 | .setOfRotations = output->crtc->rotations, | |||
| 806 | .sequenceNumber = client->sequence, | |||
| 807 | .length = 0, | |||
| 808 | .root = pWin->drawable.pScreen->root->drawable.id, | |||
| 809 | .timestamp = pScrPriv->lastSetTime.milliseconds, | |||
| 810 | .configTimestamp = pScrPriv->lastConfigTime.milliseconds, | |||
| 811 | .rotation = output->crtc->rotation, | |||
| 812 | .nSizes = pData->nsize, | |||
| 813 | .nrateEnts = pData->nrefresh + pData->nsize, | |||
| 814 | .sizeID = pData->size, | |||
| 815 | .rate = pData->refresh | |||
| 816 | }; | |||
| 817 | ||||
| 818 | extraLen = rep.nSizes * sizeof(xScreenSizes); | |||
| 819 | if (has_rate) | |||
| 820 | extraLen += rep.nrateEnts * sizeof(CARD16); | |||
| 821 | ||||
| 822 | if (extraLen) { | |||
| 823 | extra = (CARD8 *) malloc(extraLen); | |||
| 824 | if (!extra) { | |||
| 825 | free(pData); | |||
| 826 | return BadAlloc11; | |||
| 827 | } | |||
| 828 | } | |||
| 829 | else | |||
| 830 | extra = NULL((void*)0); | |||
| 831 | ||||
| 832 | /* | |||
| 833 | * First comes the size information | |||
| 834 | */ | |||
| 835 | size = (xScreenSizes *) extra; | |||
| 836 | rates = (CARD16 *) (size + rep.nSizes); | |||
| 837 | for (i = 0; i < pData->nsize; i++) { | |||
| 838 | pSize = &pData->sizes[i]; | |||
| 839 | size->widthInPixels = pSize->width; | |||
| ||||
| 840 | size->heightInPixels = pSize->height; | |||
| 841 | size->widthInMillimeters = pSize->mmWidth; | |||
| 842 | size->heightInMillimeters = pSize->mmHeight; | |||
| 843 | if (client->swapped) { | |||
| 844 | 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); | |||
| 845 | 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); | |||
| 846 | 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); | |||
| 847 | 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); | |||
| 848 | } | |||
| 849 | size++; | |||
| 850 | if (has_rate) { | |||
| 851 | *rates = pSize->nRates; | |||
| 852 | if (client->swapped) { | |||
| 853 | 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); | |||
| 854 | } | |||
| 855 | rates++; | |||
| 856 | for (j = 0; j < pSize->nRates; j++) { | |||
| 857 | *rates = pSize->pRates[j].rate; | |||
| 858 | if (client->swapped) { | |||
| 859 | 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); | |||
| 860 | } | |||
| 861 | rates++; | |||
| 862 | } | |||
| 863 | } | |||
| 864 | } | |||
| 865 | free(pData); | |||
| 866 | ||||
| 867 | data8 = (CARD8 *) rates; | |||
| 868 | ||||
| 869 | if (data8 - (CARD8 *) extra != extraLen) | |||
| 870 | FatalError("RRGetScreenInfo bad extra len %ld != %ld\n", | |||
| 871 | (unsigned long) (data8 - (CARD8 *) extra), extraLen); | |||
| 872 | rep.length = bytes_to_int32(extraLen); | |||
| 873 | } | |||
| 874 | if (client->swapped) { | |||
| 875 | 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); | |||
| 876 | 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); | |||
| 877 | 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); | |||
| 878 | 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); | |||
| 879 | 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); | |||
| 880 | 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); | |||
| 881 | 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); | |||
| 882 | 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); | |||
| 883 | 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); | |||
| 884 | } | |||
| 885 | WriteToClient(client, sizeof(xRRGetScreenInfoReply), &rep); | |||
| 886 | if (extraLen) { | |||
| 887 | WriteToClient(client, extraLen, extra); | |||
| 888 | free(extra); | |||
| 889 | } | |||
| 890 | return Success0; | |||
| 891 | } | |||
| 892 | ||||
| 893 | int | |||
| 894 | ProcRRSetScreenConfig(ClientPtr client) | |||
| 895 | { | |||
| 896 | REQUEST(xRRSetScreenConfigReq)xRRSetScreenConfigReq *stuff = (xRRSetScreenConfigReq *)client ->requestBuffer; | |||
| 897 | xRRSetScreenConfigReply rep; | |||
| 898 | DrawablePtr pDraw; | |||
| 899 | int rc; | |||
| 900 | ScreenPtr pScreen; | |||
| 901 | rrScrPrivPtr pScrPriv; | |||
| 902 | TimeStamp time; | |||
| 903 | int i; | |||
| 904 | Rotation rotation; | |||
| 905 | int rate; | |||
| 906 | Bool has_rate; | |||
| 907 | CARD8 status; | |||
| 908 | RROutputPtr output; | |||
| 909 | RRCrtcPtr crtc; | |||
| 910 | RRModePtr mode; | |||
| 911 | RR10DataPtr pData = NULL((void*)0); | |||
| 912 | RRScreenSizePtr pSize; | |||
| 913 | int width, height; | |||
| 914 | ||||
| 915 | UpdateCurrentTime(); | |||
| 916 | ||||
| 917 | if (RRClientKnowsRates(client)) { | |||
| 918 | REQUEST_SIZE_MATCH(xRRSetScreenConfigReq)if ((sizeof(xRRSetScreenConfigReq) >> 2) != client-> req_len) return(16); | |||
| 919 | has_rate = TRUE1; | |||
| 920 | } | |||
| 921 | else { | |||
| 922 | REQUEST_SIZE_MATCH(xRR1_0SetScreenConfigReq)if ((sizeof(xRR1_0SetScreenConfigReq) >> 2) != client-> req_len) return(16); | |||
| 923 | has_rate = FALSE0; | |||
| 924 | } | |||
| 925 | ||||
| 926 | rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess(1<<1)); | |||
| 927 | if (rc != Success0) | |||
| 928 | return rc; | |||
| 929 | ||||
| 930 | pScreen = pDraw->pScreen; | |||
| 931 | ||||
| 932 | pScrPriv = rrGetScrPriv(pScreen)((rrScrPrivPtr)dixLookupPrivate(&(pScreen)->devPrivates , (&rrPrivKeyRec))); | |||
| 933 | ||||
| 934 | time = ClientTimeToServerTime(stuff->timestamp); | |||
| 935 | ||||
| 936 | if (!pScrPriv) { | |||
| 937 | time = currentTime; | |||
| 938 | status = RRSetConfigFailed3; | |||
| 939 | goto sendReply; | |||
| 940 | } | |||
| 941 | if (!RRGetInfo(pScreen, FALSE0)) | |||
| 942 | return BadAlloc11; | |||
| 943 | ||||
| 944 | output = RRFirstOutput(pScreen); | |||
| 945 | if (!output) { | |||
| 946 | time = currentTime; | |||
| 947 | status = RRSetConfigFailed3; | |||
| 948 | goto sendReply; | |||
| 949 | } | |||
| 950 | ||||
| 951 | crtc = output->crtc; | |||
| 952 | ||||
| 953 | /* | |||
| 954 | * If the client's config timestamp is not the same as the last config | |||
| 955 | * timestamp, then the config information isn't up-to-date and | |||
| 956 | * can't even be validated. | |||
| 957 | * | |||
| 958 | * Note that the client only knows about the milliseconds part of the | |||
| 959 | * timestamp, so using CompareTimeStamps here would cause randr to suddenly | |||
| 960 | * stop working after several hours have passed (freedesktop bug #6502). | |||
| 961 | */ | |||
| 962 | if (stuff->configTimestamp != pScrPriv->lastConfigTime.milliseconds) { | |||
| 963 | status = RRSetConfigInvalidConfigTime1; | |||
| 964 | goto sendReply; | |||
| 965 | } | |||
| 966 | ||||
| 967 | pData = RR10GetData(pScreen, output); | |||
| 968 | if (!pData) | |||
| 969 | return BadAlloc11; | |||
| 970 | ||||
| 971 | if (stuff->sizeID >= pData->nsize) { | |||
| 972 | /* | |||
| 973 | * Invalid size ID | |||
| 974 | */ | |||
| 975 | client->errorValue = stuff->sizeID; | |||
| 976 | free(pData); | |||
| 977 | return BadValue2; | |||
| 978 | } | |||
| 979 | pSize = &pData->sizes[stuff->sizeID]; | |||
| 980 | ||||
| 981 | /* | |||
| 982 | * Validate requested rotation | |||
| 983 | */ | |||
| 984 | rotation = (Rotation) stuff->rotation; | |||
| 985 | ||||
| 986 | /* test the rotation bits only! */ | |||
| 987 | switch (rotation & 0xf) { | |||
| 988 | case RR_Rotate_01: | |||
| 989 | case RR_Rotate_902: | |||
| 990 | case RR_Rotate_1804: | |||
| 991 | case RR_Rotate_2708: | |||
| 992 | break; | |||
| 993 | default: | |||
| 994 | /* | |||
| 995 | * Invalid rotation | |||
| 996 | */ | |||
| 997 | client->errorValue = stuff->rotation; | |||
| 998 | free(pData); | |||
| 999 | return BadValue2; | |||
| 1000 | } | |||
| 1001 | ||||
| 1002 | if ((~crtc->rotations) & rotation) { | |||
| 1003 | /* | |||
| 1004 | * requested rotation or reflection not supported by screen | |||
| 1005 | */ | |||
| 1006 | client->errorValue = stuff->rotation; | |||
| 1007 | free(pData); | |||
| 1008 | return BadMatch8; | |||
| 1009 | } | |||
| 1010 | ||||
| 1011 | /* | |||
| 1012 | * Validate requested refresh | |||
| 1013 | */ | |||
| 1014 | if (has_rate) | |||
| 1015 | rate = (int) stuff->rate; | |||
| 1016 | else | |||
| 1017 | rate = 0; | |||
| 1018 | ||||
| 1019 | if (rate) { | |||
| 1020 | for (i = 0; i < pSize->nRates; i++) { | |||
| 1021 | if (pSize->pRates[i].rate == rate) | |||
| 1022 | break; | |||
| 1023 | } | |||
| 1024 | if (i == pSize->nRates) { | |||
| 1025 | /* | |||
| 1026 | * Invalid rate | |||
| 1027 | */ | |||
| 1028 | client->errorValue = rate; | |||
| 1029 | free(pData); | |||
| 1030 | return BadValue2; | |||
| 1031 | } | |||
| 1032 | mode = pSize->pRates[i].mode; | |||
| 1033 | } | |||
| 1034 | else | |||
| 1035 | mode = pSize->pRates[0].mode; | |||
| 1036 | ||||
| 1037 | /* | |||
| 1038 | * Make sure the requested set-time is not older than | |||
| 1039 | * the last set-time | |||
| 1040 | */ | |||
| 1041 | if (CompareTimeStamps(time, pScrPriv->lastSetTime) < 0) { | |||
| 1042 | status = RRSetConfigInvalidTime2; | |||
| 1043 | goto sendReply; | |||
| 1044 | } | |||
| 1045 | ||||
| 1046 | /* | |||
| 1047 | * If the screen size is changing, adjust all of the other outputs | |||
| 1048 | * to fit the new size, mirroring as much as possible | |||
| 1049 | */ | |||
| 1050 | width = mode->mode.width; | |||
| 1051 | height = mode->mode.height; | |||
| 1052 | if (width < pScrPriv->minWidth || pScrPriv->maxWidth < width) { | |||
| 1053 | client->errorValue = width; | |||
| 1054 | free(pData); | |||
| 1055 | return BadValue2; | |||
| 1056 | } | |||
| 1057 | if (height < pScrPriv->minHeight || pScrPriv->maxHeight < height) { | |||
| 1058 | client->errorValue = height; | |||
| 1059 | free(pData); | |||
| 1060 | return BadValue2; | |||
| 1061 | } | |||
| 1062 | ||||
| 1063 | if (rotation & (RR_Rotate_902 | RR_Rotate_2708)) { | |||
| 1064 | width = mode->mode.height; | |||
| 1065 | height = mode->mode.width; | |||
| 1066 | } | |||
| 1067 | ||||
| 1068 | if (width != pScreen->width || height != pScreen->height) { | |||
| 1069 | int c; | |||
| 1070 | ||||
| 1071 | for (c = 0; c < pScrPriv->numCrtcs; c++) { | |||
| 1072 | if (!RRCrtcSet(pScrPriv->crtcs[c], NULL((void*)0), 0, 0, RR_Rotate_01, | |||
| 1073 | 0, NULL((void*)0))) { | |||
| 1074 | status = RRSetConfigFailed3; | |||
| 1075 | /* XXX recover from failure */ | |||
| 1076 | goto sendReply; | |||
| 1077 | } | |||
| 1078 | } | |||
| 1079 | if (!RRScreenSizeSet(pScreen, width, height, | |||
| 1080 | pScreen->mmWidth, pScreen->mmHeight)) { | |||
| 1081 | status = RRSetConfigFailed3; | |||
| 1082 | /* XXX recover from failure */ | |||
| 1083 | goto sendReply; | |||
| 1084 | } | |||
| 1085 | } | |||
| 1086 | ||||
| 1087 | if (!RRCrtcSet(crtc, mode, 0, 0, stuff->rotation, 1, &output)) | |||
| 1088 | status = RRSetConfigFailed3; | |||
| 1089 | else { | |||
| 1090 | pScrPriv->lastSetTime = time; | |||
| 1091 | status = RRSetConfigSuccess0; | |||
| 1092 | } | |||
| 1093 | ||||
| 1094 | /* | |||
| 1095 | * XXX Configure other crtcs to mirror as much as possible | |||
| 1096 | */ | |||
| 1097 | ||||
| 1098 | sendReply: | |||
| 1099 | ||||
| 1100 | free(pData); | |||
| 1101 | ||||
| 1102 | rep = (xRRSetScreenConfigReply) { | |||
| 1103 | .type = X_Reply1, | |||
| 1104 | .status = status, | |||
| 1105 | .sequenceNumber = client->sequence, | |||
| 1106 | .length = 0, | |||
| 1107 | ||||
| 1108 | .newTimestamp = pScrPriv->lastSetTime.milliseconds, | |||
| 1109 | .newConfigTimestamp = pScrPriv->lastConfigTime.milliseconds, | |||
| 1110 | .root = pDraw->pScreen->root->drawable.id, | |||
| 1111 | /* .subpixelOrder = ?? */ | |||
| 1112 | }; | |||
| 1113 | ||||
| 1114 | if (client->swapped) { | |||
| 1115 | 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); | |||
| 1116 | 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); | |||
| 1117 | 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); | |||
| 1118 | 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); | |||
| 1119 | 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); | |||
| 1120 | } | |||
| 1121 | WriteToClient(client, sizeof(xRRSetScreenConfigReply), &rep); | |||
| 1122 | ||||
| 1123 | return Success0; | |||
| 1124 | } | |||
| 1125 | ||||
| 1126 | static CARD16 | |||
| 1127 | RR10CurrentSizeID(ScreenPtr pScreen) | |||
| 1128 | { | |||
| 1129 | CARD16 sizeID = 0xffff; | |||
| 1130 | RROutputPtr output = RRFirstOutput(pScreen); | |||
| 1131 | ||||
| 1132 | if (output) { | |||
| 1133 | RR10DataPtr data = RR10GetData(pScreen, output); | |||
| 1134 | ||||
| 1135 | if (data) { | |||
| 1136 | int i; | |||
| 1137 | ||||
| 1138 | for (i = 0; i < data->nsize; i++) | |||
| 1139 | if (data->sizes[i].width == pScreen->width && | |||
| 1140 | data->sizes[i].height == pScreen->height) { | |||
| 1141 | sizeID = (CARD16) i; | |||
| 1142 | break; | |||
| 1143 | } | |||
| 1144 | free(data); | |||
| 1145 | } | |||
| 1146 | } | |||
| 1147 | return sizeID; | |||
| 1148 | } |