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"
41 #include "glapitable.h"
46 int __glXDispSwap_ReadPixels(__GLXclientState *cl, GLbyte *pc)
48 GLsizei width, height;
50 GLboolean swapBytes, lsbFirst;
52 __GLX_DECLARE_SWAP_VARIABLES;
54 ClientPtr client = cl->client;
56 char *answer, answerBuffer[200];
58 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
59 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
64 pc += __GLX_SINGLE_HDR_SIZE;
68 __GLX_SWAP_INT(pc+12);
69 __GLX_SWAP_INT(pc+16);
70 __GLX_SWAP_INT(pc+20);
72 width = *(GLsizei *)(pc + 8);
73 height = *(GLsizei *)(pc + 12);
74 format = *(GLenum *)(pc + 16);
75 type = *(GLenum *)(pc + 20);
76 swapBytes = *(GLboolean *)(pc + 24);
77 lsbFirst = *(GLboolean *)(pc + 25);
78 compsize = __glReadPixels_size(format,type,width,height);
79 if (compsize < 0) compsize = 0;
81 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
82 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
83 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
84 __glXClearErrorOccured();
85 CALL_ReadPixels( GET_DISPATCH(),
89 *(GLsizei *)(pc + 12),
95 if (__glXErrorOccured()) {
97 __GLX_SWAP_REPLY_HEADER();
100 __GLX_BEGIN_REPLY(compsize);
101 __GLX_SWAP_REPLY_HEADER();
103 __GLX_SEND_VOID_ARRAY(compsize);
105 __GLX_NOTE_FLUSHED_CMDS(cx);
109 int __glXDispSwap_GetTexImage(__GLXclientState *cl, GLbyte *pc)
111 GLint level, compsize;
112 GLenum format, type, target;
114 __GLX_DECLARE_SWAP_VARIABLES;
116 ClientPtr client = cl->client;
118 char *answer, answerBuffer[200];
119 GLint width=0, height=0, depth=1;
121 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
122 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
127 pc += __GLX_SINGLE_HDR_SIZE;
128 __GLX_SWAP_INT(pc+0);
129 __GLX_SWAP_INT(pc+4);
130 __GLX_SWAP_INT(pc+8);
131 __GLX_SWAP_INT(pc+12);
133 level = *(GLint *)(pc + 4);
134 format = *(GLenum *)(pc + 8);
135 type = *(GLenum *)(pc + 12);
136 target = *(GLenum *)(pc + 0);
137 swapBytes = *(GLboolean *)(pc + 16);
139 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_WIDTH, &width) );
140 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_HEIGHT, &height) );
141 if ( target == GL_TEXTURE_3D) {
142 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_DEPTH, &depth) );
145 * The three queries above might fail if we're in a state where queries
146 * are illegal, but then width, height, and depth would still be zero anyway.
148 compsize = __glGetTexImage_size(target,level,format,type,width,height,depth);
149 if (compsize < 0) compsize = 0;
151 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
152 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
153 __glXClearErrorOccured();
154 CALL_GetTexImage( GET_DISPATCH(), (
158 *(GLenum *)(pc + 12),
162 if (__glXErrorOccured()) {
163 __GLX_BEGIN_REPLY(0);
164 __GLX_SWAP_REPLY_HEADER();
167 __GLX_BEGIN_REPLY(compsize);
168 __GLX_SWAP_REPLY_HEADER();
169 __GLX_SWAP_INT(&width);
170 __GLX_SWAP_INT(&height);
171 __GLX_SWAP_INT(&depth);
172 ((xGLXGetTexImageReply *)&__glXReply)->width = width;
173 ((xGLXGetTexImageReply *)&__glXReply)->height = height;
174 ((xGLXGetTexImageReply *)&__glXReply)->depth = depth;
176 __GLX_SEND_VOID_ARRAY(compsize);
181 int __glXDispSwap_GetPolygonStipple(__GLXclientState *cl, GLbyte *pc)
185 ClientPtr client = cl->client;
187 GLubyte answerBuffer[200];
189 __GLX_DECLARE_SWAP_VARIABLES;
191 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
192 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
196 pc += __GLX_SINGLE_HDR_SIZE;
197 lsbFirst = *(GLboolean *)(pc + 0);
199 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
200 __GLX_GET_ANSWER_BUFFER(answer,cl,128,1);
202 __glXClearErrorOccured();
203 CALL_GetPolygonStipple( GET_DISPATCH(), ((GLubyte *) answer) );
204 if (__glXErrorOccured()) {
205 __GLX_BEGIN_REPLY(0);
206 __GLX_SWAP_REPLY_HEADER();
209 __GLX_BEGIN_REPLY(128);
210 __GLX_SWAP_REPLY_HEADER();
212 __GLX_SEND_BYTE_ARRAY(128);
217 static int GetSeparableFilter(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
219 GLint compsize, compsize2;
220 GLenum format, type, target;
223 ClientPtr client = cl->client;
225 __GLX_DECLARE_SWAP_VARIABLES;
226 char *answer, answerBuffer[200];
227 GLint width=0, height=0;
229 cx = __glXForceCurrent(cl, tag, &error);
234 __GLX_SWAP_INT(pc+0);
235 __GLX_SWAP_INT(pc+4);
236 __GLX_SWAP_INT(pc+8);
238 format = *(GLenum *)(pc + 4);
239 type = *(GLenum *)(pc + 8);
240 target = *(GLenum *)(pc + 0);
241 swapBytes = *(GLboolean *)(pc + 12);
243 /* target must be SEPARABLE_2D, however I guess we can let the GL
244 barf on this one.... */
246 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width) );
247 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height) );
249 * The two queries above might fail if we're in a state where queries
250 * are illegal, but then width and height would still be zero anyway.
252 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
253 compsize2 = __glGetTexImage_size(target,1,format,type,height,1,1);
255 if (compsize < 0) compsize = 0;
256 if (compsize2 < 0) compsize2 = 0;
257 compsize = __GLX_PAD(compsize);
258 compsize2 = __GLX_PAD(compsize2);
260 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
261 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize + compsize2,1);
262 __glXClearErrorOccured();
263 CALL_GetSeparableFilter( GET_DISPATCH(), (
272 if (__glXErrorOccured()) {
273 __GLX_BEGIN_REPLY(0);
274 __GLX_SWAP_REPLY_HEADER();
276 __GLX_BEGIN_REPLY(compsize + compsize2);
277 __GLX_SWAP_REPLY_HEADER();
278 __GLX_SWAP_INT(&width);
279 __GLX_SWAP_INT(&height);
280 ((xGLXGetSeparableFilterReply *)&__glXReply)->width = width;
281 ((xGLXGetSeparableFilterReply *)&__glXReply)->height = height;
282 __GLX_SEND_VOID_ARRAY(compsize + compsize2);
288 int __glXDispSwap_GetSeparableFilter(__GLXclientState *cl, GLbyte *pc)
290 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
292 return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
295 int __glXDispSwap_GetSeparableFilterEXT(__GLXclientState *cl, GLbyte *pc)
297 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
299 return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
302 static int GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
305 GLenum format, type, target;
308 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 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width) );
329 if (target == GL_CONVOLUTION_2D) {
332 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height) );
335 * The two queries above might fail if we're in a state where queries
336 * are illegal, but then width and height would still be zero anyway.
338 compsize = __glGetTexImage_size(target,1,format,type,width,height,1);
339 if (compsize < 0) compsize = 0;
341 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
342 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
343 __glXClearErrorOccured();
344 CALL_GetConvolutionFilter( GET_DISPATCH(), (
351 if (__glXErrorOccured()) {
352 __GLX_BEGIN_REPLY(0);
353 __GLX_SWAP_REPLY_HEADER();
355 __GLX_BEGIN_REPLY(compsize);
356 __GLX_SWAP_REPLY_HEADER();
357 __GLX_SWAP_INT(&width);
358 __GLX_SWAP_INT(&height);
359 ((xGLXGetConvolutionFilterReply *)&__glXReply)->width = width;
360 ((xGLXGetConvolutionFilterReply *)&__glXReply)->height = height;
361 __GLX_SEND_VOID_ARRAY(compsize);
367 int __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);
374 int __glXDispSwap_GetConvolutionFilterEXT(__GLXclientState *cl, GLbyte *pc)
376 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
378 return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
381 static int GetHistogram(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
384 GLenum format, type, target;
385 GLboolean swapBytes, reset;
387 ClientPtr client = cl->client;
389 __GLX_DECLARE_SWAP_VARIABLES;
390 char *answer, answerBuffer[200];
393 cx = __glXForceCurrent(cl, tag, &error);
398 __GLX_SWAP_INT(pc+0);
399 __GLX_SWAP_INT(pc+4);
400 __GLX_SWAP_INT(pc+8);
402 format = *(GLenum *)(pc + 4);
403 type = *(GLenum *)(pc + 8);
404 target = *(GLenum *)(pc + 0);
405 swapBytes = *(GLboolean *)(pc + 12);
406 reset = *(GLboolean *)(pc + 13);
408 CALL_GetHistogramParameteriv( GET_DISPATCH(), (target, GL_HISTOGRAM_WIDTH, &width) );
410 * The one query above might fail if we're in a state where queries
411 * are illegal, but then width would still be zero anyway.
413 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
414 if (compsize < 0) compsize = 0;
416 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
417 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
418 __glXClearErrorOccured();
419 CALL_GetHistogram( GET_DISPATCH(), (target, reset, format, type, answer) );
421 if (__glXErrorOccured()) {
422 __GLX_BEGIN_REPLY(0);
423 __GLX_SWAP_REPLY_HEADER();
425 __GLX_BEGIN_REPLY(compsize);
426 __GLX_SWAP_REPLY_HEADER();
427 __GLX_SWAP_INT(&width);
428 ((xGLXGetHistogramReply *)&__glXReply)->width = width;
429 __GLX_SEND_VOID_ARRAY(compsize);
435 int __glXDispSwap_GetHistogram(__GLXclientState *cl, GLbyte *pc)
437 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
439 return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
442 int __glXDispSwap_GetHistogramEXT(__GLXclientState *cl, GLbyte *pc)
444 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
446 return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
449 static int GetMinmax(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
452 GLenum format, type, target;
453 GLboolean swapBytes, reset;
455 ClientPtr client = cl->client;
457 __GLX_DECLARE_SWAP_VARIABLES;
458 char *answer, answerBuffer[200];
460 cx = __glXForceCurrent(cl, tag, &error);
465 __GLX_SWAP_INT(pc+0);
466 __GLX_SWAP_INT(pc+4);
467 __GLX_SWAP_INT(pc+8);
469 format = *(GLenum *)(pc + 4);
470 type = *(GLenum *)(pc + 8);
471 target = *(GLenum *)(pc + 0);
472 swapBytes = *(GLboolean *)(pc + 12);
473 reset = *(GLboolean *)(pc + 13);
475 compsize = __glGetTexImage_size(target,1,format,type,2,1,1);
476 if (compsize < 0) compsize = 0;
478 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
479 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
480 __glXClearErrorOccured();
481 CALL_GetMinmax( GET_DISPATCH(), (target, reset, format, type, answer) );
483 if (__glXErrorOccured()) {
484 __GLX_BEGIN_REPLY(0);
485 __GLX_SWAP_REPLY_HEADER();
487 __GLX_BEGIN_REPLY(compsize);
488 __GLX_SWAP_REPLY_HEADER();
489 __GLX_SEND_VOID_ARRAY(compsize);
495 int __glXDispSwap_GetMinmax(__GLXclientState *cl, GLbyte *pc)
497 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
499 return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
502 int __glXDispSwap_GetMinmaxEXT(__GLXclientState *cl, GLbyte *pc)
504 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
506 return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
509 static int GetColorTable(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
512 GLenum format, type, target;
515 ClientPtr client = cl->client;
517 __GLX_DECLARE_SWAP_VARIABLES;
518 char *answer, answerBuffer[200];
521 cx = __glXForceCurrent(cl, tag, &error);
526 __GLX_SWAP_INT(pc+0);
527 __GLX_SWAP_INT(pc+4);
528 __GLX_SWAP_INT(pc+8);
530 format = *(GLenum *)(pc + 4);
531 type = *(GLenum *)(pc + 8);
532 target = *(GLenum *)(pc + 0);
533 swapBytes = *(GLboolean *)(pc + 12);
535 CALL_GetColorTableParameteriv( GET_DISPATCH(), (target, GL_COLOR_TABLE_WIDTH, &width) );
537 * The one query above might fail if we're in a state where queries
538 * are illegal, but then width would still be zero anyway.
540 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
541 if (compsize < 0) compsize = 0;
543 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
544 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
545 __glXClearErrorOccured();
546 CALL_GetColorTable( GET_DISPATCH(), (
553 if (__glXErrorOccured()) {
554 __GLX_BEGIN_REPLY(0);
555 __GLX_SWAP_REPLY_HEADER();
557 __GLX_BEGIN_REPLY(compsize);
558 __GLX_SWAP_REPLY_HEADER();
559 __GLX_SWAP_INT(&width);
560 ((xGLXGetColorTableReply *)&__glXReply)->width = width;
561 __GLX_SEND_VOID_ARRAY(compsize);
567 int __glXDispSwap_GetColorTable(__GLXclientState *cl, GLbyte *pc)
569 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
571 return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
574 int __glXDispSwap_GetColorTableSGI(__GLXclientState *cl, GLbyte *pc)
576 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
578 return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);