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 #include "packsingle.h"
32 #include "indirect.h"
33 #include "glapi.h"
34 #include "glthread.h"
35 #include <GL/glxproto.h>
36 
37 void
__indirect_glGetSeparableFilter(GLenum target,GLenum format,GLenum type,GLvoid * row,GLvoid * column,GLvoid * span)38 __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
39                                 GLvoid * row, GLvoid * column, GLvoid * span)
40 {
41    __GLX_SINGLE_DECLARE_VARIABLES();
42    const __GLXattribute *state;
43    xGLXGetSeparableFilterReply reply;
44    GLubyte *rowBuf, *colBuf;
45 
46    if (!dpy)
47       return;
48    __GLX_SINGLE_LOAD_VARIABLES();
49    state = gc->client_state_private;
50 
51    /* Send request */
52    __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13));
53    __GLX_SINGLE_PUT_LONG(0, target);
54    __GLX_SINGLE_PUT_LONG(4, format);
55    __GLX_SINGLE_PUT_LONG(8, type);
56    __GLX_SINGLE_PUT_CHAR(12, state->storePack.swapEndian);
57    __GLX_SINGLE_READ_XREPLY();
58    compsize = reply.length << 2;
59 
60    if (compsize != 0) {
61       GLint width, height;
62       GLint widthsize, heightsize;
63 
64       width = reply.width;
65       height = reply.height;
66 
67       widthsize = __glImageSize(width, 1, 1, format, type, 0);
68       heightsize = __glImageSize(height, 1, 1, format, type, 0);
69 
70       /* Allocate a holding buffer to transform the data from */
71       rowBuf = (GLubyte *) Xmalloc(widthsize);
72       if (!rowBuf) {
73          /* Throw data away */
74          _XEatData(dpy, compsize);
75          __glXSetError(gc, GL_OUT_OF_MEMORY);
76          UnlockDisplay(dpy);
77          SyncHandle();
78          return;
79       }
80       else {
81          __GLX_SINGLE_GET_CHAR_ARRAY(((char *) rowBuf), widthsize);
82          __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
83          Xfree((char *) rowBuf);
84       }
85       colBuf = (GLubyte *) Xmalloc(heightsize);
86       if (!colBuf) {
87          /* Throw data away */
88          _XEatData(dpy, compsize - __GLX_PAD(widthsize));
89          __glXSetError(gc, GL_OUT_OF_MEMORY);
90          UnlockDisplay(dpy);
91          SyncHandle();
92          return;
93       }
94       else {
95          __GLX_SINGLE_GET_CHAR_ARRAY(((char *) colBuf), heightsize);
96          __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column);
97          Xfree((char *) colBuf);
98       }
99    }
100    else {
101       /*
102        ** don't modify user's buffer.
103        */
104    }
105    __GLX_SINGLE_END();
106 
107 }
108 
109 
110 /* it is defined to gl_dispatch_stub_NNN in indirect.h */
gl_dispatch_stub_GetSeparableFilterEXT(GLenum target,GLenum format,GLenum type,GLvoid * row,GLvoid * column,GLvoid * span)111 void gl_dispatch_stub_GetSeparableFilterEXT (GLenum target, GLenum format,
112                                              GLenum type, GLvoid * row,
113                                              GLvoid * column, GLvoid * span)
114 {
115    struct glx_context *const gc = __glXGetCurrentContext();
116 
117 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
118    if (gc->isDirect) {
119       const _glapi_proc *const table = (_glapi_proc *) GET_DISPATCH();
120       PFNGLGETSEPARABLEFILTEREXTPROC p =
121          (PFNGLGETSEPARABLEFILTEREXTPROC) table[359];
122 
123       p(target, format, type, row, column, span);
124       return;
125    }
126    else
127 #endif
128    {
129       Display *const dpy = gc->currentDpy;
130       const GLuint cmdlen = __GLX_PAD(13);
131 
132       if (dpy != NULL) {
133          const __GLXattribute *const state = gc->client_state_private;
134          xGLXGetSeparableFilterReply reply;
135          GLubyte const *pc =
136             __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply,
137                                     X_GLvop_GetSeparableFilterEXT, cmdlen);
138          unsigned compsize;
139 
140 
141          (void) memcpy((void *) (pc + 0), (void *) (&target), 4);
142          (void) memcpy((void *) (pc + 4), (void *) (&format), 4);
143          (void) memcpy((void *) (pc + 8), (void *) (&type), 4);
144          *(int8_t *) (pc + 12) = state->storePack.swapEndian;
145 
146          (void) _XReply(dpy, (xReply *) & reply, 0, False);
147 
148          compsize = reply.length << 2;
149 
150          if (compsize != 0) {
151             const GLint width = reply.width;
152             const GLint height = reply.height;
153             const GLint widthsize =
154                __glImageSize(width, 1, 1, format, type, 0);
155             const GLint heightsize =
156                __glImageSize(height, 1, 1, format, type, 0);
157             GLubyte *const buf =
158                (GLubyte *) Xmalloc((widthsize > heightsize) ? widthsize :
159                                    heightsize);
160 
161             if (buf == NULL) {
162                /* Throw data away */
163                _XEatData(dpy, compsize);
164                __glXSetError(gc, GL_OUT_OF_MEMORY);
165 
166                UnlockDisplay(dpy);
167                SyncHandle();
168                return;
169             }
170             else {
171                int extra;
172 
173                extra = 4 - (widthsize & 3);
174                _XRead(dpy, (char *) buf, widthsize);
175                if (extra < 4) {
176                   _XEatData(dpy, extra);
177                }
178 
179                __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, row);
180 
181                extra = 4 - (heightsize & 3);
182                _XRead(dpy, (char *) buf, heightsize);
183                if (extra < 4) {
184                   _XEatData(dpy, extra);
185                }
186 
187                __glEmptyImage(gc, 1, height, 1, 1, format, type, buf, column);
188 
189                Xfree((char *) buf);
190             }
191          }
192       }
193    }
194 }
195