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