1 /**************************************************************************
3 Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
4 Copyright 2000 VA Linux Systems, Inc.
5 Copyright (c) 2002, 2009 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_DIX_CONFIG_H
39 #include <dix-config.h>
43 #include <X11/Xproto.h>
45 #include "dixstruct.h"
46 #include "extnsionst.h"
47 #include "colormapst.h"
48 #include "cursorstr.h"
49 #include "scrnintstr.h"
51 #define _APPLEDRI_SERVER_
52 #include "appledristr.h"
55 #include "dristruct.h"
58 #include "protocol-versions.h"
60 static int DRIErrorBase = 0;
62 static DISPATCH_PROC(ProcAppleDRIDispatch);
63 static DISPATCH_PROC(SProcAppleDRIDispatch);
65 static void AppleDRIResetProc(ExtensionEntry* extEntry);
66 static int ProcAppleDRICreatePixmap(ClientPtr client);
68 static unsigned char DRIReqCode = 0;
69 static int DRIEventBase = 0;
71 static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
73 typedef struct _DRIEvent *DRIEventPtr;
74 typedef struct _DRIEvent {
83 AppleDRIExtensionInit(void)
85 ExtensionEntry* extEntry;
87 if (DRIExtensionInit() &&
88 (extEntry = AddExtension(APPLEDRINAME,
92 SProcAppleDRIDispatch,
94 StandardMinorOpcode))) {
95 DRIReqCode = (unsigned char)extEntry->base;
96 DRIErrorBase = extEntry->errorBase;
97 DRIEventBase = extEntry->eventBase;
98 EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
105 ExtensionEntry* extEntry
112 ProcAppleDRIQueryVersion(
113 register ClientPtr client
116 xAppleDRIQueryVersionReply rep;
119 REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
122 rep.sequenceNumber = client->sequence;
123 rep.majorVersion = SERVER_APPLEDRI_MAJOR_VERSION;
124 rep.minorVersion = SERVER_APPLEDRI_MINOR_VERSION;
125 rep.patchVersion = SERVER_APPLEDRI_PATCH_VERSION;
126 if (client->swapped) {
127 swaps(&rep.sequenceNumber, n);
128 swapl(&rep.length, n);
130 WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
138 ProcAppleDRIQueryDirectRenderingCapable(
139 register ClientPtr client
142 xAppleDRIQueryDirectRenderingCapableReply rep;
145 REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
146 REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
149 rep.sequenceNumber = client->sequence;
151 if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen],
155 rep.isCapable = isCapable;
157 if (!LocalClient(client))
160 WriteToClient(client,
161 sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
166 ProcAppleDRIAuthConnection(
167 register ClientPtr client
170 xAppleDRIAuthConnectionReply rep;
172 REQUEST(xAppleDRIAuthConnectionReq);
173 REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
177 rep.sequenceNumber = client->sequence;
178 rep.authenticated = 1;
180 if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
181 ErrorF("Failed to authenticate %u\n", (unsigned int)stuff->magic);
182 rep.authenticated = 0;
184 WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
188 static void surface_notify(
193 DRISurfaceNotifyArg *arg = _arg;
194 int client_index = (int) x_cvt_vptr_to_uint(data);
195 xAppleDRINotifyEvent se;
197 if (client_index < 0 || client_index >= currentMaxClients)
200 se.type = DRIEventBase + AppleDRISurfaceNotify;
203 se.time = currentTime.milliseconds;
204 WriteEventsToClient (clients[client_index], 1, (xEvent *) &se);
208 ProcAppleDRICreateSurface(
212 xAppleDRICreateSurfaceReply rep;
213 DrawablePtr pDrawable;
218 REQUEST(xAppleDRICreateSurfaceReq);
219 REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
222 rep.sequenceNumber = client->sequence;
224 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
229 rep.key_0 = rep.key_1 = rep.uid = 0;
231 if (!DRICreateSurface( screenInfo.screens[stuff->screen],
232 (Drawable)stuff->drawable, pDrawable,
233 stuff->client_id, &sid, key,
235 x_cvt_uint_to_vptr(client->index))) {
243 WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
248 ProcAppleDRIDestroySurface(
249 register ClientPtr client
253 REQUEST(xAppleDRIDestroySurfaceReq);
254 DrawablePtr pDrawable;
255 REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
257 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
262 if (!DRIDestroySurface( screenInfo.screens[stuff->screen],
263 (Drawable)stuff->drawable,
264 pDrawable, NULL, NULL)) {
272 ProcAppleDRICreatePixmap(ClientPtr client)
274 REQUEST(xAppleDRICreatePixmapReq);
275 DrawablePtr pDrawable;
278 xAppleDRICreatePixmapReply rep;
279 int width, height, pitch, bpp;
282 REQUEST_SIZE_MATCH(xAppleDRICreatePixmapReq);
284 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
290 if(!DRICreatePixmap(screenInfo.screens[stuff->screen],
291 (Drawable)stuff->drawable,
297 if(!DRIGetPixmapData(pDrawable, &width, &height,
298 &pitch, &bpp, &ptr)) {
302 rep.stringLength = strlen(path) + 1;
304 /* No need for swapping, because this only runs if LocalClient is true. */
306 rep.length = sizeof(rep) + rep.stringLength;
307 rep.sequenceNumber = client->sequence;
312 rep.size = pitch * height;
314 if(sizeof(rep) != sz_xAppleDRICreatePixmapReply)
315 ErrorF("error sizeof(rep) is %zu\n", sizeof(rep));
317 WriteReplyToClient(client, sizeof(rep), &rep);
318 (void)WriteToClient(client, rep.stringLength, path);
324 ProcAppleDRIDestroyPixmap(ClientPtr client)
326 DrawablePtr pDrawable;
328 REQUEST(xAppleDRIDestroyPixmapReq);
329 REQUEST_SIZE_MATCH(xAppleDRIDestroyPixmapReq);
331 rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
337 DRIDestroyPixmap(pDrawable);
345 ProcAppleDRIDispatch (
346 register ClientPtr client
353 case X_AppleDRIQueryVersion:
354 return ProcAppleDRIQueryVersion(client);
355 case X_AppleDRIQueryDirectRenderingCapable:
356 return ProcAppleDRIQueryDirectRenderingCapable(client);
359 if (!LocalClient(client))
360 return DRIErrorBase + AppleDRIClientNotLocal;
364 case X_AppleDRIAuthConnection:
365 return ProcAppleDRIAuthConnection(client);
366 case X_AppleDRICreateSurface:
367 return ProcAppleDRICreateSurface(client);
368 case X_AppleDRIDestroySurface:
369 return ProcAppleDRIDestroySurface(client);
370 case X_AppleDRICreatePixmap:
371 return ProcAppleDRICreatePixmap(client);
372 case X_AppleDRIDestroyPixmap:
373 return ProcAppleDRIDestroyPixmap(client);
382 xAppleDRINotifyEvent *from,
383 xAppleDRINotifyEvent *to
386 to->type = from->type;
387 to->kind = from->kind;
388 cpswaps (from->sequenceNumber, to->sequenceNumber);
389 cpswapl (from->time, to->time);
390 cpswapl (from->arg, to->arg);
394 SProcAppleDRIQueryVersion(
395 register ClientPtr client
399 REQUEST(xAppleDRIQueryVersionReq);
400 swaps(&stuff->length, n);
401 return ProcAppleDRIQueryVersion(client);
405 SProcAppleDRIDispatch (
406 register ClientPtr client
411 /* It is bound to be non-local when there is byte swapping */
412 if (!LocalClient(client))
413 return DRIErrorBase + AppleDRIClientNotLocal;
415 /* only local clients are allowed DRI access */
418 case X_AppleDRIQueryVersion:
419 return SProcAppleDRIQueryVersion(client);