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_size_get.h"
40 #include "indirect_dispatch.h"
41 #include "glapitable.h"
46 int __glXDisp_ReadPixels(__GLXclientState *cl, GLbyte *pc)
48 GLsizei width, height;
50 GLboolean swapBytes, lsbFirst;
53 ClientPtr client = cl->client;
55 char *answer, answerBuffer[200];
57 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
62 pc += __GLX_SINGLE_HDR_SIZE;
63 width = *(GLsizei *)(pc + 8);
64 height = *(GLsizei *)(pc + 12);
65 format = *(GLenum *)(pc + 16);
66 type = *(GLenum *)(pc + 20);
67 swapBytes = *(GLboolean *)(pc + 24);
68 lsbFirst = *(GLboolean *)(pc + 25);
69 compsize = __glReadPixels_size(format,type,width,height);
70 if (compsize < 0) compsize = 0;
72 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes) );
73 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
74 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
75 __glXClearErrorOccured();
76 CALL_ReadPixels( GET_DISPATCH(), (
80 *(GLsizei *)(pc + 12),
86 if (__glXErrorOccured()) {
90 __GLX_BEGIN_REPLY(compsize);
92 __GLX_SEND_VOID_ARRAY(compsize);
94 __GLX_NOTE_FLUSHED_CMDS(cx);
98 int __glXDisp_GetTexImage(__GLXclientState *cl, GLbyte *pc)
100 GLint level, compsize;
101 GLenum format, type, target;
104 ClientPtr client = cl->client;
106 char *answer, answerBuffer[200];
107 GLint width=0, height=0, depth=1;
109 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
114 pc += __GLX_SINGLE_HDR_SIZE;
115 level = *(GLint *)(pc + 4);
116 format = *(GLenum *)(pc + 8);
117 type = *(GLenum *)(pc + 12);
118 target = *(GLenum *)(pc + 0);
119 swapBytes = *(GLboolean *)(pc + 16);
121 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_WIDTH, &width) );
122 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_HEIGHT, &height) );
123 if ( target == GL_TEXTURE_3D) {
124 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_DEPTH, &depth) );
127 * The three queries above might fail if we're in a state where queries
128 * are illegal, but then width, height, and depth would still be zero anyway.
130 compsize = __glGetTexImage_size(target,level,format,type,width,height,depth);
131 if (compsize < 0) compsize = 0;
133 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes) );
134 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
135 __glXClearErrorOccured();
136 CALL_GetTexImage( GET_DISPATCH(), (
140 *(GLenum *)(pc + 12),
144 if (__glXErrorOccured()) {
145 __GLX_BEGIN_REPLY(0);
148 __GLX_BEGIN_REPLY(compsize);
149 ((xGLXGetTexImageReply *)&__glXReply)->width = width;
150 ((xGLXGetTexImageReply *)&__glXReply)->height = height;
151 ((xGLXGetTexImageReply *)&__glXReply)->depth = depth;
153 __GLX_SEND_VOID_ARRAY(compsize);
158 int __glXDisp_GetPolygonStipple(__GLXclientState *cl, GLbyte *pc)
162 ClientPtr client = cl->client;
164 GLubyte answerBuffer[200];
167 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
172 pc += __GLX_SINGLE_HDR_SIZE;
173 lsbFirst = *(GLboolean *)(pc + 0);
175 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
176 __GLX_GET_ANSWER_BUFFER(answer,cl,128,1);
178 __glXClearErrorOccured();
179 CALL_GetPolygonStipple( GET_DISPATCH(), ((GLubyte *) answer) );
181 if (__glXErrorOccured()) {
182 __GLX_BEGIN_REPLY(0);
185 __GLX_BEGIN_REPLY(128);
187 __GLX_SEND_BYTE_ARRAY(128);
192 static int GetSeparableFilter(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
194 GLint compsize, compsize2;
195 GLenum format, type, target;
198 ClientPtr client = cl->client;
200 char *answer, answerBuffer[200];
201 GLint width=0, height=0;
203 cx = __glXForceCurrent(cl, tag, &error);
208 format = *(GLenum *)(pc + 4);
209 type = *(GLenum *)(pc + 8);
210 target = *(GLenum *)(pc + 0);
211 swapBytes = *(GLboolean *)(pc + 12);
213 /* target must be SEPARABLE_2D, however I guess we can let the GL
214 barf on this one.... */
216 CALL_GetConvolutionParameteriv(GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width));
217 CALL_GetConvolutionParameteriv(GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height));
219 * The two queries above might fail if we're in a state where queries
220 * are illegal, but then width and height would still be zero anyway.
222 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
223 compsize2 = __glGetTexImage_size(target,1,format,type,height,1,1);
225 if (compsize < 0) compsize = 0;
226 if (compsize2 < 0) compsize2 = 0;
227 compsize = __GLX_PAD(compsize);
228 compsize2 = __GLX_PAD(compsize2);
230 CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes));
231 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize + compsize2,1);
232 __glXClearErrorOccured();
233 CALL_GetSeparableFilter( GET_DISPATCH(), (
242 if (__glXErrorOccured()) {
243 __GLX_BEGIN_REPLY(0);
246 __GLX_BEGIN_REPLY(compsize + compsize2);
247 ((xGLXGetSeparableFilterReply *)&__glXReply)->width = width;
248 ((xGLXGetSeparableFilterReply *)&__glXReply)->height = height;
250 __GLX_SEND_VOID_ARRAY(compsize + compsize2);
256 int __glXDisp_GetSeparableFilter(__GLXclientState *cl, GLbyte *pc)
258 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
260 return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
263 int __glXDisp_GetSeparableFilterEXT(__GLXclientState *cl, GLbyte *pc)
265 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
267 return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
270 static int GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc,
274 GLenum format, type, target;
277 ClientPtr client = cl->client;
279 char *answer, answerBuffer[200];
280 GLint width=0, height=0;
282 cx = __glXForceCurrent(cl, tag, &error);
287 format = *(GLenum *)(pc + 4);
288 type = *(GLenum *)(pc + 8);
289 target = *(GLenum *)(pc + 0);
290 swapBytes = *(GLboolean *)(pc + 12);
292 CALL_GetConvolutionParameteriv(GET_DISPATCH(),
293 (target, GL_CONVOLUTION_WIDTH, &width));
294 if (target == GL_CONVOLUTION_1D) {
297 CALL_GetConvolutionParameteriv(GET_DISPATCH(),
298 (target, GL_CONVOLUTION_HEIGHT, &height));
301 * The two queries above might fail if we're in a state where queries
302 * are illegal, but then width and height would still be zero anyway.
304 compsize = __glGetTexImage_size(target,1,format,type,width,height,1);
305 if (compsize < 0) compsize = 0;
307 CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes));
308 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
309 __glXClearErrorOccured();
310 CALL_GetConvolutionFilter( GET_DISPATCH(), (
317 if (__glXErrorOccured()) {
318 __GLX_BEGIN_REPLY(0);
321 __GLX_BEGIN_REPLY(compsize);
322 ((xGLXGetConvolutionFilterReply *)&__glXReply)->width = width;
323 ((xGLXGetConvolutionFilterReply *)&__glXReply)->height = height;
325 __GLX_SEND_VOID_ARRAY(compsize);
331 int __glXDisp_GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc)
333 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
335 return GetConvolutionFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
338 int __glXDisp_GetConvolutionFilterEXT(__GLXclientState *cl, GLbyte *pc)
340 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
342 return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
345 static int GetHistogram(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
348 GLenum format, type, target;
349 GLboolean swapBytes, reset;
351 ClientPtr client = cl->client;
353 char *answer, answerBuffer[200];
356 cx = __glXForceCurrent(cl, tag, &error);
361 format = *(GLenum *)(pc + 4);
362 type = *(GLenum *)(pc + 8);
363 target = *(GLenum *)(pc + 0);
364 swapBytes = *(GLboolean *)(pc + 12);
365 reset = *(GLboolean *)(pc + 13);
367 CALL_GetHistogramParameteriv(GET_DISPATCH(),
368 (target, GL_HISTOGRAM_WIDTH, &width));
370 * The one query above might fail if we're in a state where queries
371 * are illegal, but then width would still be zero anyway.
373 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
374 if (compsize < 0) compsize = 0;
376 CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes));
377 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
378 __glXClearErrorOccured();
379 CALL_GetHistogram(GET_DISPATCH(), (target, reset, format, type, answer));
381 if (__glXErrorOccured()) {
382 __GLX_BEGIN_REPLY(0);
385 __GLX_BEGIN_REPLY(compsize);
386 ((xGLXGetHistogramReply *)&__glXReply)->width = width;
388 __GLX_SEND_VOID_ARRAY(compsize);
394 int __glXDisp_GetHistogram(__GLXclientState *cl, GLbyte *pc)
396 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
398 return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
401 int __glXDisp_GetHistogramEXT(__GLXclientState *cl, GLbyte *pc)
403 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
405 return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
408 static int GetMinmax(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
411 GLenum format, type, target;
412 GLboolean swapBytes, reset;
414 ClientPtr client = cl->client;
416 char *answer, answerBuffer[200];
418 cx = __glXForceCurrent(cl, tag, &error);
423 format = *(GLenum *)(pc + 4);
424 type = *(GLenum *)(pc + 8);
425 target = *(GLenum *)(pc + 0);
426 swapBytes = *(GLboolean *)(pc + 12);
427 reset = *(GLboolean *)(pc + 13);
429 compsize = __glGetTexImage_size(target,1,format,type,2,1,1);
430 if (compsize < 0) compsize = 0;
432 CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes));
433 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
434 __glXClearErrorOccured();
435 CALL_GetMinmax(GET_DISPATCH(), (target, reset, format, type, answer));
437 if (__glXErrorOccured()) {
438 __GLX_BEGIN_REPLY(0);
441 __GLX_BEGIN_REPLY(compsize);
443 __GLX_SEND_VOID_ARRAY(compsize);
449 int __glXDisp_GetMinmax(__GLXclientState *cl, GLbyte *pc)
451 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
453 return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
456 int __glXDisp_GetMinmaxEXT(__GLXclientState *cl, GLbyte *pc)
458 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
460 return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
463 static int GetColorTable(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
466 GLenum format, type, target;
469 ClientPtr client = cl->client;
471 char *answer, answerBuffer[200];
474 cx = __glXForceCurrent(cl, tag, &error);
479 target = *(GLenum *)(pc + 0);
480 format = *(GLenum *)(pc + 4);
481 type = *(GLenum *)(pc + 8);
482 swapBytes = *(GLboolean *)(pc + 12);
484 CALL_GetColorTableParameteriv(GET_DISPATCH(),
485 (target, GL_COLOR_TABLE_WIDTH, &width));
487 * The one query above might fail if we're in a state where queries
488 * are illegal, but then width would still be zero anyway.
490 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
491 if (compsize < 0) compsize = 0;
493 CALL_PixelStorei(GET_DISPATCH(), (GL_PACK_SWAP_BYTES, swapBytes));
494 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
495 __glXClearErrorOccured();
496 CALL_GetColorTable( GET_DISPATCH(), (
503 if (__glXErrorOccured()) {
504 __GLX_BEGIN_REPLY(0);
507 __GLX_BEGIN_REPLY(compsize);
508 ((xGLXGetColorTableReply *)&__glXReply)->width = width;
510 __GLX_SEND_VOID_ARRAY(compsize);
516 int __glXDisp_GetColorTable(__GLXclientState *cl, GLbyte *pc)
518 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
520 return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
523 int __glXDisp_GetColorTableSGI(__GLXclientState *cl, GLbyte *pc)
525 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
527 return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);