Add mouse and keyboard configuration file
[profile/ivi/xorg-x11-server.git] / glx / indirect_program.c
1 /*
2  * (C) Copyright IBM Corporation 2005, 2006
3  * 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, sub license,
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 and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 /**
26  * \file indirect_program.c
27  * Hand-coded routines needed to support programmable pipeline extensions.
28  *
29  * \author Ian Romanick <idr@us.ibm.com>
30  */
31
32 #ifdef HAVE_DIX_CONFIG_H
33 #include <dix-config.h>
34 #endif
35
36 #include "glxserver.h"
37 #include "glxbyteorder.h"
38 #include "glxext.h"
39 #include "singlesize.h"
40 #include "unpack.h"
41 #include "indirect_size_get.h"
42 #include "indirect_dispatch.h"
43 #include "glapitable.h"
44 #include "glapi.h"
45 #include "glthread.h"
46 #include "dispatch.h"
47 #include "glapioffsets.h"
48
49 static int DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc,
50     unsigned get_programiv_offset, unsigned get_program_string_offset,
51     Bool do_swap);
52
53 /**
54  * Handle both types of glGetProgramString calls.
55  *
56  * This single function handles both \c glGetProgramStringARB and
57  * \c glGetProgramStringNV.  The dispatch offsets for the functions to use
58  * for \c glGetProgramivARB and \c glGetProgramStringARB are passed in by the
59  * caller.  These can be the offsets of either the ARB versions or the NV
60  * versions.
61  */
62 int DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte *pc,
63                        unsigned get_programiv_offset,
64                        unsigned get_program_string_offset,
65                        Bool do_swap)
66 {
67     xGLXVendorPrivateWithReplyReq * const req = 
68       (xGLXVendorPrivateWithReplyReq *) pc;
69     int error;
70     __GLXcontext * const cx = __glXForceCurrent(cl, req->contextTag, & error);
71     ClientPtr client = cl->client;
72
73
74     pc += __GLX_VENDPRIV_HDR_SIZE;
75     if (cx != NULL) {
76         GLenum target;
77         GLenum pname;
78         GLint compsize = 0;
79         char *answer = NULL, answerBuffer[200];
80
81         if (do_swap) {
82             target = (GLenum) bswap_32(*(int *)(pc + 0));
83             pname =  (GLenum) bswap_32(*(int *)(pc + 4));
84         }
85         else {
86             target = *(GLenum *)(pc + 0);
87             pname =  *(GLuint *)(pc + 4);
88         }
89
90         /* The value of the GL_PROGRAM_LENGTH_ARB and GL_PROGRAM_LENGTH_NV
91          * enumerants is the same.
92          */
93         CALL_by_offset(GET_DISPATCH(),
94                        (void (GLAPIENTRYP)(GLuint, GLenum, GLint *)), 
95                        get_programiv_offset,
96                        (target, GL_PROGRAM_LENGTH_ARB, &compsize));
97
98         if (compsize != 0) {
99             __GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
100             __glXClearErrorOccured();
101
102             CALL_by_offset(GET_DISPATCH(), 
103                            (void (GLAPIENTRYP)(GLuint, GLenum, GLubyte *)),
104                            get_program_string_offset,
105                            (target, pname, (GLubyte *)answer));
106         }
107
108         if (__glXErrorOccured()) {
109             __GLX_BEGIN_REPLY(0);
110             __GLX_SEND_HEADER();
111         } else {
112             __GLX_BEGIN_REPLY(compsize);
113             ((xGLXGetTexImageReply *)&__glXReply)->width = compsize;
114             __GLX_SEND_HEADER();
115             __GLX_SEND_VOID_ARRAY(compsize);
116         }
117
118         error = Success;
119     }
120
121     return error;
122 }
123
124 int __glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte *pc)
125 {
126     return DoGetProgramString(cl, pc, _gloffset_GetProgramivARB,
127                               _gloffset_GetProgramStringARB, False);
128 }
129
130
131 int __glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte *pc)
132 {
133     return DoGetProgramString(cl, pc, _gloffset_GetProgramivARB,
134                               _gloffset_GetProgramStringARB, True);
135 }
136
137
138 int __glXDisp_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte *pc)
139 {
140     return DoGetProgramString(cl, pc, _gloffset_GetProgramivNV,
141                               _gloffset_GetProgramStringNV, False);
142 }
143
144
145 int __glXDispSwap_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte *pc)
146 {
147     return DoGetProgramString(cl, pc, _gloffset_GetProgramivNV,
148                               _gloffset_GetProgramStringNV, True);
149 }