1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4 Copyright 2000 VA Linux Systems, Inc.
5 Copyright (c) 2002 Apple Computer, 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>
38 #ifdef HAVE_XORG_CONFIG_H
39 #include <xorg-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"
58 static int DRIErrorBase
= 0;
60 static DISPATCH_PROC(ProcAppleDRIDispatch
);
61 static DISPATCH_PROC(SProcAppleDRIDispatch
);
63 static void AppleDRIResetProc(ExtensionEntry
* extEntry
);
65 static unsigned char DRIReqCode
= 0;
66 static int DRIEventBase
= 0;
68 static void SNotifyEvent(xAppleDRINotifyEvent
*from
, xAppleDRINotifyEvent
*to
);
70 typedef struct _DRIEvent
*DRIEventPtr
;
71 typedef struct _DRIEvent
{
80 AppleDRIExtensionInit(void)
82 ExtensionEntry
* extEntry
;
84 if (DRIExtensionInit() &&
85 (extEntry
= AddExtension(APPLEDRINAME
,
89 SProcAppleDRIDispatch
,
91 StandardMinorOpcode
))) {
92 DRIReqCode
= (unsigned char)extEntry
->base
;
93 DRIErrorBase
= extEntry
->errorBase
;
94 DRIEventBase
= extEntry
->eventBase
;
95 EventSwapVector
[DRIEventBase
] = (EventSwapPtr
) SNotifyEvent
;
102 ExtensionEntry
* extEntry
109 ProcAppleDRIQueryVersion(
110 register ClientPtr client
113 xAppleDRIQueryVersionReply rep
;
116 REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq
);
119 rep
.sequenceNumber
= client
->sequence
;
120 rep
.majorVersion
= APPLE_DRI_MAJOR_VERSION
;
121 rep
.minorVersion
= APPLE_DRI_MINOR_VERSION
;
122 rep
.patchVersion
= APPLE_DRI_PATCH_VERSION
;
123 if (client
->swapped
) {
124 swaps(&rep
.sequenceNumber
, n
);
125 swapl(&rep
.length
, n
);
127 WriteToClient(client
, sizeof(xAppleDRIQueryVersionReply
), (char *)&rep
);
128 return (client
->noClientException
);
135 ProcAppleDRIQueryDirectRenderingCapable(
136 register ClientPtr client
139 xAppleDRIQueryDirectRenderingCapableReply rep
;
142 REQUEST(xAppleDRIQueryDirectRenderingCapableReq
);
143 REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq
);
146 rep
.sequenceNumber
= client
->sequence
;
148 if (!DRIQueryDirectRenderingCapable( screenInfo
.screens
[stuff
->screen
],
152 rep
.isCapable
= isCapable
;
154 if (!LocalClient(client
))
157 WriteToClient(client
,
158 sizeof(xAppleDRIQueryDirectRenderingCapableReply
), (char *)&rep
);
159 return (client
->noClientException
);
163 ProcAppleDRIAuthConnection(
164 register ClientPtr client
167 xAppleDRIAuthConnectionReply rep
;
169 REQUEST(xAppleDRIAuthConnectionReq
);
170 REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq
);
174 rep
.sequenceNumber
= client
->sequence
;
175 rep
.authenticated
= 1;
177 if (!DRIAuthConnection( screenInfo
.screens
[stuff
->screen
], stuff
->magic
)) {
178 ErrorF("Failed to authenticate %u\n", stuff
->magic
);
179 rep
.authenticated
= 0;
181 WriteToClient(client
, sizeof(xAppleDRIAuthConnectionReply
), (char *)&rep
);
182 return (client
->noClientException
);
185 static void surface_notify(
190 DRISurfaceNotifyArg
*arg
= _arg
;
191 int client_index
= (int) data
;
193 xAppleDRINotifyEvent se
;
195 if (client_index
< 0 || client_index
>= currentMaxClients
)
198 client
= clients
[client_index
];
199 if (client
== NULL
|| client
== serverClient
|| client
->clientGone
)
202 se
.type
= DRIEventBase
+ AppleDRISurfaceNotify
;
205 se
.sequenceNumber
= client
->sequence
;
206 se
.time
= currentTime
.milliseconds
;
207 WriteEventsToClient (client
, 1, (xEvent
*) &se
);
211 ProcAppleDRICreateSurface(
215 xAppleDRICreateSurfaceReply rep
;
216 DrawablePtr pDrawable
;
221 REQUEST(xAppleDRICreateSurfaceReq
);
222 REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq
);
225 rep
.sequenceNumber
= client
->sequence
;
227 rc
= dixLookupDrawable(&pDrawable
, stuff
->drawable
, client
, 0,
232 rep
.key_0
= rep
.key_1
= rep
.uid
= 0;
234 if (!DRICreateSurface( screenInfo
.screens
[stuff
->screen
],
235 (Drawable
)stuff
->drawable
, pDrawable
,
236 stuff
->client_id
, &sid
, key
,
237 surface_notify
, (void *) client
->index
)) {
245 WriteToClient(client
, sizeof(xAppleDRICreateSurfaceReply
), (char *)&rep
);
246 return (client
->noClientException
);
250 ProcAppleDRIDestroySurface(
251 register ClientPtr client
254 REQUEST(xAppleDRIDestroySurfaceReq
);
255 DrawablePtr pDrawable
;
256 REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq
);
259 rc
= dixLookupDrawable(&pDrawable
, stuff
->drawable
, client
, 0,
264 if (!DRIDestroySurface( screenInfo
.screens
[stuff
->screen
],
265 (Drawable
)stuff
->drawable
,
266 pDrawable
, NULL
, NULL
)) {
270 return (client
->noClientException
);
277 ProcAppleDRIDispatch (
278 register ClientPtr client
285 case X_AppleDRIQueryVersion
:
286 return ProcAppleDRIQueryVersion(client
);
287 case X_AppleDRIQueryDirectRenderingCapable
:
288 return ProcAppleDRIQueryDirectRenderingCapable(client
);
291 if (!LocalClient(client
))
292 return DRIErrorBase
+ AppleDRIClientNotLocal
;
296 case X_AppleDRIAuthConnection
:
297 return ProcAppleDRIAuthConnection(client
);
298 case X_AppleDRICreateSurface
:
299 return ProcAppleDRICreateSurface(client
);
300 case X_AppleDRIDestroySurface
:
301 return ProcAppleDRIDestroySurface(client
);
309 xAppleDRINotifyEvent
*from
,
310 xAppleDRINotifyEvent
*to
313 to
->type
= from
->type
;
314 to
->kind
= from
->kind
;
315 cpswaps (from
->sequenceNumber
, to
->sequenceNumber
);
316 cpswapl (from
->time
, to
->time
);
317 cpswapl (from
->arg
, to
->arg
);
321 SProcAppleDRIQueryVersion(
322 register ClientPtr client
326 REQUEST(xAppleDRIQueryVersionReq
);
327 swaps(&stuff
->length
, n
);
328 return ProcAppleDRIQueryVersion(client
);
332 SProcAppleDRIDispatch (
333 register ClientPtr client
338 /* It is bound to be non-local when there is byte swapping */
339 if (!LocalClient(client
))
340 return DRIErrorBase
+ AppleDRIClientNotLocal
;
342 /* only local clients are allowed DRI access */
345 case X_AppleDRIQueryVersion
:
346 return SProcAppleDRIQueryVersion(client
);