Update to SGI FreeB 2.0.
[mesa.git] / src / glx / x11 / 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 "dispatch.h"
34 #include "glapi.h"
35 #include "glthread.h"
36 #include "glapioffsets.h"
37 #include <GL/glxproto.h>
38
39 void __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) 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 } else {
80 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)rowBuf),widthsize);
81 __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
82 Xfree((char*) rowBuf);
83 }
84 colBuf = (GLubyte*) Xmalloc(heightsize);
85 if (!colBuf) {
86 /* Throw data away */
87 _XEatData(dpy, compsize - __GLX_PAD(widthsize));
88 __glXSetError(gc, GL_OUT_OF_MEMORY);
89 UnlockDisplay(dpy);
90 SyncHandle();
91 return;
92 } else {
93 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)colBuf),heightsize);
94 __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column);
95 Xfree((char*) colBuf);
96 }
97 } else {
98 /*
99 ** don't modify user's buffer.
100 */
101 }
102 __GLX_SINGLE_END();
103
104 }
105
106
107 #define CONCAT(a,b) a ## b
108 #define NAME(o) CONCAT(gl_dispatch_stub_, o)
109
110 void NAME(_gloffset_GetSeparableFilter)(GLenum target, GLenum format, GLenum type,
111 GLvoid *row, GLvoid *column, GLvoid *span)
112 {
113 __GLXcontext * const gc = __glXGetCurrentContext();
114
115 #ifdef GLX_DIRECT_RENDERING
116 if (gc->driContext) {
117 CALL_GetSeparableFilter(GET_DISPATCH(),
118 (target, format, type, row, column, span));
119 return;
120 } else
121 #endif
122 {
123 Display *const dpy = gc->currentDpy;
124 const GLuint cmdlen = __GLX_PAD(13);
125
126 if (dpy != NULL) {
127 const __GLXattribute * const state = gc->client_state_private;
128 xGLXGetSeparableFilterReply reply;
129 GLubyte const *pc =
130 __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply,
131 X_GLvop_GetSeparableFilterEXT, cmdlen);
132 unsigned compsize;
133
134
135 (void) memcpy((void *) (pc + 0), (void *) (&target), 4);
136 (void) memcpy((void *) (pc + 4), (void *) (&format), 4);
137 (void) memcpy((void *) (pc + 8), (void *) (&type), 4);
138 *(int8_t *) (pc + 12) = state->storePack.swapEndian;
139
140 (void) _XReply(dpy, (xReply *) & reply, 0, False);
141
142 compsize = reply.length << 2;
143
144 if (compsize != 0) {
145 const GLint width = reply.width;
146 const GLint height = reply.height;
147 const GLint widthsize =
148 __glImageSize(width, 1, 1, format, type, 0);
149 const GLint heightsize =
150 __glImageSize(height, 1, 1, format, type, 0);
151 GLubyte * const buf =
152 (GLubyte*) Xmalloc((widthsize > heightsize) ? widthsize : heightsize);
153
154 if (buf == NULL) {
155 /* Throw data away */
156 _XEatData(dpy, compsize);
157 __glXSetError(gc, GL_OUT_OF_MEMORY);
158
159 UnlockDisplay(dpy);
160 SyncHandle();
161 return;
162 } else {
163 int extra;
164
165 extra = 4 - (widthsize & 3);
166 _XRead(dpy, (char *)buf, widthsize);
167 if (extra < 4) {
168 _XEatData(dpy, extra);
169 }
170
171 __glEmptyImage(gc, 1, width, 1, 1, format, type, buf,
172 row);
173
174 extra = 4 - (heightsize & 3);
175 _XRead(dpy, (char *)buf, heightsize);
176 if (extra < 4) {
177 _XEatData(dpy, extra);
178 }
179
180 __glEmptyImage(gc, 1, height, 1, 1, format, type, buf,
181 column);
182
183 Xfree((char*) buf);
184 }
185 }
186 }
187 }
188 }