1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4 Copyright 2000 VA Linux Systems, Inc.
5 Copyright (c) 2002, 2009-2012 Apple Inc.
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sub license, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial portions
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
24 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
32 * Kevin E. Martin <martin@valinux.com>
33 * Jens Owen <jens@valinux.com>
34 * Rickard E. (Rik) Faith <faith@valinux.com>
35 * Jeremy Huddleston <jeremyhu@apple.com>
39 #ifdef HAVE_DIX_CONFIG_H
40 #include <dix-config.h>
44 #include <X11/Xproto.h>
46 #include "dixstruct.h"
47 #include "extnsionst.h"
48 #include "colormapst.h"
49 #include "cursorstr.h"
50 #include "scrnintstr.h"
52 #define _APPLEDRI_SERVER_
53 #include "appledristr.h"
56 #include "dristruct.h"
59 #include "protocol-versions.h"
61 static int DRIErrorBase
= 0;
64 AppleDRIResetProc(ExtensionEntry
* extEntry
);
66 ProcAppleDRICreatePixmap(ClientPtr client
);
68 static unsigned char DRIReqCode
= 0;
69 static int DRIEventBase
= 0;
72 SNotifyEvent(xAppleDRINotifyEvent
*from
, xAppleDRINotifyEvent
*to
);
74 typedef struct _DRIEvent
*DRIEventPtr
;
75 typedef struct _DRIEvent
{
84 AppleDRIResetProc(ExtensionEntry
* extEntry
)
90 ProcAppleDRIQueryVersion(register ClientPtr client
)
92 xAppleDRIQueryVersionReply rep
;
94 REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq
);
97 rep
.sequenceNumber
= client
->sequence
;
98 rep
.majorVersion
= SERVER_APPLEDRI_MAJOR_VERSION
;
99 rep
.minorVersion
= SERVER_APPLEDRI_MINOR_VERSION
;
100 rep
.patchVersion
= SERVER_APPLEDRI_PATCH_VERSION
;
101 if (client
->swapped
) {
102 swaps(&rep
.sequenceNumber
);
104 swaps(&rep
.majorVersion
);
105 swaps(&rep
.minorVersion
);
106 swapl(&rep
.patchVersion
);
108 WriteToClient(client
, sizeof(xAppleDRIQueryVersionReply
), &rep
);
115 ProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client
)
117 xAppleDRIQueryDirectRenderingCapableReply rep
;
120 REQUEST(xAppleDRIQueryDirectRenderingCapableReq
);
121 REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq
);
124 rep
.sequenceNumber
= client
->sequence
;
126 if (stuff
->screen
>= screenInfo
.numScreens
) {
130 if (!DRIQueryDirectRenderingCapable(screenInfo
.screens
[stuff
->screen
],
134 rep
.isCapable
= isCapable
;
139 if (client
->swapped
) {
140 swaps(&rep
.sequenceNumber
);
144 WriteToClient(client
,
145 sizeof(xAppleDRIQueryDirectRenderingCapableReply
),
151 ProcAppleDRIAuthConnection(register ClientPtr client
)
153 xAppleDRIAuthConnectionReply rep
;
155 REQUEST(xAppleDRIAuthConnectionReq
);
156 REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq
);
160 rep
.sequenceNumber
= client
->sequence
;
161 rep
.authenticated
= 1;
163 if (!DRIAuthConnection(screenInfo
.screens
[stuff
->screen
],
165 ErrorF("Failed to authenticate %u\n", (unsigned int)stuff
->magic
);
166 rep
.authenticated
= 0;
169 if (client
->swapped
) {
170 swaps(&rep
.sequenceNumber
);
172 swapl(&rep
.authenticated
); /* Yes, this is a CARD32 ... sigh */
175 WriteToClient(client
, sizeof(xAppleDRIAuthConnectionReply
), &rep
);
180 surface_notify(void *_arg
,
183 DRISurfaceNotifyArg
*arg
= _arg
;
184 int client_index
= (int)x_cvt_vptr_to_uint(data
);
185 xAppleDRINotifyEvent se
;
187 if (client_index
< 0 || client_index
>= currentMaxClients
)
190 se
.type
= DRIEventBase
+ AppleDRISurfaceNotify
;
193 se
.time
= currentTime
.milliseconds
;
194 WriteEventsToClient(clients
[client_index
], 1, (xEvent
*)&se
);
198 ProcAppleDRICreateSurface(ClientPtr client
)
200 xAppleDRICreateSurfaceReply rep
;
201 DrawablePtr pDrawable
;
206 REQUEST(xAppleDRICreateSurfaceReq
);
207 REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq
);
210 rep
.sequenceNumber
= client
->sequence
;
212 rc
= dixLookupDrawable(&pDrawable
, stuff
->drawable
, client
, 0,
217 rep
.key_0
= rep
.key_1
= rep
.uid
= 0;
219 if (!DRICreateSurface(screenInfo
.screens
[stuff
->screen
],
220 (Drawable
)stuff
->drawable
, pDrawable
,
221 stuff
->client_id
, &sid
, key
,
223 x_cvt_uint_to_vptr(client
->index
))) {
231 if (client
->swapped
) {
232 swaps(&rep
.sequenceNumber
);
239 WriteToClient(client
, sizeof(xAppleDRICreateSurfaceReply
), &rep
);
244 ProcAppleDRIDestroySurface(register ClientPtr client
)
247 REQUEST(xAppleDRIDestroySurfaceReq
);
248 DrawablePtr pDrawable
;
249 REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq
);
251 rc
= dixLookupDrawable(&pDrawable
, stuff
->drawable
, client
, 0,
256 if (!DRIDestroySurface(screenInfo
.screens
[stuff
->screen
],
257 (Drawable
)stuff
->drawable
,
258 pDrawable
, NULL
, NULL
)) {
266 ProcAppleDRICreatePixmap(ClientPtr client
)
268 REQUEST(xAppleDRICreatePixmapReq
);
269 DrawablePtr pDrawable
;
272 xAppleDRICreatePixmapReply rep
;
273 int width
, height
, pitch
, bpp
;
276 REQUEST_SIZE_MATCH(xAppleDRICreatePixmapReq
);
278 rc
= dixLookupDrawable(&pDrawable
, stuff
->drawable
, client
, 0,
284 if (!DRICreatePixmap(screenInfo
.screens
[stuff
->screen
],
285 (Drawable
)stuff
->drawable
,
291 if (!DRIGetPixmapData(pDrawable
, &width
, &height
,
292 &pitch
, &bpp
, &ptr
)) {
296 rep
.stringLength
= strlen(path
) + 1;
299 rep
.length
= bytes_to_int32(rep
.stringLength
);
300 rep
.sequenceNumber
= client
->sequence
;
305 rep
.size
= pitch
* height
;
307 if (sizeof(rep
) != sz_xAppleDRICreatePixmapReply
)
308 ErrorF("error sizeof(rep) is %zu\n", sizeof(rep
));
310 if (client
->swapped
) {
311 swaps(&rep
.sequenceNumber
);
313 swapl(&rep
.stringLength
);
321 WriteToClient(client
, sizeof(rep
), &rep
);
322 WriteToClient(client
, rep
.stringLength
, path
);
328 ProcAppleDRIDestroyPixmap(ClientPtr client
)
330 DrawablePtr pDrawable
;
332 REQUEST(xAppleDRIDestroyPixmapReq
);
333 REQUEST_SIZE_MATCH(xAppleDRIDestroyPixmapReq
);
335 rc
= dixLookupDrawable(&pDrawable
, stuff
->drawable
, client
, 0,
341 DRIDestroyPixmap(pDrawable
);
349 ProcAppleDRIDispatch(register ClientPtr client
)
353 switch (stuff
->data
) {
354 case X_AppleDRIQueryVersion
:
355 return ProcAppleDRIQueryVersion(client
);
357 case X_AppleDRIQueryDirectRenderingCapable
:
358 return ProcAppleDRIQueryDirectRenderingCapable(client
);
362 return DRIErrorBase
+ AppleDRIClientNotLocal
;
364 switch (stuff
->data
) {
365 case X_AppleDRIAuthConnection
:
366 return ProcAppleDRIAuthConnection(client
);
368 case X_AppleDRICreateSurface
:
369 return ProcAppleDRICreateSurface(client
);
371 case X_AppleDRIDestroySurface
:
372 return ProcAppleDRIDestroySurface(client
);
374 case X_AppleDRICreatePixmap
:
375 return ProcAppleDRICreatePixmap(client
);
377 case X_AppleDRIDestroyPixmap
:
378 return ProcAppleDRIDestroyPixmap(client
);
386 SNotifyEvent(xAppleDRINotifyEvent
*from
,
387 xAppleDRINotifyEvent
*to
)
389 to
->type
= from
->type
;
390 to
->kind
= from
->kind
;
391 cpswaps(from
->sequenceNumber
, to
->sequenceNumber
);
392 cpswapl(from
->time
, to
->time
);
393 cpswapl(from
->arg
, to
->arg
);
397 SProcAppleDRIQueryVersion(register ClientPtr client
)
399 REQUEST(xAppleDRIQueryVersionReq
);
400 swaps(&stuff
->length
);
401 return ProcAppleDRIQueryVersion(client
);
405 SProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client
)
407 REQUEST(xAppleDRIQueryDirectRenderingCapableReq
);
408 swaps(&stuff
->length
);
409 REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq
);
410 swapl(&stuff
->screen
);
411 return ProcAppleDRIQueryDirectRenderingCapable(client
);
415 SProcAppleDRIAuthConnection(register ClientPtr client
)
417 REQUEST(xAppleDRIAuthConnectionReq
);
418 swaps(&stuff
->length
);
419 REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq
);
420 swapl(&stuff
->screen
);
421 swapl(&stuff
->magic
);
422 return ProcAppleDRIAuthConnection(client
);
426 SProcAppleDRICreateSurface(register ClientPtr client
)
428 REQUEST(xAppleDRICreateSurfaceReq
);
429 swaps(&stuff
->length
);
430 REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq
);
431 swapl(&stuff
->screen
);
432 swapl(&stuff
->drawable
);
433 swapl(&stuff
->client_id
);
434 return ProcAppleDRICreateSurface(client
);
438 SProcAppleDRIDestroySurface(register ClientPtr client
)
440 REQUEST(xAppleDRIDestroySurfaceReq
);
441 swaps(&stuff
->length
);
442 REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq
);
443 swapl(&stuff
->screen
);
444 swapl(&stuff
->drawable
);
445 return ProcAppleDRIDestroySurface(client
);
449 SProcAppleDRICreatePixmap(register ClientPtr client
)
451 REQUEST(xAppleDRICreatePixmapReq
);
452 swaps(&stuff
->length
);
453 REQUEST_SIZE_MATCH(xAppleDRICreatePixmapReq
);
454 swapl(&stuff
->screen
);
455 swapl(&stuff
->drawable
);
456 return ProcAppleDRICreatePixmap(client
);
460 SProcAppleDRIDestroyPixmap(register ClientPtr client
)
462 REQUEST(xAppleDRIDestroyPixmapReq
);
463 swaps(&stuff
->length
);
464 REQUEST_SIZE_MATCH(xAppleDRIDestroyPixmapReq
);
465 swapl(&stuff
->drawable
);
466 return ProcAppleDRIDestroyPixmap(client
);
470 SProcAppleDRIDispatch(register ClientPtr client
)
474 switch (stuff
->data
) {
475 case X_AppleDRIQueryVersion
:
476 return SProcAppleDRIQueryVersion(client
);
478 case X_AppleDRIQueryDirectRenderingCapable
:
479 return SProcAppleDRIQueryDirectRenderingCapable(client
);
483 return DRIErrorBase
+ AppleDRIClientNotLocal
;
485 switch (stuff
->data
) {
486 case X_AppleDRIAuthConnection
:
487 return SProcAppleDRIAuthConnection(client
);
489 case X_AppleDRICreateSurface
:
490 return SProcAppleDRICreateSurface(client
);
492 case X_AppleDRIDestroySurface
:
493 return SProcAppleDRIDestroySurface(client
);
495 case X_AppleDRICreatePixmap
:
496 return SProcAppleDRICreatePixmap(client
);
498 case X_AppleDRIDestroyPixmap
:
499 return SProcAppleDRIDestroyPixmap(client
);
507 AppleDRIExtensionInit(void)
509 ExtensionEntry
* extEntry
;
511 if (DRIExtensionInit() &&
512 (extEntry
= AddExtension(APPLEDRINAME
,
513 AppleDRINumberEvents
,
514 AppleDRINumberErrors
,
515 ProcAppleDRIDispatch
,
516 SProcAppleDRIDispatch
,
518 StandardMinorOpcode
))) {
520 DRIReqCode
= (unsigned char)extEntry
->base
;
521 DRIErrorBase
= extEntry
->errorBase
;
522 DRIEventBase
= extEntry
->eventBase
;
523 for (i
= 0; i
< AppleDRINumberEvents
; i
++)
524 EventSwapVector
[DRIEventBase
+ i
] = (EventSwapPtr
)SNotifyEvent
;