1 /*
2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
29 */
30
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
33 #endif
34
35 #include "glxserver.h"
36 #include "glxext.h"
37 #include "singlesize.h"
38 #include "unpack.h"
39 #include "indirect_dispatch.h"
40 #include "indirect_size_get.h"
41
42 int
__glXDispSwap_ReadPixels(__GLXclientState * cl,GLbyte * pc)43 __glXDispSwap_ReadPixels(__GLXclientState * cl, GLbyte * pc)
44 {
45 GLsizei width, height;
46 GLenum format, type;
47 GLboolean swapBytes, lsbFirst;
48 GLint compsize;
49
50 __GLX_DECLARE_SWAP_VARIABLES;
51 __GLXcontext *cx;
52 ClientPtr client = cl->client;
53 int error;
54 char *answer, answerBuffer[200];
55 xGLXSingleReply reply = { 0, };
56
57 REQUEST_FIXED_SIZE(xGLXSingleReq, 28);
58
59 __GLX_SWAP_INT(&((xGLXSingleReq *) pc)->contextTag);
60 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
61 if (!cx) {
62 return error;
63 }
64
65 pc += __GLX_SINGLE_HDR_SIZE;
66 __GLX_SWAP_INT(pc + 0);
67 __GLX_SWAP_INT(pc + 4);
68 __GLX_SWAP_INT(pc + 8);
69 __GLX_SWAP_INT(pc + 12);
70 __GLX_SWAP_INT(pc + 16);
71 __GLX_SWAP_INT(pc + 20);
72
73 width = *(GLsizei *) (pc + 8);
74 height = *(GLsizei *) (pc + 12);
75 format = *(GLenum *) (pc + 16);
76 type = *(GLenum *) (pc + 20);
77 swapBytes = *(GLboolean *) (pc + 24);
78 lsbFirst = *(GLboolean *) (pc + 25);
79 compsize = __glReadPixels_size(format, type, width, height);
80 if (compsize < 0)
81 return BadLength;
82
83 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
84 glPixelStorei(GL_PACK_LSB_FIRST, lsbFirst);
85 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
86 __glXClearErrorOccured();
87 glReadPixels(*(GLint *) (pc + 0), *(GLint *) (pc + 4),
88 *(GLsizei *) (pc + 8), *(GLsizei *) (pc + 12),
89 *(GLenum *) (pc + 16), *(GLenum *) (pc + 20), answer);
90
91 if (__glXErrorOccured()) {
92 __GLX_BEGIN_REPLY(0);
93 __GLX_SWAP_REPLY_HEADER();
94 __GLX_SEND_HEADER();
95 }
96 else {
97 __GLX_BEGIN_REPLY(compsize);
98 __GLX_SWAP_REPLY_HEADER();
99 __GLX_SEND_HEADER();
100 __GLX_SEND_VOID_ARRAY(compsize);
101 }
102 return Success;
103 }
104
105 int
__glXDispSwap_GetTexImage(__GLXclientState * cl,GLbyte * pc)106 __glXDispSwap_GetTexImage(__GLXclientState * cl, GLbyte * pc)
107 {
108 GLint level, compsize;
109 GLenum format, type, target;
110 GLboolean swapBytes;
111
112 __GLX_DECLARE_SWAP_VARIABLES;
113 __GLXcontext *cx;
114 ClientPtr client = cl->client;
115 int error;
116 char *answer, answerBuffer[200];
117 GLint width = 0, height = 0, depth = 1;
118 xGLXSingleReply reply = { 0, };
119
120 REQUEST_FIXED_SIZE(xGLXSingleReq, 20);
121
122 __GLX_SWAP_INT(&((xGLXSingleReq *) pc)->contextTag);
123 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
124 if (!cx) {
125 return error;
126 }
127
128 pc += __GLX_SINGLE_HDR_SIZE;
129 __GLX_SWAP_INT(pc + 0);
130 __GLX_SWAP_INT(pc + 4);
131 __GLX_SWAP_INT(pc + 8);
132 __GLX_SWAP_INT(pc + 12);
133
134 level = *(GLint *) (pc + 4);
135 format = *(GLenum *) (pc + 8);
136 type = *(GLenum *) (pc + 12);
137 target = *(GLenum *) (pc + 0);
138 swapBytes = *(GLboolean *) (pc + 16);
139
140 glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
141 glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
142 if (target == GL_TEXTURE_3D) {
143 glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, &depth);
144 }
145 /*
146 * The three queries above might fail if we're in a state where queries
147 * are illegal, but then width, height, and depth would still be zero anyway.
148 */
149 compsize =
150 __glGetTexImage_size(target, level, format, type, width, height, depth);
151 if (compsize < 0)
152 return BadLength;
153
154 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
155 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
156 __glXClearErrorOccured();
157 glGetTexImage(*(GLenum *) (pc + 0), *(GLint *) (pc + 4),
158 *(GLenum *) (pc + 8), *(GLenum *) (pc + 12), answer);
159
160 if (__glXErrorOccured()) {
161 __GLX_BEGIN_REPLY(0);
162 __GLX_SWAP_REPLY_HEADER();
163 __GLX_SEND_HEADER();
164 }
165 else {
166 __GLX_BEGIN_REPLY(compsize);
167 __GLX_SWAP_REPLY_HEADER();
168 __GLX_SWAP_INT(&width);
169 __GLX_SWAP_INT(&height);
170 __GLX_SWAP_INT(&depth);
171 ((xGLXGetTexImageReply *) &reply)->width = width;
172 ((xGLXGetTexImageReply *) &reply)->height = height;
173 ((xGLXGetTexImageReply *) &reply)->depth = depth;
174 __GLX_SEND_HEADER();
175 __GLX_SEND_VOID_ARRAY(compsize);
176 }
177 return Success;
178 }
179
180 int
__glXDispSwap_GetPolygonStipple(__GLXclientState * cl,GLbyte * pc)181 __glXDispSwap_GetPolygonStipple(__GLXclientState * cl, GLbyte * pc)
182 {
183 GLboolean lsbFirst;
184 __GLXcontext *cx;
185 ClientPtr client = cl->client;
186 int error;
187 GLubyte answerBuffer[200];
188 char *answer;
189 xGLXSingleReply reply = { 0, };
190
191 __GLX_DECLARE_SWAP_VARIABLES;
192
193 REQUEST_FIXED_SIZE(xGLXSingleReq, 4);
194
195 __GLX_SWAP_INT(&((xGLXSingleReq *) pc)->contextTag);
196 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
197 if (!cx) {
198 return error;
199 }
200 pc += __GLX_SINGLE_HDR_SIZE;
201 lsbFirst = *(GLboolean *) (pc + 0);
202
203 glPixelStorei(GL_PACK_LSB_FIRST, lsbFirst);
204 __GLX_GET_ANSWER_BUFFER(answer, cl, 128, 1);
205
206 __glXClearErrorOccured();
207 glGetPolygonStipple((GLubyte *) answer);
208 if (__glXErrorOccured()) {
209 __GLX_BEGIN_REPLY(0);
210 __GLX_SWAP_REPLY_HEADER();
211 __GLX_SEND_HEADER();
212 }
213 else {
214 __GLX_BEGIN_REPLY(128);
215 __GLX_SWAP_REPLY_HEADER();
216 __GLX_SEND_HEADER();
217 __GLX_SEND_BYTE_ARRAY(128);
218 }
219 return Success;
220 }
221
222 static int
GetSeparableFilter(__GLXclientState * cl,GLbyte * pc,GLXContextTag tag)223 GetSeparableFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
224 {
225 GLint compsize, compsize2;
226 GLenum format, type, target;
227 GLboolean swapBytes;
228 __GLXcontext *cx;
229 ClientPtr client = cl->client;
230 int error;
231
232 __GLX_DECLARE_SWAP_VARIABLES;
233 char *answer, answerBuffer[200];
234 GLint width = 0, height = 0;
235 xGLXSingleReply reply = { 0, };
236
237 cx = __glXForceCurrent(cl, tag, &error);
238 if (!cx) {
239 return error;
240 }
241
242 __GLX_SWAP_INT(pc + 0);
243 __GLX_SWAP_INT(pc + 4);
244 __GLX_SWAP_INT(pc + 8);
245
246 format = *(GLenum *) (pc + 4);
247 type = *(GLenum *) (pc + 8);
248 target = *(GLenum *) (pc + 0);
249 swapBytes = *(GLboolean *) (pc + 12);
250
251 /* target must be SEPARABLE_2D, however I guess we can let the GL
252 barf on this one.... */
253
254 glGetConvolutionParameteriv(target, GL_CONVOLUTION_WIDTH, &width);
255 glGetConvolutionParameteriv(target, GL_CONVOLUTION_HEIGHT, &height);
256 /*
257 * The two queries above might fail if we're in a state where queries
258 * are illegal, but then width and height would still be zero anyway.
259 */
260 compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
261 compsize2 = __glGetTexImage_size(target, 1, format, type, height, 1, 1);
262
263 if ((compsize = safe_pad(compsize)) < 0)
264 return BadLength;
265 if ((compsize2 = safe_pad(compsize2)) < 0)
266 return BadLength;
267
268 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
269 __GLX_GET_ANSWER_BUFFER(answer, cl, safe_add(compsize, compsize2), 1);
270 __glXClearErrorOccured();
271 glGetSeparableFilter(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
272 *(GLenum *) (pc + 8), answer, answer + compsize, NULL);
273
274 if (__glXErrorOccured()) {
275 __GLX_BEGIN_REPLY(0);
276 __GLX_SWAP_REPLY_HEADER();
277 }
278 else {
279 __GLX_BEGIN_REPLY(compsize + compsize2);
280 __GLX_SWAP_REPLY_HEADER();
281 __GLX_SWAP_INT(&width);
282 __GLX_SWAP_INT(&height);
283 ((xGLXGetSeparableFilterReply *) &reply)->width = width;
284 ((xGLXGetSeparableFilterReply *) &reply)->height = height;
285 __GLX_SEND_VOID_ARRAY(compsize + compsize2);
286 }
287
288 return Success;
289 }
290
291 int
__glXDispSwap_GetSeparableFilter(__GLXclientState * cl,GLbyte * pc)292 __glXDispSwap_GetSeparableFilter(__GLXclientState * cl, GLbyte * pc)
293 {
294 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
295 ClientPtr client = cl->client;
296
297 REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
298 return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
299 }
300
301 int
__glXDispSwap_GetSeparableFilterEXT(__GLXclientState * cl,GLbyte * pc)302 __glXDispSwap_GetSeparableFilterEXT(__GLXclientState * cl, GLbyte * pc)
303 {
304 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
305 ClientPtr client = cl->client;
306
307 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
308 return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
309 }
310
311 static int
GetConvolutionFilter(__GLXclientState * cl,GLbyte * pc,GLXContextTag tag)312 GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
313 {
314 GLint compsize;
315 GLenum format, type, target;
316 GLboolean swapBytes;
317 __GLXcontext *cx;
318 ClientPtr client = cl->client;
319 int error;
320
321 __GLX_DECLARE_SWAP_VARIABLES;
322 char *answer, answerBuffer[200];
323 GLint width = 0, height = 0;
324 xGLXSingleReply reply = { 0, };
325
326 cx = __glXForceCurrent(cl, tag, &error);
327 if (!cx) {
328 return error;
329 }
330
331 __GLX_SWAP_INT(pc + 0);
332 __GLX_SWAP_INT(pc + 4);
333 __GLX_SWAP_INT(pc + 8);
334
335 format = *(GLenum *) (pc + 4);
336 type = *(GLenum *) (pc + 8);
337 target = *(GLenum *) (pc + 0);
338 swapBytes = *(GLboolean *) (pc + 12);
339
340 glGetConvolutionParameteriv(target, GL_CONVOLUTION_WIDTH, &width);
341 if (target == GL_CONVOLUTION_2D) {
342 height = 1;
343 }
344 else {
345 glGetConvolutionParameteriv(target, GL_CONVOLUTION_HEIGHT, &height);
346 }
347 /*
348 * The two queries above might fail if we're in a state where queries
349 * are illegal, but then width and height would still be zero anyway.
350 */
351 compsize = __glGetTexImage_size(target, 1, format, type, width, height, 1);
352 if (compsize < 0)
353 return BadLength;
354
355 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
356 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
357 __glXClearErrorOccured();
358 glGetConvolutionFilter(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
359 *(GLenum *) (pc + 8), answer);
360
361 if (__glXErrorOccured()) {
362 __GLX_BEGIN_REPLY(0);
363 __GLX_SWAP_REPLY_HEADER();
364 }
365 else {
366 __GLX_BEGIN_REPLY(compsize);
367 __GLX_SWAP_REPLY_HEADER();
368 __GLX_SWAP_INT(&width);
369 __GLX_SWAP_INT(&height);
370 ((xGLXGetConvolutionFilterReply *) &reply)->width = width;
371 ((xGLXGetConvolutionFilterReply *) &reply)->height = height;
372 __GLX_SEND_VOID_ARRAY(compsize);
373 }
374
375 return Success;
376 }
377
378 int
__glXDispSwap_GetConvolutionFilter(__GLXclientState * cl,GLbyte * pc)379 __glXDispSwap_GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc)
380 {
381 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
382 ClientPtr client = cl->client;
383
384 REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
385 return GetConvolutionFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
386 }
387
388 int
__glXDispSwap_GetConvolutionFilterEXT(__GLXclientState * cl,GLbyte * pc)389 __glXDispSwap_GetConvolutionFilterEXT(__GLXclientState * cl, GLbyte * pc)
390 {
391 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
392 ClientPtr client = cl->client;
393
394 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
395 return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
396 }
397
398 static int
GetHistogram(__GLXclientState * cl,GLbyte * pc,GLXContextTag tag)399 GetHistogram(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
400 {
401 GLint compsize;
402 GLenum format, type, target;
403 GLboolean swapBytes, reset;
404 __GLXcontext *cx;
405 ClientPtr client = cl->client;
406 int error;
407
408 __GLX_DECLARE_SWAP_VARIABLES;
409 char *answer, answerBuffer[200];
410 GLint width = 0;
411 xGLXSingleReply reply = { 0, };
412
413 cx = __glXForceCurrent(cl, tag, &error);
414 if (!cx) {
415 return error;
416 }
417
418 __GLX_SWAP_INT(pc + 0);
419 __GLX_SWAP_INT(pc + 4);
420 __GLX_SWAP_INT(pc + 8);
421
422 format = *(GLenum *) (pc + 4);
423 type = *(GLenum *) (pc + 8);
424 target = *(GLenum *) (pc + 0);
425 swapBytes = *(GLboolean *) (pc + 12);
426 reset = *(GLboolean *) (pc + 13);
427
428 glGetHistogramParameteriv(target, GL_HISTOGRAM_WIDTH, &width);
429 /*
430 * The one query above might fail if we're in a state where queries
431 * are illegal, but then width would still be zero anyway.
432 */
433 compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
434 if (compsize < 0)
435 return BadLength;
436
437 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
438 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
439 __glXClearErrorOccured();
440 glGetHistogram(target, reset, format, type, answer);
441
442 if (__glXErrorOccured()) {
443 __GLX_BEGIN_REPLY(0);
444 __GLX_SWAP_REPLY_HEADER();
445 }
446 else {
447 __GLX_BEGIN_REPLY(compsize);
448 __GLX_SWAP_REPLY_HEADER();
449 __GLX_SWAP_INT(&width);
450 ((xGLXGetHistogramReply *) &reply)->width = width;
451 __GLX_SEND_VOID_ARRAY(compsize);
452 }
453
454 return Success;
455 }
456
457 int
__glXDispSwap_GetHistogram(__GLXclientState * cl,GLbyte * pc)458 __glXDispSwap_GetHistogram(__GLXclientState * cl, GLbyte * pc)
459 {
460 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
461 ClientPtr client = cl->client;
462
463 REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
464 return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
465 }
466
467 int
__glXDispSwap_GetHistogramEXT(__GLXclientState * cl,GLbyte * pc)468 __glXDispSwap_GetHistogramEXT(__GLXclientState * cl, GLbyte * pc)
469 {
470 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
471 ClientPtr client = cl->client;
472
473 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
474 return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
475 }
476
477 static int
GetMinmax(__GLXclientState * cl,GLbyte * pc,GLXContextTag tag)478 GetMinmax(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
479 {
480 GLint compsize;
481 GLenum format, type, target;
482 GLboolean swapBytes, reset;
483 __GLXcontext *cx;
484 ClientPtr client = cl->client;
485 int error;
486
487 __GLX_DECLARE_SWAP_VARIABLES;
488 char *answer, answerBuffer[200];
489 xGLXSingleReply reply = { 0, };
490
491 cx = __glXForceCurrent(cl, tag, &error);
492 if (!cx) {
493 return error;
494 }
495
496 __GLX_SWAP_INT(pc + 0);
497 __GLX_SWAP_INT(pc + 4);
498 __GLX_SWAP_INT(pc + 8);
499
500 format = *(GLenum *) (pc + 4);
501 type = *(GLenum *) (pc + 8);
502 target = *(GLenum *) (pc + 0);
503 swapBytes = *(GLboolean *) (pc + 12);
504 reset = *(GLboolean *) (pc + 13);
505
506 compsize = __glGetTexImage_size(target, 1, format, type, 2, 1, 1);
507 if (compsize < 0)
508 return BadLength;
509
510 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
511 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
512 __glXClearErrorOccured();
513 glGetMinmax(target, reset, format, type, answer);
514
515 if (__glXErrorOccured()) {
516 __GLX_BEGIN_REPLY(0);
517 __GLX_SWAP_REPLY_HEADER();
518 }
519 else {
520 __GLX_BEGIN_REPLY(compsize);
521 __GLX_SWAP_REPLY_HEADER();
522 __GLX_SEND_VOID_ARRAY(compsize);
523 }
524
525 return Success;
526 }
527
528 int
__glXDispSwap_GetMinmax(__GLXclientState * cl,GLbyte * pc)529 __glXDispSwap_GetMinmax(__GLXclientState * cl, GLbyte * pc)
530 {
531 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
532 ClientPtr client = cl->client;
533
534 REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
535 return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
536 }
537
538 int
__glXDispSwap_GetMinmaxEXT(__GLXclientState * cl,GLbyte * pc)539 __glXDispSwap_GetMinmaxEXT(__GLXclientState * cl, GLbyte * pc)
540 {
541 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
542 ClientPtr client = cl->client;
543
544 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
545 return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
546 }
547
548 static int
GetColorTable(__GLXclientState * cl,GLbyte * pc,GLXContextTag tag)549 GetColorTable(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
550 {
551 GLint compsize;
552 GLenum format, type, target;
553 GLboolean swapBytes;
554 __GLXcontext *cx;
555 ClientPtr client = cl->client;
556 int error;
557
558 __GLX_DECLARE_SWAP_VARIABLES;
559 char *answer, answerBuffer[200];
560 GLint width = 0;
561 xGLXSingleReply reply = { 0, };
562
563 cx = __glXForceCurrent(cl, tag, &error);
564 if (!cx) {
565 return error;
566 }
567
568 __GLX_SWAP_INT(pc + 0);
569 __GLX_SWAP_INT(pc + 4);
570 __GLX_SWAP_INT(pc + 8);
571
572 format = *(GLenum *) (pc + 4);
573 type = *(GLenum *) (pc + 8);
574 target = *(GLenum *) (pc + 0);
575 swapBytes = *(GLboolean *) (pc + 12);
576
577 glGetColorTableParameteriv(target, GL_COLOR_TABLE_WIDTH, &width);
578 /*
579 * The one query above might fail if we're in a state where queries
580 * are illegal, but then width would still be zero anyway.
581 */
582 compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
583 if (compsize < 0)
584 return BadLength;
585
586 glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes);
587 __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
588 __glXClearErrorOccured();
589 glGetColorTable(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
590 *(GLenum *) (pc + 8), answer);
591
592 if (__glXErrorOccured()) {
593 __GLX_BEGIN_REPLY(0);
594 __GLX_SWAP_REPLY_HEADER();
595 }
596 else {
597 __GLX_BEGIN_REPLY(compsize);
598 __GLX_SWAP_REPLY_HEADER();
599 __GLX_SWAP_INT(&width);
600 ((xGLXGetColorTableReply *) &reply)->width = width;
601 __GLX_SEND_VOID_ARRAY(compsize);
602 }
603
604 return Success;
605 }
606
607 int
__glXDispSwap_GetColorTable(__GLXclientState * cl,GLbyte * pc)608 __glXDispSwap_GetColorTable(__GLXclientState * cl, GLbyte * pc)
609 {
610 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
611 ClientPtr client = cl->client;
612
613 REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
614 return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
615 }
616
617 int
__glXDispSwap_GetColorTableSGI(__GLXclientState * cl,GLbyte * pc)618 __glXDispSwap_GetColorTableSGI(__GLXclientState * cl, GLbyte * pc)
619 {
620 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
621 ClientPtr client = cl->client;
622
623 REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
624 return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
625 }
626