1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
/*
* Copyright (c) 2016, NVIDIA CORPORATION.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* unaltered in all copies or substantial portions of the Materials.
* Any additions, deletions, or changes to the original source files
* must be clearly indicated in accompanying documentation.
*
* If only executable code is distributed, then the accompanying
* documentation must state that "this software is based in part on the
* work of the Khronos Group."
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
#include "vndserver.h"
#include <pixmapstr.h>
#include "vndservervendor.h"
static ClientPtr requestClient = NULL;
void GlxSetRequestClient(ClientPtr client)
{
requestClient = client;
}
static GlxServerVendor *LookupXIDMapResource(XID id)
{
void *ptr = NULL;
int rv;
rv = dixLookupResourceByType(&ptr, id, idResource, NULL, DixReadAccess);
if (rv == Success) {
return (GlxServerVendor *) ptr;
} else {
return NULL;
}
}
GlxServerVendor *GlxGetXIDMap(XID id)
{
GlxServerVendor *vendor = LookupXIDMapResource(id);
if (vendor == NULL) {
// If we haven't seen this XID before, then it may be a drawable that
// wasn't created through GLX, like a regular X window or pixmap. Try
// to look up a matching drawable to find a screen number for it.
void *ptr = NULL;
int rv = dixLookupResourceByClass(&ptr, id, RC_DRAWABLE, NULL,
DixGetAttrAccess);
if (rv == Success && ptr != NULL) {
DrawablePtr draw = (DrawablePtr) ptr;
vendor = GlxGetVendorForScreen(requestClient, draw->pScreen);
}
}
return vendor;
}
Bool GlxAddXIDMap(XID id, GlxServerVendor *vendor)
{
if (id == 0 || vendor == NULL) {
return FALSE;
}
if (LookupXIDMapResource(id) != NULL) {
return FALSE;
}
return AddResource(id, idResource, vendor);
}
void GlxRemoveXIDMap(XID id)
{
FreeResourceByType(id, idResource, FALSE);
}
GlxContextTagInfo *GlxAllocContextTag(ClientPtr client, GlxServerVendor *vendor)
{
GlxClientPriv *cl;
unsigned int index;
if (vendor == NULL) {
return NULL;
}
cl = GlxGetClientData(client);
if (cl == NULL) {
return NULL;
}
// Look for a free tag index.
for (index=0; index<cl->contextTagCount; index++) {
if (cl->contextTags[index].vendor == NULL) {
break;
}
}
if (index >= cl->contextTagCount) {
// We didn't find a free entry, so grow the array.
GlxContextTagInfo *newTags;
unsigned int newSize = cl->contextTagCount * 2;
if (newSize == 0) {
// TODO: What's a good starting size for this?
newSize = 16;
}
newTags = (GlxContextTagInfo *)
realloc(cl->contextTags, newSize * sizeof(GlxContextTagInfo));
if (newTags == NULL) {
return NULL;
}
memset(&newTags[cl->contextTagCount], 0,
(newSize - cl->contextTagCount) * sizeof(GlxContextTagInfo));
index = cl->contextTagCount;
cl->contextTags = newTags;
cl->contextTagCount = newSize;
}
assert(index >= 0);
assert(index < cl->contextTagCount);
memset(&cl->contextTags[index], 0, sizeof(GlxContextTagInfo));
cl->contextTags[index].tag = (GLXContextTag) (index + 1);
cl->contextTags[index].client = client;
cl->contextTags[index].vendor = vendor;
return &cl->contextTags[index];
}
GlxContextTagInfo *GlxLookupContextTag(ClientPtr client, GLXContextTag tag)
{
GlxClientPriv *cl = GlxGetClientData(client);
if (cl == NULL) {
return NULL;
}
if (tag > 0 && (tag - 1) < cl->contextTagCount) {
if (cl->contextTags[tag - 1].vendor != NULL) {
assert(cl->contextTags[tag - 1].client == client);
return &cl->contextTags[tag - 1];
}
}
return NULL;
}
void GlxFreeContextTag(GlxContextTagInfo *tagInfo)
{
if (tagInfo != NULL) {
tagInfo->vendor = NULL;
tagInfo->vendor = NULL;
tagInfo->data = NULL;
tagInfo->context = None;
tagInfo->drawable = None;
tagInfo->readdrawable = None;
}
}
Bool GlxSetScreenVendor(ScreenPtr screen, GlxServerVendor *vendor)
{
GlxScreenPriv *priv;
if (vendor == NULL) {
return FALSE;
}
priv = GlxGetScreen(screen);
if (priv == NULL) {
return FALSE;
}
if (priv->vendor != NULL) {
return FALSE;
}
priv->vendor = vendor;
return TRUE;
}
Bool GlxSetClientScreenVendor(ClientPtr client, ScreenPtr screen, GlxServerVendor *vendor)
{
GlxClientPriv *cl;
if (screen == NULL || screen->isGPU) {
return FALSE;
}
cl = GlxGetClientData(client);
if (cl == NULL) {
return FALSE;
}
if (vendor != NULL) {
cl->vendors[screen->myNum] = vendor;
} else {
cl->vendors[screen->myNum] = GlxGetVendorForScreen(NULL, screen);
}
return TRUE;
}
GlxServerVendor *GlxGetVendorForScreen(ClientPtr client, ScreenPtr screen)
{
// Note that the client won't be sending GPU screen numbers, so we don't
// need per-client mappings for them.
if (client != NULL && !screen->isGPU) {
GlxClientPriv *cl = GlxGetClientData(client);
if (cl != NULL) {
return cl->vendors[screen->myNum];
} else {
return NULL;
}
} else {
GlxScreenPriv *priv = GlxGetScreen(screen);
if (priv != NULL) {
return priv->vendor;
} else {
return NULL;
}
}
}
|