Add mouse and keyboard configuration file
[profile/ivi/xorg-x11-server.git] / glx / singlepix.c
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_size_get.h"
40 #include "indirect_dispatch.h"
41 #include "glapitable.h"
42 #include "glapi.h"
43 #include "glthread.h"
44 #include "dispatch.h"
45
46 int __glXDisp_ReadPixels(__GLXclientState *cl, GLbyte *pc)
47 {
48     GLsizei width, height;
49     GLenum format, type;
50     GLboolean swapBytes, lsbFirst;
51     GLint compsize;
52     __GLXcontext *cx;
53     ClientPtr client = cl->client;
54     int error;
55     char *answer, answerBuffer[200];
56
57     cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
58     if (!cx) {
59         return error;
60     }
61
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;
71
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(), (
77                  *(GLint    *)(pc + 0),
78                  *(GLint    *)(pc + 4),
79                  *(GLsizei  *)(pc + 8),
80                  *(GLsizei  *)(pc + 12),
81                  *(GLenum   *)(pc + 16),
82                  *(GLenum   *)(pc + 20),
83                  answer
84                  ) );
85
86     if (__glXErrorOccured()) {
87         __GLX_BEGIN_REPLY(0);
88         __GLX_SEND_HEADER();
89     } else {
90         __GLX_BEGIN_REPLY(compsize);
91         __GLX_SEND_HEADER();
92         __GLX_SEND_VOID_ARRAY(compsize);
93     }
94     __GLX_NOTE_FLUSHED_CMDS(cx);
95     return Success;
96 }
97
98 int __glXDisp_GetTexImage(__GLXclientState *cl, GLbyte *pc)
99 {
100     GLint level, compsize;
101     GLenum format, type, target;
102     GLboolean swapBytes;
103     __GLXcontext *cx;
104     ClientPtr client = cl->client;
105     int error;
106     char *answer, answerBuffer[200];
107     GLint width=0, height=0, depth=1;
108
109     cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
110     if (!cx) {
111         return error;
112     }
113
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);
120
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) );
125     }
126     /*
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.
129      */
130     compsize = __glGetTexImage_size(target,level,format,type,width,height,depth);
131     if (compsize < 0) compsize = 0;
132
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(), (
137                   *(GLenum   *)(pc + 0),
138                   *(GLint    *)(pc + 4),
139                   *(GLenum   *)(pc + 8),
140                   *(GLenum   *)(pc + 12),
141                   answer
142                   ) );
143
144     if (__glXErrorOccured()) {
145         __GLX_BEGIN_REPLY(0);
146         __GLX_SEND_HEADER();
147     } else {
148         __GLX_BEGIN_REPLY(compsize);
149         ((xGLXGetTexImageReply *)&__glXReply)->width = width;
150         ((xGLXGetTexImageReply *)&__glXReply)->height = height;
151         ((xGLXGetTexImageReply *)&__glXReply)->depth = depth;
152         __GLX_SEND_HEADER();
153         __GLX_SEND_VOID_ARRAY(compsize);
154     }
155     return Success;
156 }
157
158 int __glXDisp_GetPolygonStipple(__GLXclientState *cl, GLbyte *pc)
159 {
160     GLboolean lsbFirst;
161     __GLXcontext *cx;
162     ClientPtr client = cl->client;
163     int error;
164     GLubyte answerBuffer[200];
165     char *answer;
166
167     cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
168     if (!cx) {
169         return error;
170     }
171
172     pc += __GLX_SINGLE_HDR_SIZE;
173     lsbFirst = *(GLboolean *)(pc + 0);
174
175     CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
176     __GLX_GET_ANSWER_BUFFER(answer,cl,128,1);
177
178     __glXClearErrorOccured();
179     CALL_GetPolygonStipple( GET_DISPATCH(), ((GLubyte  *) answer) );
180
181     if (__glXErrorOccured()) {
182         __GLX_BEGIN_REPLY(0);
183         __GLX_SEND_HEADER();
184     } else {
185         __GLX_BEGIN_REPLY(128);
186         __GLX_SEND_HEADER();
187         __GLX_SEND_BYTE_ARRAY(128);
188     }
189     return Success;
190 }
191
192 static int GetSeparableFilter(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
193 {
194     GLint compsize, compsize2;
195     GLenum format, type, target;
196     GLboolean swapBytes;
197     __GLXcontext *cx;
198     ClientPtr client = cl->client;
199     int error;
200     char *answer, answerBuffer[200];
201     GLint width=0, height=0;
202
203     cx = __glXForceCurrent(cl, tag, &error);
204     if (!cx) {
205         return error;
206     }
207
208     format = *(GLenum *)(pc + 4);
209     type = *(GLenum *)(pc + 8);
210     target = *(GLenum *)(pc + 0);
211     swapBytes = *(GLboolean *)(pc + 12);
212
213     /* target must be SEPARABLE_2D, however I guess we can let the GL
214        barf on this one.... */
215
216     CALL_GetConvolutionParameteriv(GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width));
217     CALL_GetConvolutionParameteriv(GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height));
218     /*
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.
221      */
222     compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
223     compsize2 = __glGetTexImage_size(target,1,format,type,height,1,1);
224
225     if (compsize < 0) compsize = 0;
226     if (compsize2 < 0) compsize2 = 0;
227     compsize = __GLX_PAD(compsize);
228     compsize2 = __GLX_PAD(compsize2);
229
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(), (
234                   *(GLenum   *)(pc + 0),
235                   *(GLenum   *)(pc + 4),
236                   *(GLenum   *)(pc + 8),
237                   answer,
238                   answer + compsize,
239                   NULL
240                   ) );
241
242     if (__glXErrorOccured()) {
243         __GLX_BEGIN_REPLY(0);
244         __GLX_SEND_HEADER();
245     } else {
246         __GLX_BEGIN_REPLY(compsize + compsize2);
247         ((xGLXGetSeparableFilterReply *)&__glXReply)->width = width;
248         ((xGLXGetSeparableFilterReply *)&__glXReply)->height = height;
249         __GLX_SEND_HEADER();
250         __GLX_SEND_VOID_ARRAY(compsize + compsize2);
251     }
252
253     return Success;
254 }
255
256 int __glXDisp_GetSeparableFilter(__GLXclientState *cl, GLbyte *pc)
257 {
258     const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
259
260     return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
261 }
262
263 int __glXDisp_GetSeparableFilterEXT(__GLXclientState *cl, GLbyte *pc)
264 {
265     const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
266
267     return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
268 }
269
270 static int GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc,
271                                 GLXContextTag tag)
272 {
273     GLint compsize;
274     GLenum format, type, target;
275     GLboolean swapBytes;
276     __GLXcontext *cx;
277     ClientPtr client = cl->client;
278     int error;
279     char *answer, answerBuffer[200];
280     GLint width=0, height=0;
281
282     cx = __glXForceCurrent(cl, tag, &error);
283     if (!cx) {
284         return error;
285     }
286
287     format = *(GLenum *)(pc + 4);
288     type = *(GLenum *)(pc + 8);
289     target = *(GLenum *)(pc + 0);
290     swapBytes = *(GLboolean *)(pc + 12);
291
292     CALL_GetConvolutionParameteriv(GET_DISPATCH(), 
293                                    (target, GL_CONVOLUTION_WIDTH, &width));
294     if (target == GL_CONVOLUTION_1D) {
295         height = 1;
296     } else {
297         CALL_GetConvolutionParameteriv(GET_DISPATCH(),
298                                        (target, GL_CONVOLUTION_HEIGHT, &height));
299     }
300     /*
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.
303      */
304     compsize = __glGetTexImage_size(target,1,format,type,width,height,1);
305     if (compsize < 0) compsize = 0;
306
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(), (
311                   *(GLenum   *)(pc + 0),
312                   *(GLenum   *)(pc + 4),
313                   *(GLenum   *)(pc + 8),
314                   answer
315                   ) );
316
317     if (__glXErrorOccured()) {
318         __GLX_BEGIN_REPLY(0);
319         __GLX_SEND_HEADER();
320     } else {
321         __GLX_BEGIN_REPLY(compsize);
322         ((xGLXGetConvolutionFilterReply *)&__glXReply)->width = width;
323         ((xGLXGetConvolutionFilterReply *)&__glXReply)->height = height;
324         __GLX_SEND_HEADER();
325         __GLX_SEND_VOID_ARRAY(compsize);
326     }
327
328     return Success;
329 }
330
331 int __glXDisp_GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc)
332 {
333     const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
334
335     return GetConvolutionFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
336 }
337
338 int __glXDisp_GetConvolutionFilterEXT(__GLXclientState *cl, GLbyte *pc)
339 {
340     const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
341
342     return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
343 }
344
345 static int GetHistogram(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
346 {
347     GLint compsize;
348     GLenum format, type, target;
349     GLboolean swapBytes, reset;
350     __GLXcontext *cx;
351     ClientPtr client = cl->client;
352     int error;
353     char *answer, answerBuffer[200];
354     GLint width=0;
355
356     cx = __glXForceCurrent(cl, tag, &error);
357     if (!cx) {
358         return error;
359     }
360
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);
366
367     CALL_GetHistogramParameteriv(GET_DISPATCH(),
368                                  (target, GL_HISTOGRAM_WIDTH, &width));
369     /*
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.
372      */
373     compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
374     if (compsize < 0) compsize = 0;
375
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));
380
381     if (__glXErrorOccured()) {
382         __GLX_BEGIN_REPLY(0);
383         __GLX_SEND_HEADER();
384     } else {
385         __GLX_BEGIN_REPLY(compsize);
386         ((xGLXGetHistogramReply *)&__glXReply)->width = width;
387         __GLX_SEND_HEADER();
388         __GLX_SEND_VOID_ARRAY(compsize);
389     }
390
391     return Success;
392 }
393
394 int __glXDisp_GetHistogram(__GLXclientState *cl, GLbyte *pc)
395 {
396     const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
397
398     return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
399 }
400
401 int __glXDisp_GetHistogramEXT(__GLXclientState *cl, GLbyte *pc)
402 {
403     const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
404
405     return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
406 }
407
408 static int GetMinmax(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
409 {
410     GLint compsize;
411     GLenum format, type, target;
412     GLboolean swapBytes, reset;
413     __GLXcontext *cx;
414     ClientPtr client = cl->client;
415     int error;
416     char *answer, answerBuffer[200];
417
418     cx = __glXForceCurrent(cl, tag, &error);
419     if (!cx) {
420         return error;
421     }
422
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);
428
429     compsize = __glGetTexImage_size(target,1,format,type,2,1,1);
430     if (compsize < 0) compsize = 0;
431
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));
436
437     if (__glXErrorOccured()) {
438         __GLX_BEGIN_REPLY(0);
439         __GLX_SEND_HEADER();
440     } else {
441         __GLX_BEGIN_REPLY(compsize);
442         __GLX_SEND_HEADER();
443         __GLX_SEND_VOID_ARRAY(compsize);
444     }
445
446     return Success;
447 }
448
449 int __glXDisp_GetMinmax(__GLXclientState *cl, GLbyte *pc)
450 {
451     const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
452
453     return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
454 }
455
456 int __glXDisp_GetMinmaxEXT(__GLXclientState *cl, GLbyte *pc)
457 {
458     const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
459
460     return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
461 }
462
463 static int GetColorTable(__GLXclientState *cl, GLbyte *pc, GLXContextTag tag)
464 {
465     GLint compsize;
466     GLenum format, type, target;
467     GLboolean swapBytes;
468     __GLXcontext *cx;
469     ClientPtr client = cl->client;
470     int error;
471     char *answer, answerBuffer[200];
472     GLint width=0;
473
474     cx = __glXForceCurrent(cl, tag, &error);
475     if (!cx) {
476         return error;
477     }
478
479     target = *(GLenum *)(pc + 0);
480     format = *(GLenum *)(pc + 4);
481     type = *(GLenum *)(pc + 8);
482     swapBytes = *(GLboolean *)(pc + 12);
483
484     CALL_GetColorTableParameteriv(GET_DISPATCH(), 
485                                   (target, GL_COLOR_TABLE_WIDTH, &width));
486     /*
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.
489      */
490     compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
491     if (compsize < 0) compsize = 0;
492
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(), (
497                   *(GLenum   *)(pc + 0),
498                   *(GLenum   *)(pc + 4),
499                   *(GLenum   *)(pc + 8),
500                   answer
501                   ) );
502
503     if (__glXErrorOccured()) {
504         __GLX_BEGIN_REPLY(0);
505         __GLX_SEND_HEADER();
506     } else {
507         __GLX_BEGIN_REPLY(compsize);
508         ((xGLXGetColorTableReply *)&__glXReply)->width = width;
509         __GLX_SEND_HEADER();
510         __GLX_SEND_VOID_ARRAY(compsize);
511     }
512
513     return Success;
514 }
515
516 int __glXDisp_GetColorTable(__GLXclientState *cl, GLbyte *pc)
517 {
518     const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
519
520     return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
521 }
522
523 int __glXDisp_GetColorTableSGI(__GLXclientState *cl, GLbyte *pc)
524 {
525     const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
526
527     return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
528 }