xref: /OK3568_Linux_fs/external/xserver/glx/indirect_program.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright IBM Corporation 2005, 2006
3*4882a593Smuzhiyun  * All Rights Reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
7*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
8*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sub license,
9*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
10*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
13*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
14*4882a593Smuzhiyun  * Software.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19*4882a593Smuzhiyun  * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
20*4882a593Smuzhiyun  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21*4882a593Smuzhiyun  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22*4882a593Smuzhiyun  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /**
26*4882a593Smuzhiyun  * \file indirect_program.c
27*4882a593Smuzhiyun  * Hand-coded routines needed to support programmable pipeline extensions.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * \author Ian Romanick <idr@us.ibm.com>
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
33*4882a593Smuzhiyun #include <dix-config.h>
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #include "glxserver.h"
37*4882a593Smuzhiyun #include "glxbyteorder.h"
38*4882a593Smuzhiyun #include "glxext.h"
39*4882a593Smuzhiyun #include "singlesize.h"
40*4882a593Smuzhiyun #include "unpack.h"
41*4882a593Smuzhiyun #include "indirect_size_get.h"
42*4882a593Smuzhiyun #include "indirect_dispatch.h"
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /**
45*4882a593Smuzhiyun  * Handle both types of glGetProgramString calls.
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun static int
DoGetProgramString(struct __GLXclientStateRec * cl,GLbyte * pc,PFNGLGETPROGRAMIVARBPROC get_programiv,PFNGLGETPROGRAMSTRINGARBPROC get_program_string,Bool do_swap)48*4882a593Smuzhiyun DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte * pc,
49*4882a593Smuzhiyun                    PFNGLGETPROGRAMIVARBPROC get_programiv,
50*4882a593Smuzhiyun                    PFNGLGETPROGRAMSTRINGARBPROC get_program_string,
51*4882a593Smuzhiyun                    Bool do_swap)
52*4882a593Smuzhiyun {
53*4882a593Smuzhiyun     xGLXVendorPrivateWithReplyReq *const req =
54*4882a593Smuzhiyun         (xGLXVendorPrivateWithReplyReq *) pc;
55*4882a593Smuzhiyun     int error;
56*4882a593Smuzhiyun     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
57*4882a593Smuzhiyun     ClientPtr client = cl->client;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun     REQUEST_FIXED_SIZE(xGLXVendorPrivateWithReplyReq, 8);
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun     pc += __GLX_VENDPRIV_HDR_SIZE;
62*4882a593Smuzhiyun     if (cx != NULL) {
63*4882a593Smuzhiyun         GLenum target;
64*4882a593Smuzhiyun         GLenum pname;
65*4882a593Smuzhiyun         GLint compsize = 0;
66*4882a593Smuzhiyun         char *answer = NULL, answerBuffer[200];
67*4882a593Smuzhiyun         xGLXSingleReply reply = { 0, };
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun         if (do_swap) {
70*4882a593Smuzhiyun             target = (GLenum) bswap_32(*(int *) (pc + 0));
71*4882a593Smuzhiyun             pname = (GLenum) bswap_32(*(int *) (pc + 4));
72*4882a593Smuzhiyun         }
73*4882a593Smuzhiyun         else {
74*4882a593Smuzhiyun             target = *(GLenum *) (pc + 0);
75*4882a593Smuzhiyun             pname = *(GLuint *) (pc + 4);
76*4882a593Smuzhiyun         }
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun         /* The value of the GL_PROGRAM_LENGTH_ARB and GL_PROGRAM_LENGTH_NV
79*4882a593Smuzhiyun          * enumerants is the same.
80*4882a593Smuzhiyun          */
81*4882a593Smuzhiyun         get_programiv(target, GL_PROGRAM_LENGTH_ARB, &compsize);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun         if (compsize != 0) {
84*4882a593Smuzhiyun             __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
85*4882a593Smuzhiyun             __glXClearErrorOccured();
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun             get_program_string(target, pname, (GLubyte *) answer);
88*4882a593Smuzhiyun         }
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun         if (__glXErrorOccured()) {
91*4882a593Smuzhiyun             __GLX_BEGIN_REPLY(0);
92*4882a593Smuzhiyun             __GLX_SEND_HEADER();
93*4882a593Smuzhiyun         }
94*4882a593Smuzhiyun         else {
95*4882a593Smuzhiyun             __GLX_BEGIN_REPLY(compsize);
96*4882a593Smuzhiyun             ((xGLXGetTexImageReply *) &reply)->width = compsize;
97*4882a593Smuzhiyun             __GLX_SEND_HEADER();
98*4882a593Smuzhiyun             __GLX_SEND_VOID_ARRAY(compsize);
99*4882a593Smuzhiyun         }
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun         error = Success;
102*4882a593Smuzhiyun     }
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun     return error;
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun int
__glXDisp_GetProgramStringARB(struct __GLXclientStateRec * cl,GLbyte * pc)108*4882a593Smuzhiyun __glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc)
109*4882a593Smuzhiyun {
110*4882a593Smuzhiyun     PFNGLGETPROGRAMIVARBPROC get_program =
111*4882a593Smuzhiyun         __glGetProcAddress("glGetProgramivARB");
112*4882a593Smuzhiyun     PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
113*4882a593Smuzhiyun         __glGetProcAddress("glGetProgramStringARB");
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun     return DoGetProgramString(cl, pc, get_program, get_program_string, FALSE);
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun int
__glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec * cl,GLbyte * pc)119*4882a593Smuzhiyun __glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun     PFNGLGETPROGRAMIVARBPROC get_program =
122*4882a593Smuzhiyun         __glGetProcAddress("glGetProgramivARB");
123*4882a593Smuzhiyun     PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
124*4882a593Smuzhiyun         __glGetProcAddress("glGetProgramStringARB");
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun     return DoGetProgramString(cl, pc, get_program, get_program_string, TRUE);
127*4882a593Smuzhiyun }
128