xref: /OK3568_Linux_fs/external/xserver/hw/xquartz/xpr/appledri.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /**************************************************************************
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun    Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4*4882a593Smuzhiyun    Copyright 2000 VA Linux Systems, Inc.
5*4882a593Smuzhiyun    Copyright (c) 2002, 2009-2012 Apple Inc.
6*4882a593Smuzhiyun    All Rights Reserved.
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun    Permission is hereby granted, free of charge, to any person obtaining a
9*4882a593Smuzhiyun    copy of this software and associated documentation files (the
10*4882a593Smuzhiyun    "Software"), to deal in the Software without restriction, including
11*4882a593Smuzhiyun    without limitation the rights to use, copy, modify, merge, publish,
12*4882a593Smuzhiyun    distribute, sub license, and/or sell copies of the Software, and to
13*4882a593Smuzhiyun    permit persons to whom the Software is furnished to do so, subject to
14*4882a593Smuzhiyun    the following conditions:
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun    The above copyright notice and this permission notice (including the
17*4882a593Smuzhiyun    next paragraph) shall be included in all copies or substantial portions
18*4882a593Smuzhiyun    of the Software.
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21*4882a593Smuzhiyun    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22*4882a593Smuzhiyun    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23*4882a593Smuzhiyun    IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
24*4882a593Smuzhiyun    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25*4882a593Smuzhiyun    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26*4882a593Smuzhiyun    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun **************************************************************************/
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun  * Authors:
32*4882a593Smuzhiyun  *   Kevin E. Martin <martin@valinux.com>
33*4882a593Smuzhiyun  *   Jens Owen <jens@valinux.com>
34*4882a593Smuzhiyun  *   Rickard E. (Rik) Faith <faith@valinux.com>
35*4882a593Smuzhiyun  *   Jeremy Huddleston <jeremyhu@apple.com>
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
40*4882a593Smuzhiyun #include <dix-config.h>
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #include <X11/X.h>
44*4882a593Smuzhiyun #include <X11/Xproto.h>
45*4882a593Smuzhiyun #include "misc.h"
46*4882a593Smuzhiyun #include "dixstruct.h"
47*4882a593Smuzhiyun #include "extnsionst.h"
48*4882a593Smuzhiyun #include "colormapst.h"
49*4882a593Smuzhiyun #include "cursorstr.h"
50*4882a593Smuzhiyun #include "scrnintstr.h"
51*4882a593Smuzhiyun #include "servermd.h"
52*4882a593Smuzhiyun #define _APPLEDRI_SERVER_
53*4882a593Smuzhiyun #include "appledristr.h"
54*4882a593Smuzhiyun #include "swaprep.h"
55*4882a593Smuzhiyun #include "dri.h"
56*4882a593Smuzhiyun #include "dristruct.h"
57*4882a593Smuzhiyun #include "xpr.h"
58*4882a593Smuzhiyun #include "x-hash.h"
59*4882a593Smuzhiyun #include "protocol-versions.h"
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun static int DRIErrorBase = 0;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun static void
64*4882a593Smuzhiyun AppleDRIResetProc(ExtensionEntry* extEntry);
65*4882a593Smuzhiyun static int
66*4882a593Smuzhiyun ProcAppleDRICreatePixmap(ClientPtr client);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun static unsigned char DRIReqCode = 0;
69*4882a593Smuzhiyun static int DRIEventBase = 0;
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun static void
72*4882a593Smuzhiyun SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun typedef struct _DRIEvent *DRIEventPtr;
75*4882a593Smuzhiyun typedef struct _DRIEvent {
76*4882a593Smuzhiyun     DRIEventPtr next;
77*4882a593Smuzhiyun     ClientPtr client;
78*4882a593Smuzhiyun     XID clientResource;
79*4882a593Smuzhiyun     unsigned int mask;
80*4882a593Smuzhiyun } DRIEventRec;
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /*ARGSUSED*/
83*4882a593Smuzhiyun static void
AppleDRIResetProc(ExtensionEntry * extEntry)84*4882a593Smuzhiyun AppleDRIResetProc(ExtensionEntry* extEntry)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun     DRIReset();
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun static int
ProcAppleDRIQueryVersion(register ClientPtr client)90*4882a593Smuzhiyun ProcAppleDRIQueryVersion(register ClientPtr client)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun     xAppleDRIQueryVersionReply rep;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
95*4882a593Smuzhiyun     rep.type = X_Reply;
96*4882a593Smuzhiyun     rep.length = 0;
97*4882a593Smuzhiyun     rep.sequenceNumber = client->sequence;
98*4882a593Smuzhiyun     rep.majorVersion = SERVER_APPLEDRI_MAJOR_VERSION;
99*4882a593Smuzhiyun     rep.minorVersion = SERVER_APPLEDRI_MINOR_VERSION;
100*4882a593Smuzhiyun     rep.patchVersion = SERVER_APPLEDRI_PATCH_VERSION;
101*4882a593Smuzhiyun     if (client->swapped) {
102*4882a593Smuzhiyun         swaps(&rep.sequenceNumber);
103*4882a593Smuzhiyun         swapl(&rep.length);
104*4882a593Smuzhiyun         swaps(&rep.majorVersion);
105*4882a593Smuzhiyun         swaps(&rep.minorVersion);
106*4882a593Smuzhiyun         swapl(&rep.patchVersion);
107*4882a593Smuzhiyun     }
108*4882a593Smuzhiyun     WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), &rep);
109*4882a593Smuzhiyun     return Success;
110*4882a593Smuzhiyun }
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun /* surfaces */
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun static int
ProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client)115*4882a593Smuzhiyun ProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun     xAppleDRIQueryDirectRenderingCapableReply rep;
118*4882a593Smuzhiyun     Bool isCapable;
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun     REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
121*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
122*4882a593Smuzhiyun     rep.type = X_Reply;
123*4882a593Smuzhiyun     rep.length = 0;
124*4882a593Smuzhiyun     rep.sequenceNumber = client->sequence;
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun     if (stuff->screen >= screenInfo.numScreens) {
127*4882a593Smuzhiyun         return BadValue;
128*4882a593Smuzhiyun     }
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun     if (!DRIQueryDirectRenderingCapable(screenInfo.screens[stuff->screen],
131*4882a593Smuzhiyun                                         &isCapable)) {
132*4882a593Smuzhiyun         return BadValue;
133*4882a593Smuzhiyun     }
134*4882a593Smuzhiyun     rep.isCapable = isCapable;
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun     if (!client->local)
137*4882a593Smuzhiyun         rep.isCapable = 0;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun     if (client->swapped) {
140*4882a593Smuzhiyun         swaps(&rep.sequenceNumber);
141*4882a593Smuzhiyun         swapl(&rep.length);
142*4882a593Smuzhiyun     }
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun     WriteToClient(client,
145*4882a593Smuzhiyun                   sizeof(xAppleDRIQueryDirectRenderingCapableReply),
146*4882a593Smuzhiyun                   &rep);
147*4882a593Smuzhiyun     return Success;
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun static int
ProcAppleDRIAuthConnection(register ClientPtr client)151*4882a593Smuzhiyun ProcAppleDRIAuthConnection(register ClientPtr client)
152*4882a593Smuzhiyun {
153*4882a593Smuzhiyun     xAppleDRIAuthConnectionReply rep;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun     REQUEST(xAppleDRIAuthConnectionReq);
156*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun     rep.type = X_Reply;
159*4882a593Smuzhiyun     rep.length = 0;
160*4882a593Smuzhiyun     rep.sequenceNumber = client->sequence;
161*4882a593Smuzhiyun     rep.authenticated = 1;
162*4882a593Smuzhiyun 
163*4882a593Smuzhiyun     if (!DRIAuthConnection(screenInfo.screens[stuff->screen],
164*4882a593Smuzhiyun                            stuff->magic)) {
165*4882a593Smuzhiyun         ErrorF("Failed to authenticate %u\n", (unsigned int)stuff->magic);
166*4882a593Smuzhiyun         rep.authenticated = 0;
167*4882a593Smuzhiyun     }
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun     if (client->swapped) {
170*4882a593Smuzhiyun         swaps(&rep.sequenceNumber);
171*4882a593Smuzhiyun         swapl(&rep.length);
172*4882a593Smuzhiyun         swapl(&rep.authenticated); /* Yes, this is a CARD32 ... sigh */
173*4882a593Smuzhiyun     }
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun     WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), &rep);
176*4882a593Smuzhiyun     return Success;
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun static void
surface_notify(void * _arg,void * data)180*4882a593Smuzhiyun surface_notify(void *_arg,
181*4882a593Smuzhiyun                void *data)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun     DRISurfaceNotifyArg *arg = _arg;
184*4882a593Smuzhiyun     int client_index = (int)x_cvt_vptr_to_uint(data);
185*4882a593Smuzhiyun     xAppleDRINotifyEvent se;
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun     if (client_index < 0 || client_index >= currentMaxClients)
188*4882a593Smuzhiyun         return;
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun     se.type = DRIEventBase + AppleDRISurfaceNotify;
191*4882a593Smuzhiyun     se.kind = arg->kind;
192*4882a593Smuzhiyun     se.arg = arg->id;
193*4882a593Smuzhiyun     se.time = currentTime.milliseconds;
194*4882a593Smuzhiyun     WriteEventsToClient(clients[client_index], 1, (xEvent *)&se);
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun static int
ProcAppleDRICreateSurface(ClientPtr client)198*4882a593Smuzhiyun ProcAppleDRICreateSurface(ClientPtr client)
199*4882a593Smuzhiyun {
200*4882a593Smuzhiyun     xAppleDRICreateSurfaceReply rep;
201*4882a593Smuzhiyun     DrawablePtr pDrawable;
202*4882a593Smuzhiyun     xp_surface_id sid;
203*4882a593Smuzhiyun     unsigned int key[2];
204*4882a593Smuzhiyun     int rc;
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun     REQUEST(xAppleDRICreateSurfaceReq);
207*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
208*4882a593Smuzhiyun     rep.type = X_Reply;
209*4882a593Smuzhiyun     rep.length = 0;
210*4882a593Smuzhiyun     rep.sequenceNumber = client->sequence;
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
213*4882a593Smuzhiyun                            DixReadAccess);
214*4882a593Smuzhiyun     if (rc != Success)
215*4882a593Smuzhiyun         return rc;
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun     rep.key_0 = rep.key_1 = rep.uid = 0;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun     if (!DRICreateSurface(screenInfo.screens[stuff->screen],
220*4882a593Smuzhiyun                           (Drawable)stuff->drawable, pDrawable,
221*4882a593Smuzhiyun                           stuff->client_id, &sid, key,
222*4882a593Smuzhiyun                           surface_notify,
223*4882a593Smuzhiyun                           x_cvt_uint_to_vptr(client->index))) {
224*4882a593Smuzhiyun         return BadValue;
225*4882a593Smuzhiyun     }
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun     rep.key_0 = key[0];
228*4882a593Smuzhiyun     rep.key_1 = key[1];
229*4882a593Smuzhiyun     rep.uid = sid;
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun     if (client->swapped) {
232*4882a593Smuzhiyun         swaps(&rep.sequenceNumber);
233*4882a593Smuzhiyun         swapl(&rep.length);
234*4882a593Smuzhiyun         swapl(&rep.key_0);
235*4882a593Smuzhiyun         swapl(&rep.key_1);
236*4882a593Smuzhiyun         swapl(&rep.uid);
237*4882a593Smuzhiyun     }
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun     WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), &rep);
240*4882a593Smuzhiyun     return Success;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun static int
ProcAppleDRIDestroySurface(register ClientPtr client)244*4882a593Smuzhiyun ProcAppleDRIDestroySurface(register ClientPtr client)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun     int rc;
247*4882a593Smuzhiyun     REQUEST(xAppleDRIDestroySurfaceReq);
248*4882a593Smuzhiyun     DrawablePtr pDrawable;
249*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
252*4882a593Smuzhiyun                            DixReadAccess);
253*4882a593Smuzhiyun     if (rc != Success)
254*4882a593Smuzhiyun         return rc;
255*4882a593Smuzhiyun 
256*4882a593Smuzhiyun     if (!DRIDestroySurface(screenInfo.screens[stuff->screen],
257*4882a593Smuzhiyun                            (Drawable)stuff->drawable,
258*4882a593Smuzhiyun                            pDrawable, NULL, NULL)) {
259*4882a593Smuzhiyun         return BadValue;
260*4882a593Smuzhiyun     }
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun     return Success;
263*4882a593Smuzhiyun }
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun static int
ProcAppleDRICreatePixmap(ClientPtr client)266*4882a593Smuzhiyun ProcAppleDRICreatePixmap(ClientPtr client)
267*4882a593Smuzhiyun {
268*4882a593Smuzhiyun     REQUEST(xAppleDRICreatePixmapReq);
269*4882a593Smuzhiyun     DrawablePtr pDrawable;
270*4882a593Smuzhiyun     int rc;
271*4882a593Smuzhiyun     char path[PATH_MAX];
272*4882a593Smuzhiyun     xAppleDRICreatePixmapReply rep;
273*4882a593Smuzhiyun     int width, height, pitch, bpp;
274*4882a593Smuzhiyun     void *ptr;
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRICreatePixmapReq);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
279*4882a593Smuzhiyun                            DixReadAccess);
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun     if (rc != Success)
282*4882a593Smuzhiyun         return rc;
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun     if (!DRICreatePixmap(screenInfo.screens[stuff->screen],
285*4882a593Smuzhiyun                          (Drawable)stuff->drawable,
286*4882a593Smuzhiyun                          pDrawable,
287*4882a593Smuzhiyun                          path, PATH_MAX)) {
288*4882a593Smuzhiyun         return BadValue;
289*4882a593Smuzhiyun     }
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun     if (!DRIGetPixmapData(pDrawable, &width, &height,
292*4882a593Smuzhiyun                           &pitch, &bpp, &ptr)) {
293*4882a593Smuzhiyun         return BadValue;
294*4882a593Smuzhiyun     }
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun     rep.stringLength = strlen(path) + 1;
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun     rep.type = X_Reply;
299*4882a593Smuzhiyun     rep.length = bytes_to_int32(rep.stringLength);
300*4882a593Smuzhiyun     rep.sequenceNumber = client->sequence;
301*4882a593Smuzhiyun     rep.width = width;
302*4882a593Smuzhiyun     rep.height = height;
303*4882a593Smuzhiyun     rep.pitch = pitch;
304*4882a593Smuzhiyun     rep.bpp = bpp;
305*4882a593Smuzhiyun     rep.size = pitch * height;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun     if (sizeof(rep) != sz_xAppleDRICreatePixmapReply)
308*4882a593Smuzhiyun         ErrorF("error sizeof(rep) is %zu\n", sizeof(rep));
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun     if (client->swapped) {
311*4882a593Smuzhiyun         swaps(&rep.sequenceNumber);
312*4882a593Smuzhiyun         swapl(&rep.length);
313*4882a593Smuzhiyun         swapl(&rep.stringLength);
314*4882a593Smuzhiyun         swapl(&rep.width);
315*4882a593Smuzhiyun         swapl(&rep.height);
316*4882a593Smuzhiyun         swapl(&rep.pitch);
317*4882a593Smuzhiyun         swapl(&rep.bpp);
318*4882a593Smuzhiyun         swapl(&rep.size);
319*4882a593Smuzhiyun     }
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun     WriteToClient(client, sizeof(rep), &rep);
322*4882a593Smuzhiyun     WriteToClient(client, rep.stringLength, path);
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun     return Success;
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun static int
ProcAppleDRIDestroyPixmap(ClientPtr client)328*4882a593Smuzhiyun ProcAppleDRIDestroyPixmap(ClientPtr client)
329*4882a593Smuzhiyun {
330*4882a593Smuzhiyun     DrawablePtr pDrawable;
331*4882a593Smuzhiyun     int rc;
332*4882a593Smuzhiyun     REQUEST(xAppleDRIDestroyPixmapReq);
333*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIDestroyPixmapReq);
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun     rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
336*4882a593Smuzhiyun                            DixReadAccess);
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun     if (rc != Success)
339*4882a593Smuzhiyun         return rc;
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun     DRIDestroyPixmap(pDrawable);
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun     return Success;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun /* dispatch */
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun static int
ProcAppleDRIDispatch(register ClientPtr client)349*4882a593Smuzhiyun ProcAppleDRIDispatch(register ClientPtr client)
350*4882a593Smuzhiyun {
351*4882a593Smuzhiyun     REQUEST(xReq);
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun     switch (stuff->data) {
354*4882a593Smuzhiyun     case X_AppleDRIQueryVersion:
355*4882a593Smuzhiyun         return ProcAppleDRIQueryVersion(client);
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun     case X_AppleDRIQueryDirectRenderingCapable:
358*4882a593Smuzhiyun         return ProcAppleDRIQueryDirectRenderingCapable(client);
359*4882a593Smuzhiyun     }
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun     if (!client->local)
362*4882a593Smuzhiyun         return DRIErrorBase + AppleDRIClientNotLocal;
363*4882a593Smuzhiyun 
364*4882a593Smuzhiyun     switch (stuff->data) {
365*4882a593Smuzhiyun     case X_AppleDRIAuthConnection:
366*4882a593Smuzhiyun         return ProcAppleDRIAuthConnection(client);
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun     case X_AppleDRICreateSurface:
369*4882a593Smuzhiyun         return ProcAppleDRICreateSurface(client);
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun     case X_AppleDRIDestroySurface:
372*4882a593Smuzhiyun         return ProcAppleDRIDestroySurface(client);
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun     case X_AppleDRICreatePixmap:
375*4882a593Smuzhiyun         return ProcAppleDRICreatePixmap(client);
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun     case X_AppleDRIDestroyPixmap:
378*4882a593Smuzhiyun         return ProcAppleDRIDestroyPixmap(client);
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun     default:
381*4882a593Smuzhiyun         return BadRequest;
382*4882a593Smuzhiyun     }
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun static void
SNotifyEvent(xAppleDRINotifyEvent * from,xAppleDRINotifyEvent * to)386*4882a593Smuzhiyun SNotifyEvent(xAppleDRINotifyEvent *from,
387*4882a593Smuzhiyun              xAppleDRINotifyEvent *to)
388*4882a593Smuzhiyun {
389*4882a593Smuzhiyun     to->type = from->type;
390*4882a593Smuzhiyun     to->kind = from->kind;
391*4882a593Smuzhiyun     cpswaps(from->sequenceNumber, to->sequenceNumber);
392*4882a593Smuzhiyun     cpswapl(from->time, to->time);
393*4882a593Smuzhiyun     cpswapl(from->arg, to->arg);
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun 
396*4882a593Smuzhiyun static int
SProcAppleDRIQueryVersion(register ClientPtr client)397*4882a593Smuzhiyun SProcAppleDRIQueryVersion(register ClientPtr client)
398*4882a593Smuzhiyun {
399*4882a593Smuzhiyun     REQUEST(xAppleDRIQueryVersionReq);
400*4882a593Smuzhiyun     swaps(&stuff->length);
401*4882a593Smuzhiyun     return ProcAppleDRIQueryVersion(client);
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun static int
SProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client)405*4882a593Smuzhiyun SProcAppleDRIQueryDirectRenderingCapable(register ClientPtr client)
406*4882a593Smuzhiyun {
407*4882a593Smuzhiyun     REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
408*4882a593Smuzhiyun     swaps(&stuff->length);
409*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
410*4882a593Smuzhiyun     swapl(&stuff->screen);
411*4882a593Smuzhiyun     return ProcAppleDRIQueryDirectRenderingCapable(client);
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun static int
SProcAppleDRIAuthConnection(register ClientPtr client)415*4882a593Smuzhiyun SProcAppleDRIAuthConnection(register ClientPtr client)
416*4882a593Smuzhiyun {
417*4882a593Smuzhiyun     REQUEST(xAppleDRIAuthConnectionReq);
418*4882a593Smuzhiyun     swaps(&stuff->length);
419*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
420*4882a593Smuzhiyun     swapl(&stuff->screen);
421*4882a593Smuzhiyun     swapl(&stuff->magic);
422*4882a593Smuzhiyun     return ProcAppleDRIAuthConnection(client);
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun static int
SProcAppleDRICreateSurface(register ClientPtr client)426*4882a593Smuzhiyun SProcAppleDRICreateSurface(register ClientPtr client)
427*4882a593Smuzhiyun {
428*4882a593Smuzhiyun     REQUEST(xAppleDRICreateSurfaceReq);
429*4882a593Smuzhiyun     swaps(&stuff->length);
430*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
431*4882a593Smuzhiyun     swapl(&stuff->screen);
432*4882a593Smuzhiyun     swapl(&stuff->drawable);
433*4882a593Smuzhiyun     swapl(&stuff->client_id);
434*4882a593Smuzhiyun     return ProcAppleDRICreateSurface(client);
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun static int
SProcAppleDRIDestroySurface(register ClientPtr client)438*4882a593Smuzhiyun SProcAppleDRIDestroySurface(register ClientPtr client)
439*4882a593Smuzhiyun {
440*4882a593Smuzhiyun     REQUEST(xAppleDRIDestroySurfaceReq);
441*4882a593Smuzhiyun     swaps(&stuff->length);
442*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
443*4882a593Smuzhiyun     swapl(&stuff->screen);
444*4882a593Smuzhiyun     swapl(&stuff->drawable);
445*4882a593Smuzhiyun     return ProcAppleDRIDestroySurface(client);
446*4882a593Smuzhiyun }
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun static int
SProcAppleDRICreatePixmap(register ClientPtr client)449*4882a593Smuzhiyun SProcAppleDRICreatePixmap(register ClientPtr client)
450*4882a593Smuzhiyun {
451*4882a593Smuzhiyun     REQUEST(xAppleDRICreatePixmapReq);
452*4882a593Smuzhiyun     swaps(&stuff->length);
453*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRICreatePixmapReq);
454*4882a593Smuzhiyun     swapl(&stuff->screen);
455*4882a593Smuzhiyun     swapl(&stuff->drawable);
456*4882a593Smuzhiyun     return ProcAppleDRICreatePixmap(client);
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun static int
SProcAppleDRIDestroyPixmap(register ClientPtr client)460*4882a593Smuzhiyun SProcAppleDRIDestroyPixmap(register ClientPtr client)
461*4882a593Smuzhiyun {
462*4882a593Smuzhiyun     REQUEST(xAppleDRIDestroyPixmapReq);
463*4882a593Smuzhiyun     swaps(&stuff->length);
464*4882a593Smuzhiyun     REQUEST_SIZE_MATCH(xAppleDRIDestroyPixmapReq);
465*4882a593Smuzhiyun     swapl(&stuff->drawable);
466*4882a593Smuzhiyun     return ProcAppleDRIDestroyPixmap(client);
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun static int
SProcAppleDRIDispatch(register ClientPtr client)470*4882a593Smuzhiyun SProcAppleDRIDispatch(register ClientPtr client)
471*4882a593Smuzhiyun {
472*4882a593Smuzhiyun     REQUEST(xReq);
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun     switch (stuff->data) {
475*4882a593Smuzhiyun     case X_AppleDRIQueryVersion:
476*4882a593Smuzhiyun         return SProcAppleDRIQueryVersion(client);
477*4882a593Smuzhiyun 
478*4882a593Smuzhiyun     case X_AppleDRIQueryDirectRenderingCapable:
479*4882a593Smuzhiyun         return SProcAppleDRIQueryDirectRenderingCapable(client);
480*4882a593Smuzhiyun     }
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun     if (!client->local)
483*4882a593Smuzhiyun         return DRIErrorBase + AppleDRIClientNotLocal;
484*4882a593Smuzhiyun 
485*4882a593Smuzhiyun     switch (stuff->data) {
486*4882a593Smuzhiyun     case X_AppleDRIAuthConnection:
487*4882a593Smuzhiyun         return SProcAppleDRIAuthConnection(client);
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun     case X_AppleDRICreateSurface:
490*4882a593Smuzhiyun         return SProcAppleDRICreateSurface(client);
491*4882a593Smuzhiyun 
492*4882a593Smuzhiyun     case X_AppleDRIDestroySurface:
493*4882a593Smuzhiyun         return SProcAppleDRIDestroySurface(client);
494*4882a593Smuzhiyun 
495*4882a593Smuzhiyun     case X_AppleDRICreatePixmap:
496*4882a593Smuzhiyun         return SProcAppleDRICreatePixmap(client);
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun     case X_AppleDRIDestroyPixmap:
499*4882a593Smuzhiyun         return SProcAppleDRIDestroyPixmap(client);
500*4882a593Smuzhiyun 
501*4882a593Smuzhiyun     default:
502*4882a593Smuzhiyun         return BadRequest;
503*4882a593Smuzhiyun     }
504*4882a593Smuzhiyun }
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun void
AppleDRIExtensionInit(void)507*4882a593Smuzhiyun AppleDRIExtensionInit(void)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun     ExtensionEntry* extEntry;
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun     if (DRIExtensionInit() &&
512*4882a593Smuzhiyun         (extEntry = AddExtension(APPLEDRINAME,
513*4882a593Smuzhiyun                                  AppleDRINumberEvents,
514*4882a593Smuzhiyun                                  AppleDRINumberErrors,
515*4882a593Smuzhiyun                                  ProcAppleDRIDispatch,
516*4882a593Smuzhiyun                                  SProcAppleDRIDispatch,
517*4882a593Smuzhiyun                                  AppleDRIResetProc,
518*4882a593Smuzhiyun                                  StandardMinorOpcode))) {
519*4882a593Smuzhiyun         size_t i;
520*4882a593Smuzhiyun         DRIReqCode = (unsigned char)extEntry->base;
521*4882a593Smuzhiyun         DRIErrorBase = extEntry->errorBase;
522*4882a593Smuzhiyun         DRIEventBase = extEntry->eventBase;
523*4882a593Smuzhiyun         for (i = 0; i < AppleDRINumberEvents; i++)
524*4882a593Smuzhiyun             EventSwapVector[DRIEventBase + i] = (EventSwapPtr)SNotifyEvent;
525*4882a593Smuzhiyun     }
526*4882a593Smuzhiyun }
527