~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/darwin/quartz/xpr/appledri.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/GL/dri/xf86dri.c,v 1.10 2000/12/07 20:26:14 dawes Exp $ */
 
2
/**************************************************************************
 
3
 
 
4
Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
 
5
Copyright 2000 VA Linux Systems, Inc.
 
6
Copyright (c) 2002 Apple Computer, Inc.
 
7
All Rights Reserved.
 
8
 
 
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:
 
16
 
 
17
The above copyright notice and this permission notice (including the
 
18
next paragraph) shall be included in all copies or substantial portions
 
19
of the Software.
 
20
 
 
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.
 
28
 
 
29
**************************************************************************/
 
30
 
 
31
/*
 
32
 * Authors:
 
33
 *   Kevin E. Martin <martin@valinux.com>
 
34
 *   Jens Owen <jens@valinux.com>
 
35
 *   Rickard E. (Rik) Faith <faith@valinux.com>
 
36
 *
 
37
 */
 
38
 
 
39
#define NEED_REPLIES
 
40
#define NEED_EVENTS
 
41
#include <X11/X.h>
 
42
#include <X11/Xproto.h>
 
43
#include "misc.h"
 
44
#include "dixstruct.h"
 
45
#include "extnsionst.h"
 
46
#include "colormapst.h"
 
47
#include "cursorstr.h"
 
48
#include "scrnintstr.h"
 
49
#include "servermd.h"
 
50
#define _APPLEDRI_SERVER_
 
51
#include "appledristr.h"
 
52
#include "swaprep.h"
 
53
#include "dri.h"
 
54
#include "dristruct.h"
 
55
 
 
56
static int DRIErrorBase = 0;
 
57
 
 
58
static DISPATCH_PROC(ProcAppleDRIDispatch);
 
59
static DISPATCH_PROC(SProcAppleDRIDispatch);
 
60
 
 
61
static void AppleDRIResetProc(ExtensionEntry* extEntry);
 
62
 
 
63
static unsigned char DRIReqCode = 0;
 
64
static int DRIEventBase = 0;
 
65
 
 
66
static void SNotifyEvent(xAppleDRINotifyEvent *from, xAppleDRINotifyEvent *to);
 
67
 
 
68
typedef struct _DRIEvent *DRIEventPtr;
 
69
typedef struct _DRIEvent {
 
70
    DRIEventPtr     next;
 
71
    ClientPtr       client;
 
72
    XID             clientResource;
 
73
    unsigned int    mask;
 
74
} DRIEventRec;
 
75
 
 
76
 
 
77
void
 
78
AppleDRIExtensionInit(void)
 
79
{
 
80
    ExtensionEntry* extEntry;
 
81
 
 
82
    if (DRIExtensionInit() &&
 
83
        (extEntry = AddExtension(APPLEDRINAME,
 
84
                                 AppleDRINumberEvents,
 
85
                                 AppleDRINumberErrors,
 
86
                                 ProcAppleDRIDispatch,
 
87
                                 SProcAppleDRIDispatch,
 
88
                                 AppleDRIResetProc,
 
89
                                 StandardMinorOpcode))) {
 
90
        DRIReqCode = (unsigned char)extEntry->base;
 
91
        DRIErrorBase = extEntry->errorBase;
 
92
        DRIEventBase = extEntry->eventBase;
 
93
        EventSwapVector[DRIEventBase] = (EventSwapPtr) SNotifyEvent;
 
94
    }
 
95
}
 
96
 
 
97
/*ARGSUSED*/
 
98
static void
 
99
AppleDRIResetProc (
 
100
    ExtensionEntry* extEntry
 
101
)
 
102
{
 
103
    DRIReset();
 
104
}
 
105
 
 
106
static int
 
107
ProcAppleDRIQueryVersion(
 
108
    register ClientPtr client
 
109
)
 
110
{
 
111
    xAppleDRIQueryVersionReply rep;
 
112
    register int n;
 
113
 
 
114
    REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq);
 
115
    rep.type = X_Reply;
 
116
    rep.length = 0;
 
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);
 
124
    }
 
125
    WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep);
 
126
    return (client->noClientException);
 
127
}
 
128
 
 
129
 
 
130
/* surfaces */
 
131
 
 
132
static int
 
133
ProcAppleDRIQueryDirectRenderingCapable(
 
134
    register ClientPtr client
 
135
)
 
136
{
 
137
    xAppleDRIQueryDirectRenderingCapableReply rep;
 
138
    Bool isCapable;
 
139
 
 
140
    REQUEST(xAppleDRIQueryDirectRenderingCapableReq);
 
141
    REQUEST_SIZE_MATCH(xAppleDRIQueryDirectRenderingCapableReq);
 
142
    rep.type = X_Reply;
 
143
    rep.length = 0;
 
144
    rep.sequenceNumber = client->sequence;
 
145
 
 
146
    if (!DRIQueryDirectRenderingCapable( screenInfo.screens[stuff->screen], 
 
147
                                         &isCapable)) {
 
148
        return BadValue;
 
149
    }
 
150
    rep.isCapable = isCapable;
 
151
 
 
152
    if (!LocalClient(client))
 
153
        rep.isCapable = 0;
 
154
 
 
155
    WriteToClient(client, 
 
156
        sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep);
 
157
    return (client->noClientException);
 
158
}
 
159
 
 
160
static int
 
161
ProcAppleDRIAuthConnection(
 
162
    register ClientPtr client
 
163
)
 
164
{
 
165
    xAppleDRIAuthConnectionReply rep;
 
166
    
 
167
    REQUEST(xAppleDRIAuthConnectionReq);
 
168
    REQUEST_SIZE_MATCH(xAppleDRIAuthConnectionReq);
 
169
 
 
170
    rep.type = X_Reply;
 
171
    rep.length = 0;
 
172
    rep.sequenceNumber = client->sequence;
 
173
    rep.authenticated = 1;
 
174
 
 
175
    if (!DRIAuthConnection( screenInfo.screens[stuff->screen], stuff->magic)) {
 
176
        ErrorF("Failed to authenticate %u\n", stuff->magic);
 
177
        rep.authenticated = 0;
 
178
    }
 
179
    WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep);
 
180
    return (client->noClientException);
 
181
}
 
182
 
 
183
static void surface_notify(
 
184
    void *_arg,
 
185
    void *data
 
186
)
 
187
{
 
188
    DRISurfaceNotifyArg *arg = _arg;
 
189
    int client_index = (int) data;
 
190
    ClientPtr client;
 
191
    xAppleDRINotifyEvent se;
 
192
 
 
193
    if (client_index < 0 || client_index >= currentMaxClients)
 
194
        return;
 
195
 
 
196
    client = clients[client_index];
 
197
    if (client == NULL || client == serverClient || client->clientGone)
 
198
        return;
 
199
 
 
200
    se.type = DRIEventBase + AppleDRISurfaceNotify;
 
201
    se.kind = arg->kind;
 
202
    se.arg = arg->id;
 
203
    se.sequenceNumber = client->sequence;
 
204
    se.time = currentTime.milliseconds;
 
205
    WriteEventsToClient (client, 1, (xEvent *) &se);
 
206
}
 
207
 
 
208
static int
 
209
ProcAppleDRICreateSurface(
 
210
    ClientPtr client
 
211
)
 
212
{
 
213
    xAppleDRICreateSurfaceReply rep;
 
214
    DrawablePtr pDrawable;
 
215
    xp_surface_id sid;
 
216
    unsigned int key[2];
 
217
 
 
218
    REQUEST(xAppleDRICreateSurfaceReq);
 
219
    REQUEST_SIZE_MATCH(xAppleDRICreateSurfaceReq);
 
220
    rep.type = X_Reply;
 
221
    rep.length = 0;
 
222
    rep.sequenceNumber = client->sequence;
 
223
 
 
224
    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
 
225
                                                (Drawable)stuff->drawable,
 
226
                                                client, 
 
227
                                                SecurityReadAccess))) {
 
228
        return BadValue;
 
229
    }
 
230
 
 
231
    rep.key_0 = rep.key_1 = rep.uid = 0;
 
232
 
 
233
    if (!DRICreateSurface( screenInfo.screens[stuff->screen],
 
234
                           (Drawable)stuff->drawable, pDrawable,
 
235
                           stuff->client_id, &sid, key,
 
236
                           surface_notify, (void *) client->index)) {
 
237
        return BadValue;
 
238
    }
 
239
 
 
240
    rep.key_0 = key[0];
 
241
    rep.key_1 = key[1];
 
242
    rep.uid = sid;
 
243
 
 
244
    WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep);
 
245
    return (client->noClientException);
 
246
}
 
247
 
 
248
static int
 
249
ProcAppleDRIDestroySurface(
 
250
    register ClientPtr client
 
251
)
 
252
{
 
253
    REQUEST(xAppleDRIDestroySurfaceReq);
 
254
    DrawablePtr pDrawable;
 
255
    REQUEST_SIZE_MATCH(xAppleDRIDestroySurfaceReq);
 
256
 
 
257
    if (!(pDrawable = (DrawablePtr)SecurityLookupDrawable(
 
258
                                                (Drawable)stuff->drawable,
 
259
                                                client, 
 
260
                                                SecurityReadAccess))) {
 
261
        return BadValue;
 
262
    }
 
263
 
 
264
    if (!DRIDestroySurface( screenInfo.screens[stuff->screen], 
 
265
                            (Drawable)stuff->drawable,
 
266
                            pDrawable, NULL, NULL)) {
 
267
        return BadValue;
 
268
    }
 
269
 
 
270
    return (client->noClientException);
 
271
}
 
272
 
 
273
 
 
274
/* dispatch */
 
275
 
 
276
static int
 
277
ProcAppleDRIDispatch (
 
278
    register ClientPtr client
 
279
)
 
280
{
 
281
    REQUEST(xReq);
 
282
 
 
283
    switch (stuff->data)
 
284
    {
 
285
    case X_AppleDRIQueryVersion:
 
286
        return ProcAppleDRIQueryVersion(client);
 
287
    case X_AppleDRIQueryDirectRenderingCapable:
 
288
        return ProcAppleDRIQueryDirectRenderingCapable(client);
 
289
    }
 
290
 
 
291
    if (!LocalClient(client))
 
292
        return DRIErrorBase + AppleDRIClientNotLocal;
 
293
 
 
294
    switch (stuff->data)
 
295
    {
 
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;
 
304
    }
 
305
}
 
306
 
 
307
static void
 
308
SNotifyEvent(
 
309
    xAppleDRINotifyEvent *from,
 
310
    xAppleDRINotifyEvent *to
 
311
)
 
312
{
 
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);
 
318
}
 
319
 
 
320
static int
 
321
SProcAppleDRIQueryVersion(
 
322
    register ClientPtr client
 
323
)
 
324
{
 
325
    register int n;
 
326
    REQUEST(xAppleDRIQueryVersionReq);
 
327
    swaps(&stuff->length, n);
 
328
    return ProcAppleDRIQueryVersion(client);
 
329
}
 
330
 
 
331
static int
 
332
SProcAppleDRIDispatch (
 
333
    register ClientPtr client
 
334
)
 
335
{
 
336
    REQUEST(xReq);
 
337
 
 
338
    /* It is bound to be non-local when there is byte swapping */
 
339
    if (!LocalClient(client))
 
340
        return DRIErrorBase + AppleDRIClientNotLocal;
 
341
 
 
342
    /* only local clients are allowed DRI access */
 
343
    switch (stuff->data)
 
344
    {
 
345
    case X_AppleDRIQueryVersion:
 
346
        return SProcAppleDRIQueryVersion(client);
 
347
    default:
 
348
        return BadRequest;
 
349
    }
 
350
}