2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
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:
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.
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
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.
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
35 #include "glxserver.h"
37 #include "singlesize.h"
39 #include "indirect_dispatch.h"
40 #include "indirect_size_get.h"
43 __glXDispSwap_ReadPixels(__GLXclientState
* cl
, GLbyte
* pc
)
45 GLsizei width
, height
;
47 GLboolean swapBytes
, lsbFirst
;
50 __GLX_DECLARE_SWAP_VARIABLES
;
52 ClientPtr client
= cl
->client
;
54 char *answer
, answerBuffer
[200];
56 __GLX_SWAP_INT(&((xGLXSingleReq
*) pc
)->contextTag
);
57 cx
= __glXForceCurrent(cl
, __GLX_GET_SINGLE_CONTEXT_TAG(pc
), &error
);
62 pc
+= __GLX_SINGLE_HDR_SIZE
;
63 __GLX_SWAP_INT(pc
+ 0);
64 __GLX_SWAP_INT(pc
+ 4);
65 __GLX_SWAP_INT(pc
+ 8);
66 __GLX_SWAP_INT(pc
+ 12);
67 __GLX_SWAP_INT(pc
+ 16);
68 __GLX_SWAP_INT(pc
+ 20);
70 width
= *(GLsizei
*) (pc
+ 8);
71 height
= *(GLsizei
*) (pc
+ 12);
72 format
= *(GLenum
*) (pc
+ 16);
73 type
= *(GLenum
*) (pc
+ 20);
74 swapBytes
= *(GLboolean
*) (pc
+ 24);
75 lsbFirst
= *(GLboolean
*) (pc
+ 25);
76 compsize
= __glReadPixels_size(format
, type
, width
, height
);
80 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
81 glPixelStorei(GL_PACK_LSB_FIRST
, lsbFirst
);
82 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
, 1);
83 __glXClearErrorOccured();
84 glReadPixels(*(GLint
*) (pc
+ 0), *(GLint
*) (pc
+ 4),
85 *(GLsizei
*) (pc
+ 8), *(GLsizei
*) (pc
+ 12),
86 *(GLenum
*) (pc
+ 16), *(GLenum
*) (pc
+ 20), answer
);
88 if (__glXErrorOccured()) {
90 __GLX_SWAP_REPLY_HEADER();
94 __GLX_BEGIN_REPLY(compsize
);
95 __GLX_SWAP_REPLY_HEADER();
97 __GLX_SEND_VOID_ARRAY(compsize
);
99 cx
->hasUnflushedCommands
= GL_FALSE
;
104 __glXDispSwap_GetTexImage(__GLXclientState
* cl
, GLbyte
* pc
)
106 GLint level
, compsize
;
107 GLenum format
, type
, target
;
110 __GLX_DECLARE_SWAP_VARIABLES
;
112 ClientPtr client
= cl
->client
;
114 char *answer
, answerBuffer
[200];
115 GLint width
= 0, height
= 0, depth
= 1;
117 __GLX_SWAP_INT(&((xGLXSingleReq
*) pc
)->contextTag
);
118 cx
= __glXForceCurrent(cl
, __GLX_GET_SINGLE_CONTEXT_TAG(pc
), &error
);
123 pc
+= __GLX_SINGLE_HDR_SIZE
;
124 __GLX_SWAP_INT(pc
+ 0);
125 __GLX_SWAP_INT(pc
+ 4);
126 __GLX_SWAP_INT(pc
+ 8);
127 __GLX_SWAP_INT(pc
+ 12);
129 level
= *(GLint
*) (pc
+ 4);
130 format
= *(GLenum
*) (pc
+ 8);
131 type
= *(GLenum
*) (pc
+ 12);
132 target
= *(GLenum
*) (pc
+ 0);
133 swapBytes
= *(GLboolean
*) (pc
+ 16);
135 glGetTexLevelParameteriv(target
, level
, GL_TEXTURE_WIDTH
, &width
);
136 glGetTexLevelParameteriv(target
, level
, GL_TEXTURE_HEIGHT
, &height
);
137 if (target
== GL_TEXTURE_3D
) {
138 glGetTexLevelParameteriv(target
, level
, GL_TEXTURE_DEPTH
, &depth
);
141 * The three queries above might fail if we're in a state where queries
142 * are illegal, but then width, height, and depth would still be zero anyway.
145 __glGetTexImage_size(target
, level
, format
, type
, width
, height
, depth
);
149 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
150 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
, 1);
151 __glXClearErrorOccured();
152 glGetTexImage(*(GLenum
*) (pc
+ 0), *(GLint
*) (pc
+ 4),
153 *(GLenum
*) (pc
+ 8), *(GLenum
*) (pc
+ 12), answer
);
155 if (__glXErrorOccured()) {
156 __GLX_BEGIN_REPLY(0);
157 __GLX_SWAP_REPLY_HEADER();
161 __GLX_BEGIN_REPLY(compsize
);
162 __GLX_SWAP_REPLY_HEADER();
163 __GLX_SWAP_INT(&width
);
164 __GLX_SWAP_INT(&height
);
165 __GLX_SWAP_INT(&depth
);
166 ((xGLXGetTexImageReply
*) &__glXReply
)->width
= width
;
167 ((xGLXGetTexImageReply
*) &__glXReply
)->height
= height
;
168 ((xGLXGetTexImageReply
*) &__glXReply
)->depth
= depth
;
170 __GLX_SEND_VOID_ARRAY(compsize
);
176 __glXDispSwap_GetPolygonStipple(__GLXclientState
* cl
, GLbyte
* pc
)
180 ClientPtr client
= cl
->client
;
182 GLubyte answerBuffer
[200];
185 __GLX_DECLARE_SWAP_VARIABLES
;
187 __GLX_SWAP_INT(&((xGLXSingleReq
*) pc
)->contextTag
);
188 cx
= __glXForceCurrent(cl
, __GLX_GET_SINGLE_CONTEXT_TAG(pc
), &error
);
192 pc
+= __GLX_SINGLE_HDR_SIZE
;
193 lsbFirst
= *(GLboolean
*) (pc
+ 0);
195 glPixelStorei(GL_PACK_LSB_FIRST
, lsbFirst
);
196 __GLX_GET_ANSWER_BUFFER(answer
, cl
, 128, 1);
198 __glXClearErrorOccured();
199 glGetPolygonStipple((GLubyte
*) answer
);
200 if (__glXErrorOccured()) {
201 __GLX_BEGIN_REPLY(0);
202 __GLX_SWAP_REPLY_HEADER();
206 __GLX_BEGIN_REPLY(128);
207 __GLX_SWAP_REPLY_HEADER();
209 __GLX_SEND_BYTE_ARRAY(128);
215 GetSeparableFilter(__GLXclientState
* cl
, GLbyte
* pc
, GLXContextTag tag
)
217 GLint compsize
, compsize2
;
218 GLenum format
, type
, target
;
221 ClientPtr client
= cl
->client
;
224 __GLX_DECLARE_SWAP_VARIABLES
;
225 char *answer
, answerBuffer
[200];
226 GLint width
= 0, height
= 0;
228 cx
= __glXForceCurrent(cl
, tag
, &error
);
233 __GLX_SWAP_INT(pc
+ 0);
234 __GLX_SWAP_INT(pc
+ 4);
235 __GLX_SWAP_INT(pc
+ 8);
237 format
= *(GLenum
*) (pc
+ 4);
238 type
= *(GLenum
*) (pc
+ 8);
239 target
= *(GLenum
*) (pc
+ 0);
240 swapBytes
= *(GLboolean
*) (pc
+ 12);
242 /* target must be SEPARABLE_2D, however I guess we can let the GL
243 barf on this one.... */
245 glGetConvolutionParameteriv(target
, GL_CONVOLUTION_WIDTH
, &width
);
246 glGetConvolutionParameteriv(target
, GL_CONVOLUTION_HEIGHT
, &height
);
248 * The two queries above might fail if we're in a state where queries
249 * are illegal, but then width and height would still be zero anyway.
251 compsize
= __glGetTexImage_size(target
, 1, format
, type
, width
, 1, 1);
252 compsize2
= __glGetTexImage_size(target
, 1, format
, type
, height
, 1, 1);
258 compsize
= __GLX_PAD(compsize
);
259 compsize2
= __GLX_PAD(compsize2
);
261 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
262 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
+ compsize2
, 1);
263 __glXClearErrorOccured();
264 glGetSeparableFilter(*(GLenum
*) (pc
+ 0), *(GLenum
*) (pc
+ 4),
265 *(GLenum
*) (pc
+ 8), answer
, answer
+ compsize
, NULL
);
267 if (__glXErrorOccured()) {
268 __GLX_BEGIN_REPLY(0);
269 __GLX_SWAP_REPLY_HEADER();
272 __GLX_BEGIN_REPLY(compsize
+ compsize2
);
273 __GLX_SWAP_REPLY_HEADER();
274 __GLX_SWAP_INT(&width
);
275 __GLX_SWAP_INT(&height
);
276 ((xGLXGetSeparableFilterReply
*) &__glXReply
)->width
= width
;
277 ((xGLXGetSeparableFilterReply
*) &__glXReply
)->height
= height
;
278 __GLX_SEND_VOID_ARRAY(compsize
+ compsize2
);
285 __glXDispSwap_GetSeparableFilter(__GLXclientState
* cl
, GLbyte
* pc
)
287 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
289 return GetSeparableFilter(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
293 __glXDispSwap_GetSeparableFilterEXT(__GLXclientState
* cl
, GLbyte
* pc
)
295 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
297 return GetSeparableFilter(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
301 GetConvolutionFilter(__GLXclientState
* cl
, GLbyte
* pc
, GLXContextTag tag
)
304 GLenum format
, type
, target
;
307 ClientPtr client
= cl
->client
;
310 __GLX_DECLARE_SWAP_VARIABLES
;
311 char *answer
, answerBuffer
[200];
312 GLint width
= 0, height
= 0;
314 cx
= __glXForceCurrent(cl
, tag
, &error
);
319 __GLX_SWAP_INT(pc
+ 0);
320 __GLX_SWAP_INT(pc
+ 4);
321 __GLX_SWAP_INT(pc
+ 8);
323 format
= *(GLenum
*) (pc
+ 4);
324 type
= *(GLenum
*) (pc
+ 8);
325 target
= *(GLenum
*) (pc
+ 0);
326 swapBytes
= *(GLboolean
*) (pc
+ 12);
328 glGetConvolutionParameteriv(target
, GL_CONVOLUTION_WIDTH
, &width
);
329 if (target
== GL_CONVOLUTION_2D
) {
333 glGetConvolutionParameteriv(target
, GL_CONVOLUTION_HEIGHT
, &height
);
336 * The two queries above might fail if we're in a state where queries
337 * are illegal, but then width and height would still be zero anyway.
339 compsize
= __glGetTexImage_size(target
, 1, format
, type
, width
, height
, 1);
343 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
344 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
, 1);
345 __glXClearErrorOccured();
346 glGetConvolutionFilter(*(GLenum
*) (pc
+ 0), *(GLenum
*) (pc
+ 4),
347 *(GLenum
*) (pc
+ 8), answer
);
349 if (__glXErrorOccured()) {
350 __GLX_BEGIN_REPLY(0);
351 __GLX_SWAP_REPLY_HEADER();
354 __GLX_BEGIN_REPLY(compsize
);
355 __GLX_SWAP_REPLY_HEADER();
356 __GLX_SWAP_INT(&width
);
357 __GLX_SWAP_INT(&height
);
358 ((xGLXGetConvolutionFilterReply
*) &__glXReply
)->width
= width
;
359 ((xGLXGetConvolutionFilterReply
*) &__glXReply
)->height
= height
;
360 __GLX_SEND_VOID_ARRAY(compsize
);
367 __glXDispSwap_GetConvolutionFilter(__GLXclientState
* cl
, GLbyte
* pc
)
369 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
371 return GetConvolutionFilter(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
375 __glXDispSwap_GetConvolutionFilterEXT(__GLXclientState
* cl
, GLbyte
* pc
)
377 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
379 return GetConvolutionFilter(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
383 GetHistogram(__GLXclientState
* cl
, GLbyte
* pc
, GLXContextTag tag
)
386 GLenum format
, type
, target
;
387 GLboolean swapBytes
, reset
;
389 ClientPtr client
= cl
->client
;
392 __GLX_DECLARE_SWAP_VARIABLES
;
393 char *answer
, answerBuffer
[200];
396 cx
= __glXForceCurrent(cl
, tag
, &error
);
401 __GLX_SWAP_INT(pc
+ 0);
402 __GLX_SWAP_INT(pc
+ 4);
403 __GLX_SWAP_INT(pc
+ 8);
405 format
= *(GLenum
*) (pc
+ 4);
406 type
= *(GLenum
*) (pc
+ 8);
407 target
= *(GLenum
*) (pc
+ 0);
408 swapBytes
= *(GLboolean
*) (pc
+ 12);
409 reset
= *(GLboolean
*) (pc
+ 13);
411 glGetHistogramParameteriv(target
, GL_HISTOGRAM_WIDTH
, &width
);
413 * The one query above might fail if we're in a state where queries
414 * are illegal, but then width would still be zero anyway.
416 compsize
= __glGetTexImage_size(target
, 1, format
, type
, width
, 1, 1);
420 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
421 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
, 1);
422 __glXClearErrorOccured();
423 glGetHistogram(target
, reset
, format
, type
, answer
);
425 if (__glXErrorOccured()) {
426 __GLX_BEGIN_REPLY(0);
427 __GLX_SWAP_REPLY_HEADER();
430 __GLX_BEGIN_REPLY(compsize
);
431 __GLX_SWAP_REPLY_HEADER();
432 __GLX_SWAP_INT(&width
);
433 ((xGLXGetHistogramReply
*) &__glXReply
)->width
= width
;
434 __GLX_SEND_VOID_ARRAY(compsize
);
441 __glXDispSwap_GetHistogram(__GLXclientState
* cl
, GLbyte
* pc
)
443 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
445 return GetHistogram(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
449 __glXDispSwap_GetHistogramEXT(__GLXclientState
* cl
, GLbyte
* pc
)
451 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
453 return GetHistogram(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
457 GetMinmax(__GLXclientState
* cl
, GLbyte
* pc
, GLXContextTag tag
)
460 GLenum format
, type
, target
;
461 GLboolean swapBytes
, reset
;
463 ClientPtr client
= cl
->client
;
466 __GLX_DECLARE_SWAP_VARIABLES
;
467 char *answer
, answerBuffer
[200];
469 cx
= __glXForceCurrent(cl
, tag
, &error
);
474 __GLX_SWAP_INT(pc
+ 0);
475 __GLX_SWAP_INT(pc
+ 4);
476 __GLX_SWAP_INT(pc
+ 8);
478 format
= *(GLenum
*) (pc
+ 4);
479 type
= *(GLenum
*) (pc
+ 8);
480 target
= *(GLenum
*) (pc
+ 0);
481 swapBytes
= *(GLboolean
*) (pc
+ 12);
482 reset
= *(GLboolean
*) (pc
+ 13);
484 compsize
= __glGetTexImage_size(target
, 1, format
, type
, 2, 1, 1);
488 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
489 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
, 1);
490 __glXClearErrorOccured();
491 glGetMinmax(target
, reset
, format
, type
, answer
);
493 if (__glXErrorOccured()) {
494 __GLX_BEGIN_REPLY(0);
495 __GLX_SWAP_REPLY_HEADER();
498 __GLX_BEGIN_REPLY(compsize
);
499 __GLX_SWAP_REPLY_HEADER();
500 __GLX_SEND_VOID_ARRAY(compsize
);
507 __glXDispSwap_GetMinmax(__GLXclientState
* cl
, GLbyte
* pc
)
509 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
511 return GetMinmax(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
515 __glXDispSwap_GetMinmaxEXT(__GLXclientState
* cl
, GLbyte
* pc
)
517 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
519 return GetMinmax(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
523 GetColorTable(__GLXclientState
* cl
, GLbyte
* pc
, GLXContextTag tag
)
526 GLenum format
, type
, target
;
529 ClientPtr client
= cl
->client
;
532 __GLX_DECLARE_SWAP_VARIABLES
;
533 char *answer
, answerBuffer
[200];
536 cx
= __glXForceCurrent(cl
, tag
, &error
);
541 __GLX_SWAP_INT(pc
+ 0);
542 __GLX_SWAP_INT(pc
+ 4);
543 __GLX_SWAP_INT(pc
+ 8);
545 format
= *(GLenum
*) (pc
+ 4);
546 type
= *(GLenum
*) (pc
+ 8);
547 target
= *(GLenum
*) (pc
+ 0);
548 swapBytes
= *(GLboolean
*) (pc
+ 12);
550 glGetColorTableParameteriv(target
, GL_COLOR_TABLE_WIDTH
, &width
);
552 * The one query above might fail if we're in a state where queries
553 * are illegal, but then width would still be zero anyway.
555 compsize
= __glGetTexImage_size(target
, 1, format
, type
, width
, 1, 1);
559 glPixelStorei(GL_PACK_SWAP_BYTES
, !swapBytes
);
560 __GLX_GET_ANSWER_BUFFER(answer
, cl
, compsize
, 1);
561 __glXClearErrorOccured();
562 glGetColorTable(*(GLenum
*) (pc
+ 0), *(GLenum
*) (pc
+ 4),
563 *(GLenum
*) (pc
+ 8), answer
);
565 if (__glXErrorOccured()) {
566 __GLX_BEGIN_REPLY(0);
567 __GLX_SWAP_REPLY_HEADER();
570 __GLX_BEGIN_REPLY(compsize
);
571 __GLX_SWAP_REPLY_HEADER();
572 __GLX_SWAP_INT(&width
);
573 ((xGLXGetColorTableReply
*) &__glXReply
)->width
= width
;
574 __GLX_SEND_VOID_ARRAY(compsize
);
581 __glXDispSwap_GetColorTable(__GLXclientState
* cl
, GLbyte
* pc
)
583 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
585 return GetColorTable(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
589 __glXDispSwap_GetColorTableSGI(__GLXclientState
* cl
, GLbyte
* pc
)
591 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
593 return GetColorTable(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);