1 /* $XFree86: xc/programs/Xserver/GL/dri/xf86dri.c,v 1.10 2000/12/07 20:26:14 dawes Exp $ */
2 /**************************************************************************
4 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
5 Copyright 2000 VA Linux Systems, Inc.
6 Copyright (c) 2002 Apple Computer, Inc.
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Kevin E. Martin <martin@valinux.com>
34 * Jens Owen <jens@valinux.com>
35 * Rickard E. (Rik) Faith <faith@valinux.com>
44 #include "dixstruct.h"
45 #include "extnsionst.h"
46 #include "colormapst.h"
47 #include "cursorstr.h"
48 #include "scrnintstr.h"
50 #define _APPLEDRI_SERVER_
51 #include "appledristr.h"
54 #include "dri-surface.h"
55 #include "dristruct.h"
56 #include "rootless-common.h"
57 #include "X11Application.h"
59 static int DRIErrorBase;
61 static DISPATCH_PROC(ProcAppleDRIDispatch);
62 static DISPATCH_PROC(SProcAppleDRIDispatch);
64 static void AppleDRIResetProc(ExtensionEntry* extEntry);
66 static unsigned char DRIReqCode = 0;
67 static int DRIEventBase = 0;
69 extern void AppleDRIExtensionInit(void);
71 static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
73 typedef struct _DRIEvent *DRIEventPtr;
74 typedef struct _DRIEvent {
82 AppleDRIExtensionInit(void)
84 ExtensionEntry* extEntry;
86 if (DRIExtensionInit() &&
87 (extEntry = AddExtension(APPLEDRINAME,
91 SProcAppleDRIDispatch,
93 StandardMinorOpcode))) {
94 DRIReqCode = (unsigned char)extEntry->base;
95 DRIErrorBase = extEntry->errorBase;
96 DRIEventBase = extEntry->eventBase;
97 EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
104 ExtensionEntry* extEntry
111 ProcAppleDRIQueryVersion(
112 register ClientPtr client
115 xAppleDRIQueryVersionReply rep;
118 REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
121 rep.sequenceNumber = client->sequence;
122 rep.majorVersion = APPLE_DRI_MAJOR_VERSION;
123 rep.minorVersion = APPLE_DRI_MINOR_VERSION;
124 rep.patchVersion = APPLE_DRI_PATCH_VERSION;
125 if (client->swapped) {
126 swaps(&rep.sequenceNumber, n);
127 swapl(&rep.length, n);
129 WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
130 return (client->noClientException);
137 ProcAppleDRIQueryDirectRenderingCapable(
138 register ClientPtr client
141 xAppleDRIQueryDirectRenderingCapableReply rep;
144 REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
145 REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
148 rep.sequenceNumber = client->sequence;
150 if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen],
154 rep.isCapable = isCapable;
156 if (!LocalClient(client))
159 WriteToClient(client,
160 sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
161 return (client->noClientException);
165 ProcAppleDRIAuthConnection(
166 register ClientPtr client
169 xAppleDRIAuthConnectionReply rep;
171 REQUEST(xAppleDRIAuthConnectionReq);
172 REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
176 rep.sequenceNumber = client->sequence;
177 rep.authenticated = 1;
179 if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
180 ErrorF("Failed to authenticate %u\n", stuff->magic);
181 rep.authenticated = 0;
183 WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
184 return (client->noClientException);
187 static void surface_notify (void *_arg, void *data)
189 DRISurfaceNotifyArg *arg = _arg;
190 int client_index = (int) data;
192 xAppleDRINotifyEvent se;
194 if (client_index < 0 || client_index >= currentMaxClients)
197 client = clients[client_index];
198 if (client == NULL || client == serverClient || client->clientGone)
201 se.type = DRIEventBase + AppleDRISurfaceNotify;
204 se.sequenceNumber = client->sequence;
205 se.time = currentTime.milliseconds;
206 WriteEventsToClient (client, 1, (xEvent *) &se);
210 ProcAppleDRICreateSurface(
214 xAppleDRICreateSurfaceReply rep;
215 DrawablePtr pDrawable;
219 REQUEST(xAppleDRICreateSurfaceReq);
220 REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
223 rep.sequenceNumber = client->sequence;
225 if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
226 (Drawable)stuff->drawable,
228 SecurityReadAccess))) {
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);
258 if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
259 (Drawable)stuff->drawable,
261 SecurityReadAccess))) {
265 if (!DRIDestroySurface( screenInfo.screens[stuff->screen],
266 (Drawable)stuff->drawable,
267 pDrawable, NULL, NULL)) {
271 return (client->noClientException);
278 ProcAppleDRIDispatch (
279 register ClientPtr client
286 case X_AppleDRIQueryVersion:
287 return ProcAppleDRIQueryVersion(client);
288 case X_AppleDRIQueryDirectRenderingCapable:
289 return ProcAppleDRIQueryDirectRenderingCapable(client);
292 if (!LocalClient(client))
293 return DRIErrorBase + AppleDRIClientNotLocal;
297 case X_AppleDRIAuthConnection:
298 return ProcAppleDRIAuthConnection(client);
299 case X_AppleDRICreateSurface:
300 return ProcAppleDRICreateSurface(client);
301 case X_AppleDRIDestroySurface:
302 return ProcAppleDRIDestroySurface(client);
309 SNotifyEvent(from, to)
310 xAppleDRINotifyEvent *from, *to;
312 to->type = from->type;
313 to->kind = from->kind;
314 cpswaps (from->sequenceNumber, to->sequenceNumber);
315 cpswapl (from->time, to->time);
316 cpswapl (from->arg, to->arg);
320 SProcAppleDRIQueryVersion(
321 register ClientPtr client
325 REQUEST(xAppleDRIQueryVersionReq);
326 swaps(&stuff->length, n);
327 return ProcAppleDRIQueryVersion(client);
331 SProcAppleDRIDispatch (
332 register ClientPtr client
337 /* It is bound to be non-local when there is byte swapping */
338 if (!LocalClient(client))
339 return DRIErrorBase + AppleDRIClientNotLocal;
341 /* only local clients are allowed DRI access */
344 case X_AppleDRIQueryVersion:
345 return SProcAppleDRIQueryVersion(client);