Initial commit
[xorg_rtime.git] / xorg-server-1.4 / GL / glx / singlepixswap.c
blob032b42765989b803150add6671b9bdf3fd55004d
1 /*
2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9 **
10 ** http://oss.sgi.com/projects/FreeB
11 **
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17 **
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
23 **
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
36 #define NEED_REPLIES
37 #ifdef HAVE_DIX_CONFIG_H
38 #include <dix-config.h>
39 #endif
41 #include "glxserver.h"
42 #include "glxext.h"
43 #include "singlesize.h"
44 #include "unpack.h"
45 #include "indirect_dispatch.h"
46 #include "indirect_size_get.h"
47 #include "glapitable.h"
48 #include "glapi.h"
49 #include "glthread.h"
50 #include "dispatch.h"
52 int __glXDispSwap_ReadPixels(__GLXclientState *cl, GLbyte *pc)
54 GLsizei width, height;
55 GLenum format, type;
56 GLboolean swapBytes, lsbFirst;
57 GLint compsize;
58 __GLX_DECLARE_SWAP_VARIABLES;
59 __GLXcontext *cx;
60 ClientPtr client = cl->client;
61 int error;
62 char *answer, answerBuffer[200];
64 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
65 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
66 if (!cx) {
67 return error;
70 pc += __GLX_SINGLE_HDR_SIZE;
71 __GLX_SWAP_INT(pc+0);
72 __GLX_SWAP_INT(pc+4);
73 __GLX_SWAP_INT(pc+8);
74 __GLX_SWAP_INT(pc+12);
75 __GLX_SWAP_INT(pc+16);
76 __GLX_SWAP_INT(pc+20);
78 width = *(GLsizei *)(pc + 8);
79 height = *(GLsizei *)(pc + 12);
80 format = *(GLenum *)(pc + 16);
81 type = *(GLenum *)(pc + 20);
82 swapBytes = *(GLboolean *)(pc + 24);
83 lsbFirst = *(GLboolean *)(pc + 25);
84 compsize = __glReadPixels_size(format,type,width,height);
85 if (compsize < 0) compsize = 0;
87 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
88 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
89 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
90 __glXClearErrorOccured();
91 CALL_ReadPixels( GET_DISPATCH(),
92 (*(GLint *)(pc + 0),
93 *(GLint *)(pc + 4),
94 *(GLsizei *)(pc + 8),
95 *(GLsizei *)(pc + 12),
96 *(GLenum *)(pc + 16),
97 *(GLenum *)(pc + 20),
98 answer)
101 if (__glXErrorOccured()) {
102 __GLX_BEGIN_REPLY(0);
103 __GLX_SWAP_REPLY_HEADER();
104 __GLX_SEND_HEADER();
105 } else {
106 __GLX_BEGIN_REPLY(compsize);
107 __GLX_SWAP_REPLY_HEADER();
108 __GLX_SEND_HEADER();
109 __GLX_SEND_VOID_ARRAY(compsize);
111 return Success;
114 int __glXDispSwap_GetTexImage(__GLXclientState *cl, GLbyte *pc)
116 GLint level, compsize;
117 GLenum format, type, target;
118 GLboolean swapBytes;
119 __GLX_DECLARE_SWAP_VARIABLES;
120 __GLXcontext *cx;
121 ClientPtr client = cl->client;
122 int error;
123 char *answer, answerBuffer[200];
124 GLint width=0, height=0, depth=1;
126 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
127 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
128 if (!cx) {
129 return error;
132 pc += __GLX_SINGLE_HDR_SIZE;
133 __GLX_SWAP_INT(pc+0);
134 __GLX_SWAP_INT(pc+4);
135 __GLX_SWAP_INT(pc+8);
136 __GLX_SWAP_INT(pc+12);
138 level = *(GLint *)(pc + 4);
139 format = *(GLenum *)(pc + 8);
140 type = *(GLenum *)(pc + 12);
141 target = *(GLenum *)(pc + 0);
142 swapBytes = *(GLboolean *)(pc + 16);
144 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_WIDTH, &width) );
145 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_HEIGHT, &height) );
146 if ( target == GL_TEXTURE_3D) {
147 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_DEPTH, &depth) );
150 * The three queries above might fail if we're in a state where queries
151 * are illegal, but then width, height, and depth would still be zero anyway.
153 compsize = __glGetTexImage_size(target,level,format,type,width,height,depth);
154 if (compsize < 0) compsize = 0;
156 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
157 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
158 __glXClearErrorOccured();
159 CALL_GetTexImage( GET_DISPATCH(), (
160 *(GLenum *)(pc + 0),
161 *(GLint *)(pc + 4),
162 *(GLenum *)(pc + 8),
163 *(GLenum *)(pc + 12),
164 answer
165 ) );
167 if (__glXErrorOccured()) {
168 __GLX_BEGIN_REPLY(0);
169 __GLX_SWAP_REPLY_HEADER();
170 __GLX_SEND_HEADER();
171 } else {
172 __GLX_BEGIN_REPLY(compsize);
173 __GLX_SWAP_REPLY_HEADER();
174 __GLX_SWAP_INT(&width);
175 __GLX_SWAP_INT(&height);
176 __GLX_SWAP_INT(&depth);
177 ((xGLXGetTexImageReply *)&__glXReply)->width = width;
178 ((xGLXGetTexImageReply *)&__glXReply)->height = height;
179 ((xGLXGetTexImageReply *)&__glXReply)->depth = depth;
180 __GLX_SEND_HEADER();
181 __GLX_SEND_VOID_ARRAY(compsize);
183 return Success;
186 int __glXDispSwap_GetPolygonStipple(__GLXclientState *cl, GLbyte *pc)
188 GLboolean lsbFirst;
189 __GLXcontext *cx;
190 ClientPtr client = cl->client;
191 int error;
192 GLubyte answerBuffer[200];
193 char *answer;
194 __GLX_DECLARE_SWAP_VARIABLES;
196 __GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
197 cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
198 if (!cx) {
199 return error;
201 pc += __GLX_SINGLE_HDR_SIZE;
202 lsbFirst = *(GLboolean *)(pc + 0);
204 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
205 __GLX_GET_ANSWER_BUFFER(answer,cl,128,1);
207 __glXClearErrorOccured();
208 CALL_GetPolygonStipple( GET_DISPATCH(), ((GLubyte *) answer) );
209 if (__glXErrorOccured()) {
210 __GLX_BEGIN_REPLY(0);
211 __GLX_SWAP_REPLY_HEADER();
212 __GLX_SEND_HEADER();
213 } else {
214 __GLX_BEGIN_REPLY(128);
215 __GLX_SWAP_REPLY_HEADER();
216 __GLX_SEND_HEADER();
217 __GLX_SEND_BYTE_ARRAY(128);
219 return Success;
222 static int GetSeparableFilter(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
224 GLint compsize, compsize2;
225 GLenum format, type, target;
226 GLboolean swapBytes;
227 __GLXcontext *cx;
228 ClientPtr client = cl->client;
229 int error;
230 __GLX_DECLARE_SWAP_VARIABLES;
231 char *answer, answerBuffer[200];
232 GLint width=0, height=0;
234 cx = __glXForceCurrent(cl, tag, &error);
235 if (!cx) {
236 return error;
239 __GLX_SWAP_INT(pc+0);
240 __GLX_SWAP_INT(pc+4);
241 __GLX_SWAP_INT(pc+8);
243 format = *(GLenum *)(pc + 4);
244 type = *(GLenum *)(pc + 8);
245 target = *(GLenum *)(pc + 0);
246 swapBytes = *(GLboolean *)(pc + 12);
248 /* target must be SEPARABLE_2D, however I guess we can let the GL
249 barf on this one.... */
251 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width) );
252 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height) );
254 * The two queries above might fail if we're in a state where queries
255 * are illegal, but then width and height would still be zero anyway.
257 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
258 compsize2 = __glGetTexImage_size(target,1,format,type,height,1,1);
260 if (compsize < 0) compsize = 0;
261 if (compsize2 < 0) compsize2 = 0;
262 compsize = __GLX_PAD(compsize);
263 compsize2 = __GLX_PAD(compsize2);
265 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
266 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize + compsize2,1);
267 __glXClearErrorOccured();
268 CALL_GetSeparableFilter( GET_DISPATCH(), (
269 *(GLenum *)(pc + 0),
270 *(GLenum *)(pc + 4),
271 *(GLenum *)(pc + 8),
272 answer,
273 answer + compsize,
274 NULL
275 ) );
277 if (__glXErrorOccured()) {
278 __GLX_BEGIN_REPLY(0);
279 __GLX_SWAP_REPLY_HEADER();
280 } else {
281 __GLX_BEGIN_REPLY(compsize + compsize2);
282 __GLX_SWAP_REPLY_HEADER();
283 __GLX_SWAP_INT(&width);
284 __GLX_SWAP_INT(&height);
285 ((xGLXGetSeparableFilterReply *)&__glXReply)->width = width;
286 ((xGLXGetSeparableFilterReply *)&__glXReply)->height = height;
287 __GLX_SEND_VOID_ARRAY(compsize + compsize2);
290 return Success;
293 int __glXDispSwap_GetSeparableFilter(__GLXclientState *cl, GLbyte *pc)
295 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
297 return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
300 int __glXDispSwap_GetSeparableFilterEXT(__GLXclientState *cl, GLbyte *pc)
302 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
304 return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
307 static int GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
309 GLint compsize;
310 GLenum format, type, target;
311 GLboolean swapBytes;
312 __GLXcontext *cx;
313 ClientPtr client = cl->client;
314 int error;
315 __GLX_DECLARE_SWAP_VARIABLES;
316 char *answer, answerBuffer[200];
317 GLint width=0, height=0;
319 cx = __glXForceCurrent(cl, tag, &error);
320 if (!cx) {
321 return error;
324 __GLX_SWAP_INT(pc+0);
325 __GLX_SWAP_INT(pc+4);
326 __GLX_SWAP_INT(pc+8);
328 format = *(GLenum *)(pc + 4);
329 type = *(GLenum *)(pc + 8);
330 target = *(GLenum *)(pc + 0);
331 swapBytes = *(GLboolean *)(pc + 12);
333 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width) );
334 if (target == GL_CONVOLUTION_2D) {
335 height = 1;
336 } else {
337 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height) );
340 * The two queries above might fail if we're in a state where queries
341 * are illegal, but then width and height would still be zero anyway.
343 compsize = __glGetTexImage_size(target,1,format,type,width,height,1);
344 if (compsize < 0) compsize = 0;
346 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
347 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
348 __glXClearErrorOccured();
349 CALL_GetConvolutionFilter( GET_DISPATCH(), (
350 *(GLenum *)(pc + 0),
351 *(GLenum *)(pc + 4),
352 *(GLenum *)(pc + 8),
353 answer
354 ) );
356 if (__glXErrorOccured()) {
357 __GLX_BEGIN_REPLY(0);
358 __GLX_SWAP_REPLY_HEADER();
359 } else {
360 __GLX_BEGIN_REPLY(compsize);
361 __GLX_SWAP_REPLY_HEADER();
362 __GLX_SWAP_INT(&width);
363 __GLX_SWAP_INT(&height);
364 ((xGLXGetConvolutionFilterReply *)&__glXReply)->width = width;
365 ((xGLXGetConvolutionFilterReply *)&__glXReply)->height = height;
366 __GLX_SEND_VOID_ARRAY(compsize);
369 return Success;
372 int __glXDispSwap_GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc)
374 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
376 return GetConvolutionFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
379 int __glXDispSwap_GetConvolutionFilterEXT(__GLXclientState *cl, GLbyte *pc)
381 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
383 return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
386 static int GetHistogram(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
388 GLint compsize;
389 GLenum format, type, target;
390 GLboolean swapBytes, reset;
391 __GLXcontext *cx;
392 ClientPtr client = cl->client;
393 int error;
394 __GLX_DECLARE_SWAP_VARIABLES;
395 char *answer, answerBuffer[200];
396 GLint width=0;
398 cx = __glXForceCurrent(cl, tag, &error);
399 if (!cx) {
400 return error;
403 __GLX_SWAP_INT(pc+0);
404 __GLX_SWAP_INT(pc+4);
405 __GLX_SWAP_INT(pc+8);
407 format = *(GLenum *)(pc + 4);
408 type = *(GLenum *)(pc + 8);
409 target = *(GLenum *)(pc + 0);
410 swapBytes = *(GLboolean *)(pc + 12);
411 reset = *(GLboolean *)(pc + 13);
413 CALL_GetHistogramParameteriv( GET_DISPATCH(), (target, GL_HISTOGRAM_WIDTH, &width) );
415 * The one query above might fail if we're in a state where queries
416 * are illegal, but then width would still be zero anyway.
418 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
419 if (compsize < 0) compsize = 0;
421 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
422 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
423 __glXClearErrorOccured();
424 CALL_GetHistogram( GET_DISPATCH(), (target, reset, format, type, answer) );
426 if (__glXErrorOccured()) {
427 __GLX_BEGIN_REPLY(0);
428 __GLX_SWAP_REPLY_HEADER();
429 } else {
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);
437 return Success;
440 int __glXDispSwap_GetHistogram(__GLXclientState *cl, GLbyte *pc)
442 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
444 return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
447 int __glXDispSwap_GetHistogramEXT(__GLXclientState *cl, GLbyte *pc)
449 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
451 return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
454 static int GetMinmax(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
456 GLint compsize;
457 GLenum format, type, target;
458 GLboolean swapBytes, reset;
459 __GLXcontext *cx;
460 ClientPtr client = cl->client;
461 int error;
462 __GLX_DECLARE_SWAP_VARIABLES;
463 char *answer, answerBuffer[200];
465 cx = __glXForceCurrent(cl, tag, &error);
466 if (!cx) {
467 return error;
470 __GLX_SWAP_INT(pc+0);
471 __GLX_SWAP_INT(pc+4);
472 __GLX_SWAP_INT(pc+8);
474 format = *(GLenum *)(pc + 4);
475 type = *(GLenum *)(pc + 8);
476 target = *(GLenum *)(pc + 0);
477 swapBytes = *(GLboolean *)(pc + 12);
478 reset = *(GLboolean *)(pc + 13);
480 compsize = __glGetTexImage_size(target,1,format,type,2,1,1);
481 if (compsize < 0) compsize = 0;
483 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
484 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
485 __glXClearErrorOccured();
486 CALL_GetMinmax( GET_DISPATCH(), (target, reset, format, type, answer) );
488 if (__glXErrorOccured()) {
489 __GLX_BEGIN_REPLY(0);
490 __GLX_SWAP_REPLY_HEADER();
491 } else {
492 __GLX_BEGIN_REPLY(compsize);
493 __GLX_SWAP_REPLY_HEADER();
494 __GLX_SEND_VOID_ARRAY(compsize);
497 return Success;
500 int __glXDispSwap_GetMinmax(__GLXclientState *cl, GLbyte *pc)
502 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
504 return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
507 int __glXDispSwap_GetMinmaxEXT(__GLXclientState *cl, GLbyte *pc)
509 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
511 return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
514 static int GetColorTable(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
516 GLint compsize;
517 GLenum format, type, target;
518 GLboolean swapBytes;
519 __GLXcontext *cx;
520 ClientPtr client = cl->client;
521 int error;
522 __GLX_DECLARE_SWAP_VARIABLES;
523 char *answer, answerBuffer[200];
524 GLint width=0;
526 cx = __glXForceCurrent(cl, tag, &error);
527 if (!cx) {
528 return error;
531 __GLX_SWAP_INT(pc+0);
532 __GLX_SWAP_INT(pc+4);
533 __GLX_SWAP_INT(pc+8);
535 format = *(GLenum *)(pc + 4);
536 type = *(GLenum *)(pc + 8);
537 target = *(GLenum *)(pc + 0);
538 swapBytes = *(GLboolean *)(pc + 12);
540 CALL_GetColorTableParameteriv( GET_DISPATCH(), (target, GL_COLOR_TABLE_WIDTH, &width) );
542 * The one query above might fail if we're in a state where queries
543 * are illegal, but then width would still be zero anyway.
545 compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
546 if (compsize < 0) compsize = 0;
548 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
549 __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
550 __glXClearErrorOccured();
551 CALL_GetColorTable( GET_DISPATCH(), (
552 *(GLenum *)(pc + 0),
553 *(GLenum *)(pc + 4),
554 *(GLenum *)(pc + 8),
555 answer
556 ) );
558 if (__glXErrorOccured()) {
559 __GLX_BEGIN_REPLY(0);
560 __GLX_SWAP_REPLY_HEADER();
561 } else {
562 __GLX_BEGIN_REPLY(compsize);
563 __GLX_SWAP_REPLY_HEADER();
564 __GLX_SWAP_INT(&width);
565 ((xGLXGetColorTableReply *)&__glXReply)->width = width;
566 __GLX_SEND_VOID_ARRAY(compsize);
569 return Success;
572 int __glXDispSwap_GetColorTable(__GLXclientState *cl, GLbyte *pc)
574 const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
576 return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
579 int __glXDispSwap_GetColorTableSGI(__GLXclientState *cl, GLbyte *pc)
581 const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
583 return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);