| 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 int |
| 26 | SProcRRQueryVersion(ClientPtr client) |
| 27 | { |
| 28 | REQUEST(xRRQueryVersionReq); |
| 29 | |
| 30 | swaps(&stuff->length); |
| 31 | swapl(&stuff->majorVersion); |
| 32 | swapl(&stuff->minorVersion); |
| 33 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 34 | } |
| 35 | |
| 36 | static int |
| 37 | SProcRRGetScreenInfo(ClientPtr client) |
| 38 | { |
| 39 | REQUEST(xRRGetScreenInfoReq); |
| 40 | |
| 41 | swaps(&stuff->length); |
| 42 | swapl(&stuff->window); |
| 43 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 44 | } |
| 45 | |
| 46 | static int |
| 47 | SProcRRSetScreenConfig(ClientPtr client) |
| 48 | { |
| 49 | REQUEST(xRRSetScreenConfigReq); |
| 50 | |
| 51 | if (RRClientKnowsRates(client)) { |
| 52 | REQUEST_SIZE_MATCH(xRRSetScreenConfigReq); |
| 53 | swaps(&stuff->rate); |
| 54 | } |
| 55 | else { |
| 56 | REQUEST_SIZE_MATCH(xRR1_0SetScreenConfigReq); |
| 57 | } |
| 58 | |
| 59 | swaps(&stuff->length); |
| 60 | swapl(&stuff->drawable); |
| 61 | swapl(&stuff->timestamp); |
| 62 | swaps(&stuff->sizeID); |
| 63 | swaps(&stuff->rotation); |
| 64 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 65 | } |
| 66 | |
| 67 | static int |
| 68 | SProcRRSelectInput(ClientPtr client) |
| 69 | { |
| 70 | REQUEST(xRRSelectInputReq); |
| 71 | |
| 72 | swaps(&stuff->length); |
| 73 | swapl(&stuff->window); |
| 74 | swaps(&stuff->enable); |
| 75 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 76 | } |
| 77 | |
| 78 | static int |
| 79 | SProcRRGetScreenSizeRange(ClientPtr client) |
| 80 | { |
| 81 | REQUEST(xRRGetScreenSizeRangeReq); |
| 82 | |
| 83 | REQUEST_SIZE_MATCH(xRRGetScreenSizeRangeReq); |
| 84 | swaps(&stuff->length); |
| 85 | swapl(&stuff->window); |
| 86 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 87 | } |
| 88 | |
| 89 | static int |
| 90 | SProcRRSetScreenSize(ClientPtr client) |
| 91 | { |
| 92 | REQUEST(xRRSetScreenSizeReq); |
| 93 | |
| 94 | REQUEST_SIZE_MATCH(xRRSetScreenSizeReq); |
| 95 | swaps(&stuff->length); |
| 96 | swapl(&stuff->window); |
| 97 | swaps(&stuff->width); |
| 98 | swaps(&stuff->height); |
| 99 | swapl(&stuff->widthInMillimeters); |
| 100 | swapl(&stuff->heightInMillimeters); |
| 101 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 102 | } |
| 103 | |
| 104 | static int |
| 105 | SProcRRGetScreenResources(ClientPtr client) |
| 106 | { |
| 107 | REQUEST(xRRGetScreenResourcesReq); |
| 108 | |
| 109 | REQUEST_SIZE_MATCH(xRRGetScreenResourcesReq); |
| 110 | swaps(&stuff->length); |
| 111 | swapl(&stuff->window); |
| 112 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 113 | } |
| 114 | |
| 115 | static int |
| 116 | SProcRRGetOutputInfo(ClientPtr client) |
| 117 | { |
| 118 | REQUEST(xRRGetOutputInfoReq); |
| 119 | |
| 120 | REQUEST_SIZE_MATCH(xRRGetOutputInfoReq); |
| 121 | swaps(&stuff->length); |
| 122 | swapl(&stuff->output); |
| 123 | swapl(&stuff->configTimestamp); |
| 124 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 125 | } |
| 126 | |
| 127 | static int |
| 128 | SProcRRListOutputProperties(ClientPtr client) |
| 129 | { |
| 130 | REQUEST(xRRListOutputPropertiesReq); |
| 131 | |
| 132 | REQUEST_SIZE_MATCH(xRRListOutputPropertiesReq); |
| 133 | swaps(&stuff->length); |
| 134 | swapl(&stuff->output); |
| 135 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 136 | } |
| 137 | |
| 138 | static int |
| 139 | SProcRRQueryOutputProperty(ClientPtr client) |
| 140 | { |
| 141 | REQUEST(xRRQueryOutputPropertyReq); |
| 142 | |
| 143 | REQUEST_SIZE_MATCH(xRRQueryOutputPropertyReq); |
| 144 | swaps(&stuff->length); |
| 145 | swapl(&stuff->output); |
| 146 | swapl(&stuff->property); |
| 147 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 148 | } |
| 149 | |
| 150 | static int |
| 151 | SProcRRConfigureOutputProperty(ClientPtr client) |
| 152 | { |
| 153 | REQUEST(xRRConfigureOutputPropertyReq); |
| 154 | |
| 155 | swaps(&stuff->length); |
| 156 | swapl(&stuff->output); |
| 157 | swapl(&stuff->property); |
| 158 | SwapRestL(stuff); |
| 159 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 160 | } |
| 161 | |
| 162 | static int |
| 163 | SProcRRChangeOutputProperty(ClientPtr client) |
| 164 | { |
| 165 | REQUEST(xRRChangeOutputPropertyReq); |
| 166 | |
| 167 | REQUEST_AT_LEAST_SIZE(xRRChangeOutputPropertyReq); |
| 168 | swaps(&stuff->length); |
| 169 | swapl(&stuff->output); |
| 170 | swapl(&stuff->property); |
| 171 | swapl(&stuff->type); |
| 172 | swapl(&stuff->nUnits); |
| 173 | switch (stuff->format) { |
| 174 | case 8: |
| 175 | break; |
| 176 | case 16: |
| 177 | SwapRestS(stuff); |
| 178 | break; |
| 179 | case 32: |
| 180 | SwapRestL(stuff); |
| 181 | break; |
| 182 | default: |
| 183 | client->errorValue = stuff->format; |
| 184 | return BadValue; |
| 185 | } |
| 186 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 187 | } |
| 188 | |
| 189 | static int |
| 190 | SProcRRDeleteOutputProperty(ClientPtr client) |
| 191 | { |
| 192 | REQUEST(xRRDeleteOutputPropertyReq); |
| 193 | |
| 194 | REQUEST_SIZE_MATCH(xRRDeleteOutputPropertyReq); |
| 195 | swaps(&stuff->length); |
| 196 | swapl(&stuff->output); |
| 197 | swapl(&stuff->property); |
| 198 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 199 | } |
| 200 | |
| 201 | static int |
| 202 | SProcRRGetOutputProperty(ClientPtr client) |
| 203 | { |
| 204 | REQUEST(xRRGetOutputPropertyReq); |
| 205 | |
| 206 | REQUEST_SIZE_MATCH(xRRGetOutputPropertyReq); |
| 207 | swaps(&stuff->length); |
| 208 | swapl(&stuff->output); |
| 209 | swapl(&stuff->property); |
| 210 | swapl(&stuff->type); |
| 211 | swapl(&stuff->longOffset); |
| 212 | swapl(&stuff->longLength); |
| 213 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 214 | } |
| 215 | |
| 216 | static int |
| 217 | SProcRRCreateMode(ClientPtr client) |
| 218 | { |
| 219 | xRRModeInfo *modeinfo; |
| 220 | |
| 221 | REQUEST(xRRCreateModeReq); |
| 222 | |
| 223 | REQUEST_AT_LEAST_SIZE(xRRCreateModeReq); |
| 224 | swaps(&stuff->length); |
| 225 | swapl(&stuff->window); |
| 226 | |
| 227 | modeinfo = &stuff->modeInfo; |
| 228 | swapl(&modeinfo->id); |
| 229 | swaps(&modeinfo->width); |
| 230 | swaps(&modeinfo->height); |
| 231 | swapl(&modeinfo->dotClock); |
| 232 | swaps(&modeinfo->hSyncStart); |
| 233 | swaps(&modeinfo->hSyncEnd); |
| 234 | swaps(&modeinfo->hTotal); |
| 235 | swaps(&modeinfo->vSyncStart); |
| 236 | swaps(&modeinfo->vSyncEnd); |
| 237 | swaps(&modeinfo->vTotal); |
| 238 | swaps(&modeinfo->nameLength); |
| 239 | swapl(&modeinfo->modeFlags); |
| 240 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 241 | } |
| 242 | |
| 243 | static int |
| 244 | SProcRRDestroyMode(ClientPtr client) |
| 245 | { |
| 246 | REQUEST(xRRDestroyModeReq); |
| 247 | |
| 248 | REQUEST_SIZE_MATCH(xRRDestroyModeReq); |
| 249 | swaps(&stuff->length); |
| 250 | swapl(&stuff->mode); |
| 251 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 252 | } |
| 253 | |
| 254 | static int |
| 255 | SProcRRAddOutputMode(ClientPtr client) |
| 256 | { |
| 257 | REQUEST(xRRAddOutputModeReq); |
| 258 | |
| 259 | REQUEST_SIZE_MATCH(xRRAddOutputModeReq); |
| 260 | swaps(&stuff->length); |
| 261 | swapl(&stuff->output); |
| 262 | swapl(&stuff->mode); |
| 263 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 264 | } |
| 265 | |
| 266 | static int |
| 267 | SProcRRDeleteOutputMode(ClientPtr client) |
| 268 | { |
| 269 | REQUEST(xRRDeleteOutputModeReq); |
| 270 | |
| 271 | REQUEST_SIZE_MATCH(xRRDeleteOutputModeReq); |
| 272 | swaps(&stuff->length); |
| 273 | swapl(&stuff->output); |
| 274 | swapl(&stuff->mode); |
| 275 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 276 | } |
| 277 | |
| 278 | static int |
| 279 | SProcRRGetCrtcInfo(ClientPtr client) |
| 280 | { |
| 281 | REQUEST(xRRGetCrtcInfoReq); |
| 282 | |
| 283 | REQUEST_SIZE_MATCH(xRRGetCrtcInfoReq); |
| 284 | swaps(&stuff->length); |
| 285 | swapl(&stuff->crtc); |
| 286 | swapl(&stuff->configTimestamp); |
| 287 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 288 | } |
| 289 | |
| 290 | static int |
| 291 | SProcRRSetCrtcConfig(ClientPtr client) |
| 292 | { |
| 293 | REQUEST(xRRSetCrtcConfigReq); |
| 294 | |
| 295 | REQUEST_AT_LEAST_SIZE(xRRSetCrtcConfigReq); |
| 296 | swaps(&stuff->length); |
| 297 | swapl(&stuff->crtc); |
| 298 | swapl(&stuff->timestamp); |
| 299 | swapl(&stuff->configTimestamp); |
| 300 | swaps(&stuff->x); |
| 301 | swaps(&stuff->y); |
| 302 | swapl(&stuff->mode); |
| 303 | swaps(&stuff->rotation); |
| 304 | SwapRestL(stuff); |
| 305 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 306 | } |
| 307 | |
| 308 | static int |
| 309 | SProcRRGetCrtcGammaSize(ClientPtr client) |
| 310 | { |
| 311 | REQUEST(xRRGetCrtcGammaSizeReq); |
| 312 | |
| 313 | REQUEST_SIZE_MATCH(xRRGetCrtcGammaSizeReq); |
| 314 | swaps(&stuff->length); |
| 315 | swapl(&stuff->crtc); |
| 316 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 317 | } |
| 318 | |
| 319 | static int |
| 320 | SProcRRGetCrtcGamma(ClientPtr client) |
| 321 | { |
| 322 | REQUEST(xRRGetCrtcGammaReq); |
| 323 | |
| 324 | REQUEST_SIZE_MATCH(xRRGetCrtcGammaReq); |
| 325 | swaps(&stuff->length); |
| 326 | swapl(&stuff->crtc); |
| 327 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 328 | } |
| 329 | |
| 330 | static int |
| 331 | SProcRRSetCrtcGamma(ClientPtr client) |
| 332 | { |
| 333 | REQUEST(xRRSetCrtcGammaReq); |
| 334 | |
| 335 | REQUEST_AT_LEAST_SIZE(xRRSetCrtcGammaReq); |
| 336 | swaps(&stuff->length); |
| 337 | swapl(&stuff->crtc); |
| 338 | swaps(&stuff->size); |
| 339 | SwapRestS(stuff); |
| 340 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 341 | } |
| 342 | |
| 343 | static int |
| 344 | SProcRRSetCrtcTransform(ClientPtr client) |
| 345 | { |
| 346 | int nparams; |
| 347 | char *filter; |
| 348 | CARD32 *params; |
| 349 | |
| 350 | REQUEST(xRRSetCrtcTransformReq); |
| 351 | |
| 352 | REQUEST_AT_LEAST_SIZE(xRRSetCrtcTransformReq); |
| 353 | swaps(&stuff->length); |
| 354 | swapl(&stuff->crtc); |
| 355 | SwapLongs((CARD32 *) &stuff->transform, |
| 356 | bytes_to_int32(sizeof(xRenderTransform))); |
| 357 | swaps(&stuff->nbytesFilter); |
| 358 | filter = (char *) (stuff + 1); |
| 359 | params = (CARD32 *) (filter + pad_to_int32(stuff->nbytesFilter)); |
| 360 | nparams = ((CARD32 *) stuff + client->req_len) - params; |
| 361 | if (nparams < 0) |
| 362 | return BadLength; |
| 363 | |
| 364 | SwapLongs(params, nparams); |
| 365 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 366 | } |
| 367 | |
| 368 | static int |
| 369 | SProcRRGetCrtcTransform(ClientPtr client) |
| 370 | { |
| 371 | REQUEST(xRRGetCrtcTransformReq); |
| 372 | |
| 373 | REQUEST_SIZE_MATCH(xRRGetCrtcTransformReq); |
| 374 | swaps(&stuff->length); |
| 375 | swapl(&stuff->crtc); |
| 376 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 377 | } |
| 378 | |
| 379 | static int |
| 380 | SProcRRGetPanning(ClientPtr client) |
| 381 | { |
| 382 | REQUEST(xRRGetPanningReq); |
| 383 | |
| 384 | REQUEST_SIZE_MATCH(xRRGetPanningReq); |
| 385 | swaps(&stuff->length); |
| 386 | swapl(&stuff->crtc); |
| 387 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 388 | } |
| 389 | |
| 390 | static int |
| 391 | SProcRRSetPanning(ClientPtr client) |
| 392 | { |
| 393 | REQUEST(xRRSetPanningReq); |
| 394 | |
| 395 | REQUEST_SIZE_MATCH(xRRSetPanningReq); |
| 396 | swaps(&stuff->length); |
| 397 | swapl(&stuff->crtc); |
| 398 | swapl(&stuff->timestamp); |
| 399 | swaps(&stuff->left); |
| 400 | swaps(&stuff->top); |
| 401 | swaps(&stuff->width); |
| 402 | swaps(&stuff->height); |
| 403 | swaps(&stuff->track_left); |
| 404 | swaps(&stuff->track_top); |
| 405 | swaps(&stuff->track_width); |
| 406 | swaps(&stuff->track_height); |
| 407 | swaps(&stuff->border_left); |
| 408 | swaps(&stuff->border_top); |
| 409 | swaps(&stuff->border_right); |
| 410 | swaps(&stuff->border_bottom); |
| 411 | return (*ProcRandrVector[stuff->randrReqType]) (client); |
| 412 | } |
| 413 | |
| 414 | static int |
| 415 | SProcRRSetOutputPrimary(ClientPtr client) |
| 416 | { |
| 417 | REQUEST(xRRSetOutputPrimaryReq); |
| 418 | |
| 419 | REQUEST_SIZE_MATCH(xRRSetOutputPrimaryReq); |
| 420 | swaps(&stuff->length); |
| 421 | swapl(&stuff->window); |
| 422 | swapl(&stuff->output); |
| 423 | return ProcRandrVector[stuff->randrReqType] (client); |
| 424 | } |
| 425 | |
| 426 | static int |
| 427 | SProcRRGetOutputPrimary(ClientPtr client) |
| 428 | { |
| 429 | REQUEST(xRRGetOutputPrimaryReq); |
| 430 | |
| 431 | REQUEST_SIZE_MATCH(xRRGetOutputPrimaryReq); |
| 432 | swaps(&stuff->length); |
| 433 | swapl(&stuff->window); |
| 434 | return ProcRandrVector[stuff->randrReqType] (client); |
| 435 | } |
| 436 | |
| 437 | int (*SProcRandrVector[RRNumberRequests]) (ClientPtr) = { |
| 438 | SProcRRQueryVersion, /* 0 */ |
| 439 | /* we skip 1 to make old clients fail pretty immediately */ |
| 440 | NULL, /* 1 SProcRandrOldGetScreenInfo */ |
| 441 | /* V1.0 apps share the same set screen config request id */ |
| 442 | SProcRRSetScreenConfig, /* 2 */ |
| 443 | NULL, /* 3 SProcRandrOldScreenChangeSelectInput */ |
| 444 | /* 3 used to be ScreenChangeSelectInput; deprecated */ |
| 445 | SProcRRSelectInput, /* 4 */ |
| 446 | SProcRRGetScreenInfo, /* 5 */ |
| 447 | /* V1.2 additions */ |
| 448 | SProcRRGetScreenSizeRange, /* 6 */ |
| 449 | SProcRRSetScreenSize, /* 7 */ |
| 450 | SProcRRGetScreenResources, /* 8 */ |
| 451 | SProcRRGetOutputInfo, /* 9 */ |
| 452 | SProcRRListOutputProperties, /* 10 */ |
| 453 | SProcRRQueryOutputProperty, /* 11 */ |
| 454 | SProcRRConfigureOutputProperty, /* 12 */ |
| 455 | SProcRRChangeOutputProperty, /* 13 */ |
| 456 | SProcRRDeleteOutputProperty, /* 14 */ |
| 457 | SProcRRGetOutputProperty, /* 15 */ |
| 458 | SProcRRCreateMode, /* 16 */ |
| 459 | SProcRRDestroyMode, /* 17 */ |
| 460 | SProcRRAddOutputMode, /* 18 */ |
| 461 | SProcRRDeleteOutputMode, /* 19 */ |
| 462 | SProcRRGetCrtcInfo, /* 20 */ |
| 463 | SProcRRSetCrtcConfig, /* 21 */ |
| 464 | SProcRRGetCrtcGammaSize, /* 22 */ |
| 465 | SProcRRGetCrtcGamma, /* 23 */ |
| 466 | SProcRRSetCrtcGamma, /* 24 */ |
| 467 | /* V1.3 additions */ |
| 468 | SProcRRGetScreenResources, /* 25 GetScreenResourcesCurrent */ |
| 469 | SProcRRSetCrtcTransform, /* 26 */ |
| 470 | SProcRRGetCrtcTransform, /* 27 */ |
| 471 | SProcRRGetPanning, /* 28 */ |
| 472 | SProcRRSetPanning, /* 29 */ |
| 473 | SProcRRSetOutputPrimary, /* 30 */ |
| 474 | SProcRRGetOutputPrimary, /* 31 */ |
| 475 | }; |