1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2016, NVIDIA CORPORATION.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun * copy of this software and/or associated documentation files (the
6*4882a593Smuzhiyun * "Materials"), to deal in the Materials without restriction, including
7*4882a593Smuzhiyun * without limitation the rights to use, copy, modify, merge, publish,
8*4882a593Smuzhiyun * distribute, sublicense, and/or sell copies of the Materials, and to
9*4882a593Smuzhiyun * permit persons to whom the Materials are furnished to do so, subject to
10*4882a593Smuzhiyun * the following conditions:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included
13*4882a593Smuzhiyun * unaltered in all copies or substantial portions of the Materials.
14*4882a593Smuzhiyun * Any additions, deletions, or changes to the original source files
15*4882a593Smuzhiyun * must be clearly indicated in accompanying documentation.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * If only executable code is distributed, then the accompanying
18*4882a593Smuzhiyun * documentation must state that "this software is based in part on the
19*4882a593Smuzhiyun * work of the Khronos Group."
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24*4882a593Smuzhiyun * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25*4882a593Smuzhiyun * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26*4882a593Smuzhiyun * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27*4882a593Smuzhiyun * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include <dix-config.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "hashtable.h"
33*4882a593Smuzhiyun #include "vndserver.h"
34*4882a593Smuzhiyun #include "vndservervendor.h"
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun /**
37*4882a593Smuzhiyun * The length of the dispatchFuncs array. Every opcode above this is a
38*4882a593Smuzhiyun * X_GLsop_* code, which all can use the same handler.
39*4882a593Smuzhiyun */
40*4882a593Smuzhiyun #define OPCODE_ARRAY_LEN 100
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun // This hashtable is used to keep track of the dispatch stubs for
43*4882a593Smuzhiyun // GLXVendorPrivate and GLXVendorPrivateWithReply.
44*4882a593Smuzhiyun typedef struct GlxVendorPrivDispatchRec {
45*4882a593Smuzhiyun CARD32 vendorCode;
46*4882a593Smuzhiyun GlxServerDispatchProc proc;
47*4882a593Smuzhiyun HashTable hh;
48*4882a593Smuzhiyun } GlxVendorPrivDispatch;
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun static GlxServerDispatchProc dispatchFuncs[OPCODE_ARRAY_LEN] = {};
51*4882a593Smuzhiyun static HashTable vendorPrivHash = NULL;
52*4882a593Smuzhiyun static HtGenericHashSetupRec vendorPrivSetup = {
53*4882a593Smuzhiyun .keySize = sizeof(CARD32)
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun
DispatchBadRequest(ClientPtr client)56*4882a593Smuzhiyun static int DispatchBadRequest(ClientPtr client)
57*4882a593Smuzhiyun {
58*4882a593Smuzhiyun return BadRequest;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
LookupVendorPrivDispatch(CARD32 vendorCode,Bool create)61*4882a593Smuzhiyun static GlxVendorPrivDispatch *LookupVendorPrivDispatch(CARD32 vendorCode, Bool create)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun GlxVendorPrivDispatch *disp = NULL;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun disp = ht_find(vendorPrivHash, &vendorCode);
66*4882a593Smuzhiyun if (disp == NULL && create) {
67*4882a593Smuzhiyun if ((disp = ht_add(vendorPrivHash, &vendorCode))) {
68*4882a593Smuzhiyun disp->vendorCode = vendorCode;
69*4882a593Smuzhiyun disp->proc = NULL;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun return disp;
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
GetVendorDispatchFunc(CARD8 opcode,CARD32 vendorCode)76*4882a593Smuzhiyun static GlxServerDispatchProc GetVendorDispatchFunc(CARD8 opcode, CARD32 vendorCode)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun GlxServerVendor *vendor;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun xorg_list_for_each_entry(vendor, &GlxVendorList, entry) {
81*4882a593Smuzhiyun GlxServerDispatchProc proc = vendor->glxvc.getDispatchAddress(opcode, vendorCode);
82*4882a593Smuzhiyun if (proc != NULL) {
83*4882a593Smuzhiyun return proc;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun return DispatchBadRequest;
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun
SetReplyHeader(ClientPtr client,void * replyPtr)90*4882a593Smuzhiyun static void SetReplyHeader(ClientPtr client, void *replyPtr)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun xGenericReply *rep = (xGenericReply *) replyPtr;
93*4882a593Smuzhiyun rep->type = X_Reply;
94*4882a593Smuzhiyun rep->sequenceNumber = client->sequence;
95*4882a593Smuzhiyun rep->length = 0;
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun /* Include the trivial dispatch handlers */
99*4882a593Smuzhiyun #include "vnd_dispatch_stubs.c"
100*4882a593Smuzhiyun
dispatch_GLXQueryVersion(ClientPtr client)101*4882a593Smuzhiyun static int dispatch_GLXQueryVersion(ClientPtr client)
102*4882a593Smuzhiyun {
103*4882a593Smuzhiyun xGLXQueryVersionReply reply;
104*4882a593Smuzhiyun REQUEST_SIZE_MATCH(xGLXQueryVersionReq);
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun SetReplyHeader(client, &reply);
107*4882a593Smuzhiyun reply.majorVersion = GlxCheckSwap(client, 1);
108*4882a593Smuzhiyun reply.minorVersion = GlxCheckSwap(client, 4);
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun WriteToClient(client, sz_xGLXQueryVersionReply, &reply);
111*4882a593Smuzhiyun return Success;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun /* broken header workaround */
115*4882a593Smuzhiyun #ifndef X_GLXSetClientInfo2ARB
116*4882a593Smuzhiyun #define X_GLXSetClientInfo2ARB X_GLXSetConfigInfo2ARB
117*4882a593Smuzhiyun #endif
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /**
120*4882a593Smuzhiyun * This function is used for X_GLXClientInfo, X_GLXSetClientInfoARB, and
121*4882a593Smuzhiyun * X_GLXSetClientInfo2ARB.
122*4882a593Smuzhiyun */
dispatch_GLXClientInfo(ClientPtr client)123*4882a593Smuzhiyun static int dispatch_GLXClientInfo(ClientPtr client)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun GlxServerVendor *vendor;
126*4882a593Smuzhiyun void *requestCopy = NULL;
127*4882a593Smuzhiyun size_t requestSize = client->req_len * 4;
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun if (client->minorOp == X_GLXClientInfo) {
130*4882a593Smuzhiyun REQUEST_AT_LEAST_SIZE(xGLXClientInfoReq);
131*4882a593Smuzhiyun } else if (client->minorOp == X_GLXSetClientInfoARB) {
132*4882a593Smuzhiyun REQUEST_AT_LEAST_SIZE(xGLXSetClientInfoARBReq);
133*4882a593Smuzhiyun } else if (client->minorOp == X_GLXSetClientInfo2ARB) {
134*4882a593Smuzhiyun REQUEST_AT_LEAST_SIZE(xGLXSetClientInfo2ARBReq);
135*4882a593Smuzhiyun } else {
136*4882a593Smuzhiyun return BadImplementation;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun // We'll forward this request to each vendor library. Since a vendor might
140*4882a593Smuzhiyun // modify the request data in place (e.g., for byte swapping), make a copy
141*4882a593Smuzhiyun // of the request first.
142*4882a593Smuzhiyun requestCopy = malloc(requestSize);
143*4882a593Smuzhiyun if (requestCopy == NULL) {
144*4882a593Smuzhiyun return BadAlloc;
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun memcpy(requestCopy, client->requestBuffer, requestSize);
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun xorg_list_for_each_entry(vendor, &GlxVendorList, entry) {
149*4882a593Smuzhiyun vendor->glxvc.handleRequest(client);
150*4882a593Smuzhiyun // Revert the request buffer back to our copy.
151*4882a593Smuzhiyun memcpy(client->requestBuffer, requestCopy, requestSize);
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun free(requestCopy);
154*4882a593Smuzhiyun return Success;
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun
CommonLoseCurrent(ClientPtr client,GlxContextTagInfo * tagInfo)157*4882a593Smuzhiyun static int CommonLoseCurrent(ClientPtr client, GlxContextTagInfo *tagInfo)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun int ret;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun ret = tagInfo->vendor->glxvc.makeCurrent(client,
162*4882a593Smuzhiyun tagInfo->tag, // No old context tag,
163*4882a593Smuzhiyun None, None, None, 0);
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun if (ret == Success) {
166*4882a593Smuzhiyun GlxFreeContextTag(tagInfo);
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun return ret;
169*4882a593Smuzhiyun }
170*4882a593Smuzhiyun
CommonMakeNewCurrent(ClientPtr client,GlxServerVendor * vendor,GLXDrawable drawable,GLXDrawable readdrawable,GLXContextID context,GLXContextTag * newContextTag)171*4882a593Smuzhiyun static int CommonMakeNewCurrent(ClientPtr client,
172*4882a593Smuzhiyun GlxServerVendor *vendor,
173*4882a593Smuzhiyun GLXDrawable drawable,
174*4882a593Smuzhiyun GLXDrawable readdrawable,
175*4882a593Smuzhiyun GLXContextID context,
176*4882a593Smuzhiyun GLXContextTag *newContextTag)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun int ret = BadAlloc;
179*4882a593Smuzhiyun GlxContextTagInfo *tagInfo;
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun tagInfo = GlxAllocContextTag(client, vendor);
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun if (tagInfo) {
184*4882a593Smuzhiyun ret = vendor->glxvc.makeCurrent(client,
185*4882a593Smuzhiyun 0, // No old context tag,
186*4882a593Smuzhiyun drawable, readdrawable, context,
187*4882a593Smuzhiyun tagInfo->tag);
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun if (ret == Success) {
190*4882a593Smuzhiyun tagInfo->drawable = drawable;
191*4882a593Smuzhiyun tagInfo->readdrawable = readdrawable;
192*4882a593Smuzhiyun tagInfo->context = context;
193*4882a593Smuzhiyun *newContextTag = tagInfo->tag;
194*4882a593Smuzhiyun } else {
195*4882a593Smuzhiyun GlxFreeContextTag(tagInfo);
196*4882a593Smuzhiyun }
197*4882a593Smuzhiyun }
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun return ret;
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun
CommonMakeCurrent(ClientPtr client,GLXContextTag oldContextTag,GLXDrawable drawable,GLXDrawable readdrawable,GLXContextID context)202*4882a593Smuzhiyun static int CommonMakeCurrent(ClientPtr client,
203*4882a593Smuzhiyun GLXContextTag oldContextTag,
204*4882a593Smuzhiyun GLXDrawable drawable,
205*4882a593Smuzhiyun GLXDrawable readdrawable,
206*4882a593Smuzhiyun GLXContextID context)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun xGLXMakeCurrentReply reply = {};
209*4882a593Smuzhiyun GlxContextTagInfo *oldTag = NULL;
210*4882a593Smuzhiyun GlxServerVendor *newVendor = NULL;
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun oldContextTag = GlxCheckSwap(client, oldContextTag);
213*4882a593Smuzhiyun drawable = GlxCheckSwap(client, drawable);
214*4882a593Smuzhiyun readdrawable = GlxCheckSwap(client, readdrawable);
215*4882a593Smuzhiyun context = GlxCheckSwap(client, context);
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun SetReplyHeader(client, &reply);
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun if (oldContextTag != 0) {
220*4882a593Smuzhiyun oldTag = GlxLookupContextTag(client, oldContextTag);
221*4882a593Smuzhiyun if (oldTag == NULL) {
222*4882a593Smuzhiyun return GlxErrorBase + GLXBadContextTag;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun if (context != 0) {
226*4882a593Smuzhiyun newVendor = GlxGetXIDMap(context);
227*4882a593Smuzhiyun if (newVendor == NULL) {
228*4882a593Smuzhiyun return GlxErrorBase + GLXBadContext;
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun if (oldTag == NULL && newVendor == NULL) {
233*4882a593Smuzhiyun // Nothing to do here. Just send a successful reply.
234*4882a593Smuzhiyun reply.contextTag = 0;
235*4882a593Smuzhiyun } else if (oldTag != NULL && newVendor != NULL
236*4882a593Smuzhiyun && oldTag->context == context
237*4882a593Smuzhiyun && oldTag->drawable == drawable
238*4882a593Smuzhiyun && oldTag->readdrawable == readdrawable)
239*4882a593Smuzhiyun {
240*4882a593Smuzhiyun // The old and new values are all the same, so send a successful reply.
241*4882a593Smuzhiyun reply.contextTag = oldTag->tag;
242*4882a593Smuzhiyun } else {
243*4882a593Smuzhiyun // TODO: For switching contexts in a single vendor, just make one
244*4882a593Smuzhiyun // makeCurrent call?
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun // TODO: When changing vendors, would it be better to do the
247*4882a593Smuzhiyun // MakeCurrent(new) first, then the LoseCurrent(old)?
248*4882a593Smuzhiyun // If the MakeCurrent(new) fails, then the old context will still be current.
249*4882a593Smuzhiyun // If the LoseCurrent(old) fails, then we can (probably) undo the MakeCurrent(new) with
250*4882a593Smuzhiyun // a LoseCurrent(old).
251*4882a593Smuzhiyun // But, if the recovery LoseCurrent(old) fails, then we're really in a bad state.
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun // Clear the old context first.
254*4882a593Smuzhiyun if (oldTag != NULL) {
255*4882a593Smuzhiyun int ret = CommonLoseCurrent(client, oldTag);
256*4882a593Smuzhiyun if (ret != Success) {
257*4882a593Smuzhiyun return ret;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun oldTag = NULL;
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun if (newVendor != NULL) {
263*4882a593Smuzhiyun int ret = CommonMakeNewCurrent(client, newVendor, drawable, readdrawable, context, &reply.contextTag);
264*4882a593Smuzhiyun if (ret != Success) {
265*4882a593Smuzhiyun return ret;
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun } else {
268*4882a593Smuzhiyun reply.contextTag = 0;
269*4882a593Smuzhiyun }
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun reply.contextTag = GlxCheckSwap(client, reply.contextTag);
273*4882a593Smuzhiyun WriteToClient(client, sz_xGLXMakeCurrentReply, &reply);
274*4882a593Smuzhiyun return Success;
275*4882a593Smuzhiyun }
276*4882a593Smuzhiyun
dispatch_GLXMakeCurrent(ClientPtr client)277*4882a593Smuzhiyun static int dispatch_GLXMakeCurrent(ClientPtr client)
278*4882a593Smuzhiyun {
279*4882a593Smuzhiyun REQUEST(xGLXMakeCurrentReq);
280*4882a593Smuzhiyun REQUEST_SIZE_MATCH(*stuff);
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun return CommonMakeCurrent(client, stuff->oldContextTag,
283*4882a593Smuzhiyun stuff->drawable, stuff->drawable, stuff->context);
284*4882a593Smuzhiyun }
285*4882a593Smuzhiyun
dispatch_GLXMakeContextCurrent(ClientPtr client)286*4882a593Smuzhiyun static int dispatch_GLXMakeContextCurrent(ClientPtr client)
287*4882a593Smuzhiyun {
288*4882a593Smuzhiyun REQUEST(xGLXMakeContextCurrentReq);
289*4882a593Smuzhiyun REQUEST_SIZE_MATCH(*stuff);
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun return CommonMakeCurrent(client, stuff->oldContextTag,
292*4882a593Smuzhiyun stuff->drawable, stuff->readdrawable, stuff->context);
293*4882a593Smuzhiyun }
294*4882a593Smuzhiyun
dispatch_GLXMakeCurrentReadSGI(ClientPtr client)295*4882a593Smuzhiyun static int dispatch_GLXMakeCurrentReadSGI(ClientPtr client)
296*4882a593Smuzhiyun {
297*4882a593Smuzhiyun REQUEST(xGLXMakeCurrentReadSGIReq);
298*4882a593Smuzhiyun REQUEST_SIZE_MATCH(*stuff);
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun return CommonMakeCurrent(client, stuff->oldContextTag,
301*4882a593Smuzhiyun stuff->drawable, stuff->readable, stuff->context);
302*4882a593Smuzhiyun }
303*4882a593Smuzhiyun
dispatch_GLXCopyContext(ClientPtr client)304*4882a593Smuzhiyun static int dispatch_GLXCopyContext(ClientPtr client)
305*4882a593Smuzhiyun {
306*4882a593Smuzhiyun REQUEST(xGLXCopyContextReq);
307*4882a593Smuzhiyun GlxServerVendor *vendor;
308*4882a593Smuzhiyun REQUEST_SIZE_MATCH(*stuff);
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun // If we've got a context tag, then we'll use it to select a vendor. If we
311*4882a593Smuzhiyun // don't have a tag, then we'll look up one of the contexts. In either
312*4882a593Smuzhiyun // case, it's up to the vendor library to make sure that the context ID's
313*4882a593Smuzhiyun // are valid.
314*4882a593Smuzhiyun if (stuff->contextTag != 0) {
315*4882a593Smuzhiyun GlxContextTagInfo *tagInfo = GlxLookupContextTag(client, GlxCheckSwap(client, stuff->contextTag));
316*4882a593Smuzhiyun if (tagInfo == NULL) {
317*4882a593Smuzhiyun return GlxErrorBase + GLXBadContextTag;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun vendor = tagInfo->vendor;
320*4882a593Smuzhiyun } else {
321*4882a593Smuzhiyun vendor = GlxGetXIDMap(GlxCheckSwap(client, stuff->source));
322*4882a593Smuzhiyun if (vendor == NULL) {
323*4882a593Smuzhiyun return GlxErrorBase + GLXBadContext;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun return vendor->glxvc.handleRequest(client);
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun
dispatch_GLXSwapBuffers(ClientPtr client)329*4882a593Smuzhiyun static int dispatch_GLXSwapBuffers(ClientPtr client)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun GlxServerVendor *vendor = NULL;
332*4882a593Smuzhiyun REQUEST(xGLXSwapBuffersReq);
333*4882a593Smuzhiyun REQUEST_SIZE_MATCH(*stuff);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun if (stuff->contextTag != 0) {
336*4882a593Smuzhiyun // If the request has a context tag, then look up a vendor from that.
337*4882a593Smuzhiyun // The vendor library is then responsible for validating the drawable.
338*4882a593Smuzhiyun GlxContextTagInfo *tagInfo = GlxLookupContextTag(client, GlxCheckSwap(client, stuff->contextTag));
339*4882a593Smuzhiyun if (tagInfo == NULL) {
340*4882a593Smuzhiyun return GlxErrorBase + GLXBadContextTag;
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun vendor = tagInfo->vendor;
343*4882a593Smuzhiyun } else {
344*4882a593Smuzhiyun // We don't have a context tag, so look up the vendor from the
345*4882a593Smuzhiyun // drawable.
346*4882a593Smuzhiyun vendor = GlxGetXIDMap(GlxCheckSwap(client, stuff->drawable));
347*4882a593Smuzhiyun if (vendor == NULL) {
348*4882a593Smuzhiyun return GlxErrorBase + GLXBadDrawable;
349*4882a593Smuzhiyun }
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun return vendor->glxvc.handleRequest(client);
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun /**
356*4882a593Smuzhiyun * This is a generic handler for all of the X_GLXsop* requests.
357*4882a593Smuzhiyun */
dispatch_GLXSingle(ClientPtr client)358*4882a593Smuzhiyun static int dispatch_GLXSingle(ClientPtr client)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun REQUEST(xGLXSingleReq);
361*4882a593Smuzhiyun GlxContextTagInfo *tagInfo;
362*4882a593Smuzhiyun REQUEST_AT_LEAST_SIZE(*stuff);
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun tagInfo = GlxLookupContextTag(client, GlxCheckSwap(client, stuff->contextTag));
365*4882a593Smuzhiyun if (tagInfo != NULL) {
366*4882a593Smuzhiyun return tagInfo->vendor->glxvc.handleRequest(client);
367*4882a593Smuzhiyun } else {
368*4882a593Smuzhiyun return GlxErrorBase + GLXBadContextTag;
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun }
371*4882a593Smuzhiyun
dispatch_GLXVendorPriv(ClientPtr client)372*4882a593Smuzhiyun static int dispatch_GLXVendorPriv(ClientPtr client)
373*4882a593Smuzhiyun {
374*4882a593Smuzhiyun GlxVendorPrivDispatch *disp;
375*4882a593Smuzhiyun REQUEST(xGLXVendorPrivateReq);
376*4882a593Smuzhiyun REQUEST_AT_LEAST_SIZE(*stuff);
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun disp = LookupVendorPrivDispatch(GlxCheckSwap(client, stuff->vendorCode), TRUE);
379*4882a593Smuzhiyun if (disp == NULL) {
380*4882a593Smuzhiyun return BadAlloc;
381*4882a593Smuzhiyun }
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun if (disp->proc == NULL) {
384*4882a593Smuzhiyun // We don't have a dispatch function for this request yet. Check with
385*4882a593Smuzhiyun // each vendor library to find one.
386*4882a593Smuzhiyun // Note that even if none of the vendors provides a dispatch stub,
387*4882a593Smuzhiyun // we'll still add an entry to the dispatch table, so that we don't
388*4882a593Smuzhiyun // have to look it up again later.
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun disp->proc = GetVendorDispatchFunc(stuff->glxCode,
391*4882a593Smuzhiyun GlxCheckSwap(client,
392*4882a593Smuzhiyun stuff->vendorCode));
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun return disp->proc(client);
395*4882a593Smuzhiyun }
396*4882a593Smuzhiyun
GlxDispatchInit(void)397*4882a593Smuzhiyun Bool GlxDispatchInit(void)
398*4882a593Smuzhiyun {
399*4882a593Smuzhiyun GlxVendorPrivDispatch *disp;
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun vendorPrivHash = ht_create(sizeof(CARD32), sizeof(GlxVendorPrivDispatch),
402*4882a593Smuzhiyun ht_generic_hash, ht_generic_compare,
403*4882a593Smuzhiyun (void *) &vendorPrivSetup);
404*4882a593Smuzhiyun if (!vendorPrivHash) {
405*4882a593Smuzhiyun return FALSE;
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun // Assign a custom dispatch stub GLXMakeCurrentReadSGI. This is the only
409*4882a593Smuzhiyun // vendor private request that we need to deal with in libglvnd itself.
410*4882a593Smuzhiyun disp = LookupVendorPrivDispatch(X_GLXvop_MakeCurrentReadSGI, TRUE);
411*4882a593Smuzhiyun if (disp == NULL) {
412*4882a593Smuzhiyun return FALSE;
413*4882a593Smuzhiyun }
414*4882a593Smuzhiyun disp->proc = dispatch_GLXMakeCurrentReadSGI;
415*4882a593Smuzhiyun
416*4882a593Smuzhiyun // Assign the dispatch stubs for requests that need special handling.
417*4882a593Smuzhiyun dispatchFuncs[X_GLXQueryVersion] = dispatch_GLXQueryVersion;
418*4882a593Smuzhiyun dispatchFuncs[X_GLXMakeCurrent] = dispatch_GLXMakeCurrent;
419*4882a593Smuzhiyun dispatchFuncs[X_GLXMakeContextCurrent] = dispatch_GLXMakeContextCurrent;
420*4882a593Smuzhiyun dispatchFuncs[X_GLXCopyContext] = dispatch_GLXCopyContext;
421*4882a593Smuzhiyun dispatchFuncs[X_GLXSwapBuffers] = dispatch_GLXSwapBuffers;
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun dispatchFuncs[X_GLXClientInfo] = dispatch_GLXClientInfo;
424*4882a593Smuzhiyun dispatchFuncs[X_GLXSetClientInfoARB] = dispatch_GLXClientInfo;
425*4882a593Smuzhiyun dispatchFuncs[X_GLXSetClientInfo2ARB] = dispatch_GLXClientInfo;
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun dispatchFuncs[X_GLXVendorPrivate] = dispatch_GLXVendorPriv;
428*4882a593Smuzhiyun dispatchFuncs[X_GLXVendorPrivateWithReply] = dispatch_GLXVendorPriv;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun // Assign the trivial stubs
431*4882a593Smuzhiyun dispatchFuncs[X_GLXRender] = dispatch_Render;
432*4882a593Smuzhiyun dispatchFuncs[X_GLXRenderLarge] = dispatch_RenderLarge;
433*4882a593Smuzhiyun dispatchFuncs[X_GLXCreateContext] = dispatch_CreateContext;
434*4882a593Smuzhiyun dispatchFuncs[X_GLXDestroyContext] = dispatch_DestroyContext;
435*4882a593Smuzhiyun dispatchFuncs[X_GLXWaitGL] = dispatch_WaitGL;
436*4882a593Smuzhiyun dispatchFuncs[X_GLXWaitX] = dispatch_WaitX;
437*4882a593Smuzhiyun dispatchFuncs[X_GLXUseXFont] = dispatch_UseXFont;
438*4882a593Smuzhiyun dispatchFuncs[X_GLXCreateGLXPixmap] = dispatch_CreateGLXPixmap;
439*4882a593Smuzhiyun dispatchFuncs[X_GLXGetVisualConfigs] = dispatch_GetVisualConfigs;
440*4882a593Smuzhiyun dispatchFuncs[X_GLXDestroyGLXPixmap] = dispatch_DestroyGLXPixmap;
441*4882a593Smuzhiyun dispatchFuncs[X_GLXQueryExtensionsString] = dispatch_QueryExtensionsString;
442*4882a593Smuzhiyun dispatchFuncs[X_GLXQueryServerString] = dispatch_QueryServerString;
443*4882a593Smuzhiyun dispatchFuncs[X_GLXChangeDrawableAttributes] = dispatch_ChangeDrawableAttributes;
444*4882a593Smuzhiyun dispatchFuncs[X_GLXCreateNewContext] = dispatch_CreateNewContext;
445*4882a593Smuzhiyun dispatchFuncs[X_GLXCreatePbuffer] = dispatch_CreatePbuffer;
446*4882a593Smuzhiyun dispatchFuncs[X_GLXCreatePixmap] = dispatch_CreatePixmap;
447*4882a593Smuzhiyun dispatchFuncs[X_GLXCreateWindow] = dispatch_CreateWindow;
448*4882a593Smuzhiyun dispatchFuncs[X_GLXCreateContextAttribsARB] = dispatch_CreateContextAttribsARB;
449*4882a593Smuzhiyun dispatchFuncs[X_GLXDestroyPbuffer] = dispatch_DestroyPbuffer;
450*4882a593Smuzhiyun dispatchFuncs[X_GLXDestroyPixmap] = dispatch_DestroyPixmap;
451*4882a593Smuzhiyun dispatchFuncs[X_GLXDestroyWindow] = dispatch_DestroyWindow;
452*4882a593Smuzhiyun dispatchFuncs[X_GLXGetDrawableAttributes] = dispatch_GetDrawableAttributes;
453*4882a593Smuzhiyun dispatchFuncs[X_GLXGetFBConfigs] = dispatch_GetFBConfigs;
454*4882a593Smuzhiyun dispatchFuncs[X_GLXQueryContext] = dispatch_QueryContext;
455*4882a593Smuzhiyun dispatchFuncs[X_GLXIsDirect] = dispatch_IsDirect;
456*4882a593Smuzhiyun
457*4882a593Smuzhiyun return TRUE;
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun
GlxDispatchReset(void)460*4882a593Smuzhiyun void GlxDispatchReset(void)
461*4882a593Smuzhiyun {
462*4882a593Smuzhiyun memset(dispatchFuncs, 0, sizeof(dispatchFuncs));
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun ht_destroy(vendorPrivHash);
465*4882a593Smuzhiyun vendorPrivHash = NULL;
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun
GlxDispatchRequest(ClientPtr client)468*4882a593Smuzhiyun int GlxDispatchRequest(ClientPtr client)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun REQUEST(xReq);
471*4882a593Smuzhiyun int result;
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun if (GlxExtensionEntry->base == 0)
474*4882a593Smuzhiyun return BadRequest;
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun GlxSetRequestClient(client);
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun if (stuff->data < OPCODE_ARRAY_LEN) {
479*4882a593Smuzhiyun if (dispatchFuncs[stuff->data] == NULL) {
480*4882a593Smuzhiyun // Try to find a dispatch stub.
481*4882a593Smuzhiyun dispatchFuncs[stuff->data] = GetVendorDispatchFunc(stuff->data, 0);
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun result = dispatchFuncs[stuff->data](client);
484*4882a593Smuzhiyun } else {
485*4882a593Smuzhiyun result = dispatch_GLXSingle(client);
486*4882a593Smuzhiyun }
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun GlxSetRequestClient(NULL);
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun return result;
491*4882a593Smuzhiyun }
492