First import
[xorg_rtime.git] / xorg-server-1.4 / hw / darwin / quartz / xpr / appledri.c
blobef68c867b306fc1e46355c9192103e6c16d68eea
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.
6 All Rights Reserved.
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
18 of the Software.
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 **************************************************************************/
31 * Authors:
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>
40 #endif
41 #define NEED_REPLIES
42 #define NEED_EVENTS
43 #include <X11/X.h>
44 #include <X11/Xproto.h>
45 #include "misc.h"
46 #include "dixstruct.h"
47 #include "extnsionst.h"
48 #include "colormapst.h"
49 #include "cursorstr.h"
50 #include "scrnintstr.h"
51 #include "servermd.h"
52 #define _APPLEDRI_SERVER_
53 #include "appledristr.h"
54 #include "swaprep.h"
55 #include "dri.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 {
72 DRIEventPtr next;
73 ClientPtr client;
74 XID clientResource;
75 unsigned int mask;
76 } DRIEventRec;
79 void
80 AppleDRIExtensionInit(void)
82 ExtensionEntry* extEntry;
84 if (DRIExtensionInit() &&
85 (extEntry = AddExtension(APPLEDRINAME,
86 AppleDRINumberEvents,
87 AppleDRINumberErrors,
88 ProcAppleDRIDispatch,
89 SProcAppleDRIDispatch,
90 AppleDRIResetProc,
91 StandardMinorOpcode))) {
92 DRIReqCode = (unsigned char)extEntry->base;
93 DRIErrorBase = extEntry->errorBase;
94 DRIEventBase = extEntry->eventBase;
95 EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
99 /*ARGSUSED*/
100 static void
101 AppleDRIResetProc (
102 ExtensionEntry* extEntry
105 DRIReset();
108 static int
109 ProcAppleDRIQueryVersion(
110 register ClientPtr client
113 xAppleDRIQueryVersionReply rep;
114 register int n;
116 REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
117 rep.type = X_Reply;
118 rep.length = 0;
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);
132 /* surfaces */
134 static int
135 ProcAppleDRIQueryDirectRenderingCapable(
136 register ClientPtr client
139 xAppleDRIQueryDirectRenderingCapableReply rep;
140 Bool isCapable;
142 REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
143 REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
144 rep.type = X_Reply;
145 rep.length = 0;
146 rep.sequenceNumber = client->sequence;
148 if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen],
149 &isCapable)) {
150 return BadValue;
152 rep.isCapable = isCapable;
154 if (!LocalClient(client))
155 rep.isCapable = 0;
157 WriteToClient(client,
158 sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
159 return (client->noClientException);
162 static int
163 ProcAppleDRIAuthConnection(
164 register ClientPtr client
167 xAppleDRIAuthConnectionReply rep;
169 REQUEST(xAppleDRIAuthConnectionReq);
170 REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
172 rep.type = X_Reply;
173 rep.length = 0;
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(
186 void *_arg,
187 void *data
190 DRISurfaceNotifyArg *arg = _arg;
191 int client_index = (int) data;
192 ClientPtr client;
193 xAppleDRINotifyEvent se;
195 if (client_index < 0 || client_index >= currentMaxClients)
196 return;
198 client = clients[client_index];
199 if (client == NULL || client == serverClient || client->clientGone)
200 return;
202 se.type = DRIEventBase + AppleDRISurfaceNotify;
203 se.kind = arg->kind;
204 se.arg = arg->id;
205 se.sequenceNumber = client->sequence;
206 se.time = currentTime.milliseconds;
207 WriteEventsToClient (client, 1, (xEvent *) &se);
210 static int
211 ProcAppleDRICreateSurface(
212 ClientPtr client
215 xAppleDRICreateSurfaceReply rep;
216 DrawablePtr pDrawable;
217 xp_surface_id sid;
218 unsigned int key[2];
219 int rc;
221 REQUEST(xAppleDRICreateSurfaceReq);
222 REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
223 rep.type = X_Reply;
224 rep.length = 0;
225 rep.sequenceNumber = client->sequence;
227 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
228 DixReadAccess);
229 if (rc != Success)
230 return rc;
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)) {
238 return BadValue;
241 rep.key_0 = key[0];
242 rep.key_1 = key[1];
243 rep.uid = sid;
245 WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
246 return (client->noClientException);
249 static int
250 ProcAppleDRIDestroySurface(
251 register ClientPtr client
254 REQUEST(xAppleDRIDestroySurfaceReq);
255 DrawablePtr pDrawable;
256 REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
257 int rc;
259 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
260 DixReadAccess);
261 if (rc != Success)
262 return rc;
264 if (!DRIDestroySurface( screenInfo.screens[stuff->screen],
265 (Drawable)stuff->drawable,
266 pDrawable, NULL, NULL)) {
267 return BadValue;
270 return (client->noClientException);
274 /* dispatch */
276 static int
277 ProcAppleDRIDispatch (
278 register ClientPtr client
281 REQUEST(xReq);
283 switch (stuff->data)
285 case X_AppleDRIQueryVersion:
286 return ProcAppleDRIQueryVersion(client);
287 case X_AppleDRIQueryDirectRenderingCapable:
288 return ProcAppleDRIQueryDirectRenderingCapable(client);
291 if (!LocalClient(client))
292 return DRIErrorBase + AppleDRIClientNotLocal;
294 switch (stuff->data)
296 case X_AppleDRIAuthConnection:
297 return ProcAppleDRIAuthConnection(client);
298 case X_AppleDRICreateSurface:
299 return ProcAppleDRICreateSurface(client);
300 case X_AppleDRIDestroySurface:
301 return ProcAppleDRIDestroySurface(client);
302 default:
303 return BadRequest;
307 static void
308 SNotifyEvent(
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);
320 static int
321 SProcAppleDRIQueryVersion(
322 register ClientPtr client
325 register int n;
326 REQUEST(xAppleDRIQueryVersionReq);
327 swaps(&stuff->length, n);
328 return ProcAppleDRIQueryVersion(client);
331 static int
332 SProcAppleDRIDispatch (
333 register ClientPtr client
336 REQUEST(xReq);
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 */
343 switch (stuff->data)
345 case X_AppleDRIQueryVersion:
346 return SProcAppleDRIQueryVersion(client);
347 default:
348 return BadRequest;