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>
42
#include <X11/Xproto.h>
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 "dristruct.h"
56
static int DRIErrorBase = 0;
58
static DISPATCH_PROC(ProcAppleDRIDispatch);
59
static DISPATCH_PROC(SProcAppleDRIDispatch);
61
static void AppleDRIResetProc(ExtensionEntry* extEntry);
63
static unsigned char DRIReqCode = 0;
64
static int DRIEventBase = 0;
66
static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
68
typedef struct _DRIEvent *DRIEventPtr;
69
typedef struct _DRIEvent {
78
AppleDRIExtensionInit(void)
80
ExtensionEntry* extEntry;
82
if (DRIExtensionInit() &&
83
(extEntry = AddExtension(APPLEDRINAME,
87
SProcAppleDRIDispatch,
89
StandardMinorOpcode))) {
90
DRIReqCode = (unsigned char)extEntry->base;
91
DRIErrorBase = extEntry->errorBase;
92
DRIEventBase = extEntry->eventBase;
93
EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
100
ExtensionEntry* extEntry
107
ProcAppleDRIQueryVersion(
108
register ClientPtr client
111
xAppleDRIQueryVersionReply rep;
114
REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
117
rep.sequenceNumber = client->sequence;
118
rep.majorVersion = APPLE_DRI_MAJOR_VERSION;
119
rep.minorVersion = APPLE_DRI_MINOR_VERSION;
120
rep.patchVersion = APPLE_DRI_PATCH_VERSION;
121
if (client->swapped) {
122
swaps(&rep.sequenceNumber, n);
123
swapl(&rep.length, n);
125
WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
126
return (client->noClientException);
133
ProcAppleDRIQueryDirectRenderingCapable(
134
register ClientPtr client
137
xAppleDRIQueryDirectRenderingCapableReply rep;
140
REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
141
REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
144
rep.sequenceNumber = client->sequence;
146
if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen],
150
rep.isCapable = isCapable;
152
if (!LocalClient(client))
155
WriteToClient(client,
156
sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
157
return (client->noClientException);
161
ProcAppleDRIAuthConnection(
162
register ClientPtr client
165
xAppleDRIAuthConnectionReply rep;
167
REQUEST(xAppleDRIAuthConnectionReq);
168
REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
172
rep.sequenceNumber = client->sequence;
173
rep.authenticated = 1;
175
if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
176
ErrorF("Failed to authenticate %u\n", stuff->magic);
177
rep.authenticated = 0;
179
WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
180
return (client->noClientException);
183
static void surface_notify(
188
DRISurfaceNotifyArg *arg = _arg;
189
int client_index = (int) data;
191
xAppleDRINotifyEvent se;
193
if (client_index < 0 || client_index >= currentMaxClients)
196
client = clients[client_index];
197
if (client == NULL || client == serverClient || client->clientGone)
200
se.type = DRIEventBase + AppleDRISurfaceNotify;
203
se.sequenceNumber = client->sequence;
204
se.time = currentTime.milliseconds;
205
WriteEventsToClient (client, 1, (xEvent *) &se);
209
ProcAppleDRICreateSurface(
213
xAppleDRICreateSurfaceReply rep;
214
DrawablePtr pDrawable;
218
REQUEST(xAppleDRICreateSurfaceReq);
219
REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
222
rep.sequenceNumber = client->sequence;
224
if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
225
(Drawable)stuff->drawable,
227
SecurityReadAccess))) {
231
rep.key_0 = rep.key_1 = rep.uid = 0;
233
if (!DRICreateSurface( screenInfo.screens[stuff->screen],
234
(Drawable)stuff->drawable, pDrawable,
235
stuff->client_id, &sid, key,
236
surface_notify, (void *) client->index)) {
244
WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
245
return (client->noClientException);
249
ProcAppleDRIDestroySurface(
250
register ClientPtr client
253
REQUEST(xAppleDRIDestroySurfaceReq);
254
DrawablePtr pDrawable;
255
REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
257
if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
258
(Drawable)stuff->drawable,
260
SecurityReadAccess))) {
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);