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