GLX: Change resulting from previous commit
[mesa.git] / src / glx / x11 / pixelstore.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 "glxclient.h"
32 #include "indirect.h"
33
34 /**
35 * Send glPixelStore command to the server
36 *
37 * \param gc Current GLX context
38 * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
39 * \param pname Selector of which pixel parameter is to be set.
40 * \param param Value that \c pname is set to.
41 *
42 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
43 */
44 static void
45 send_PixelStore(__GLXcontext * gc, unsigned sop, GLenum pname,
46 const void *param)
47 {
48 Display *const dpy = gc->currentDpy;
49 const GLuint cmdlen = 8;
50 if (__builtin_expect(dpy != NULL, 1)) {
51 GLubyte const *pc = __glXSetupSingleRequest(gc, sop, cmdlen);
52 (void) memcpy((void *) (pc + 0), (void *) (&pname), 4);
53 (void) memcpy((void *) (pc + 4), param, 4);
54 UnlockDisplay(dpy);
55 SyncHandle();
56 }
57 return;
58 }
59
60 /*
61 ** Specify parameters that control the storage format of pixel arrays.
62 */
63 void
64 __indirect_glPixelStoref(GLenum pname, GLfloat param)
65 {
66 __GLXcontext *gc = __glXGetCurrentContext();
67 __GLXattribute *state = gc->client_state_private;
68 Display *dpy = gc->currentDpy;
69 GLuint a;
70
71 if (!dpy)
72 return;
73
74 switch (pname) {
75 case GL_PACK_ROW_LENGTH:
76 a = (GLuint) (param + 0.5);
77 if (((GLint) a) < 0) {
78 __glXSetError(gc, GL_INVALID_VALUE);
79 return;
80 }
81 state->storePack.rowLength = a;
82 break;
83 case GL_PACK_IMAGE_HEIGHT:
84 a = (GLuint) (param + 0.5);
85 if (((GLint) a) < 0) {
86 __glXSetError(gc, GL_INVALID_VALUE);
87 return;
88 }
89 state->storePack.imageHeight = a;
90 break;
91 case GL_PACK_SKIP_ROWS:
92 a = (GLuint) (param + 0.5);
93 if (((GLint) a) < 0) {
94 __glXSetError(gc, GL_INVALID_VALUE);
95 return;
96 }
97 state->storePack.skipRows = a;
98 break;
99 case GL_PACK_SKIP_PIXELS:
100 a = (GLuint) (param + 0.5);
101 if (((GLint) a) < 0) {
102 __glXSetError(gc, GL_INVALID_VALUE);
103 return;
104 }
105 state->storePack.skipPixels = a;
106 break;
107 case GL_PACK_SKIP_IMAGES:
108 a = (GLuint) (param + 0.5);
109 if (((GLint) a) < 0) {
110 __glXSetError(gc, GL_INVALID_VALUE);
111 return;
112 }
113 state->storePack.skipImages = a;
114 break;
115 case GL_PACK_ALIGNMENT:
116 a = (GLint) (param + 0.5);
117 switch (a) {
118 case 1:
119 case 2:
120 case 4:
121 case 8:
122 state->storePack.alignment = a;
123 break;
124 default:
125 __glXSetError(gc, GL_INVALID_VALUE);
126 return;
127 }
128 break;
129 case GL_PACK_SWAP_BYTES:
130 state->storePack.swapEndian = (param != 0);
131 break;
132 case GL_PACK_LSB_FIRST:
133 state->storePack.lsbFirst = (param != 0);
134 break;
135
136 case GL_UNPACK_ROW_LENGTH:
137 a = (GLuint) (param + 0.5);
138 if (((GLint) a) < 0) {
139 __glXSetError(gc, GL_INVALID_VALUE);
140 return;
141 }
142 state->storeUnpack.rowLength = a;
143 break;
144 case GL_UNPACK_IMAGE_HEIGHT:
145 a = (GLuint) (param + 0.5);
146 if (((GLint) a) < 0) {
147 __glXSetError(gc, GL_INVALID_VALUE);
148 return;
149 }
150 state->storeUnpack.imageHeight = a;
151 break;
152 case GL_UNPACK_SKIP_ROWS:
153 a = (GLuint) (param + 0.5);
154 if (((GLint) a) < 0) {
155 __glXSetError(gc, GL_INVALID_VALUE);
156 return;
157 }
158 state->storeUnpack.skipRows = a;
159 break;
160 case GL_UNPACK_SKIP_PIXELS:
161 a = (GLuint) (param + 0.5);
162 if (((GLint) a) < 0) {
163 __glXSetError(gc, GL_INVALID_VALUE);
164 return;
165 }
166 state->storeUnpack.skipPixels = a;
167 break;
168 case GL_UNPACK_SKIP_IMAGES:
169 a = (GLuint) (param + 0.5);
170 if (((GLint) a) < 0) {
171 __glXSetError(gc, GL_INVALID_VALUE);
172 return;
173 }
174 state->storeUnpack.skipImages = a;
175 break;
176 case GL_UNPACK_ALIGNMENT:
177 a = (GLint) (param + 0.5);
178 switch (a) {
179 case 1:
180 case 2:
181 case 4:
182 case 8:
183 state->storeUnpack.alignment = a;
184 break;
185 default:
186 __glXSetError(gc, GL_INVALID_VALUE);
187 return;
188 }
189 break;
190 case GL_UNPACK_SWAP_BYTES:
191 state->storeUnpack.swapEndian = (param != 0);
192 break;
193 case GL_UNPACK_LSB_FIRST:
194 state->storeUnpack.lsbFirst = (param != 0);
195 break;
196
197 /* Group all of the pixel store modes that need to be sent to the
198 * server here. Care must be used to only send modes to the server that
199 * won't affect the size of the data sent to or received from the
200 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
201 * future modes may not be.
202 */
203 case GL_PACK_INVERT_MESA:
204 send_PixelStore(gc, X_GLsop_PixelStoref, pname, &param);
205 break;
206
207 default:
208 __glXSetError(gc, GL_INVALID_ENUM);
209 break;
210 }
211 }
212
213 void
214 __indirect_glPixelStorei(GLenum pname, GLint param)
215 {
216 __GLXcontext *gc = __glXGetCurrentContext();
217 __GLXattribute *state = gc->client_state_private;
218 Display *dpy = gc->currentDpy;
219
220 if (!dpy)
221 return;
222
223 switch (pname) {
224 case GL_PACK_ROW_LENGTH:
225 if (param < 0) {
226 __glXSetError(gc, GL_INVALID_VALUE);
227 return;
228 }
229 state->storePack.rowLength = param;
230 break;
231 case GL_PACK_IMAGE_HEIGHT:
232 if (param < 0) {
233 __glXSetError(gc, GL_INVALID_VALUE);
234 return;
235 }
236 state->storePack.imageHeight = param;
237 break;
238 case GL_PACK_SKIP_ROWS:
239 if (param < 0) {
240 __glXSetError(gc, GL_INVALID_VALUE);
241 return;
242 }
243 state->storePack.skipRows = param;
244 break;
245 case GL_PACK_SKIP_PIXELS:
246 if (param < 0) {
247 __glXSetError(gc, GL_INVALID_VALUE);
248 return;
249 }
250 state->storePack.skipPixels = param;
251 break;
252 case GL_PACK_SKIP_IMAGES:
253 if (param < 0) {
254 __glXSetError(gc, GL_INVALID_VALUE);
255 return;
256 }
257 state->storePack.skipImages = param;
258 break;
259 case GL_PACK_ALIGNMENT:
260 switch (param) {
261 case 1:
262 case 2:
263 case 4:
264 case 8:
265 state->storePack.alignment = param;
266 break;
267 default:
268 __glXSetError(gc, GL_INVALID_VALUE);
269 return;
270 }
271 break;
272 case GL_PACK_SWAP_BYTES:
273 state->storePack.swapEndian = (param != 0);
274 break;
275 case GL_PACK_LSB_FIRST:
276 state->storePack.lsbFirst = (param != 0);
277 break;
278
279 case GL_UNPACK_ROW_LENGTH:
280 if (param < 0) {
281 __glXSetError(gc, GL_INVALID_VALUE);
282 return;
283 }
284 state->storeUnpack.rowLength = param;
285 break;
286 case GL_UNPACK_IMAGE_HEIGHT:
287 if (param < 0) {
288 __glXSetError(gc, GL_INVALID_VALUE);
289 return;
290 }
291 state->storeUnpack.imageHeight = param;
292 break;
293 case GL_UNPACK_SKIP_ROWS:
294 if (param < 0) {
295 __glXSetError(gc, GL_INVALID_VALUE);
296 return;
297 }
298 state->storeUnpack.skipRows = param;
299 break;
300 case GL_UNPACK_SKIP_PIXELS:
301 if (param < 0) {
302 __glXSetError(gc, GL_INVALID_VALUE);
303 return;
304 }
305 state->storeUnpack.skipPixels = param;
306 break;
307 case GL_UNPACK_SKIP_IMAGES:
308 if (param < 0) {
309 __glXSetError(gc, GL_INVALID_VALUE);
310 return;
311 }
312 state->storeUnpack.skipImages = param;
313 break;
314 case GL_UNPACK_ALIGNMENT:
315 switch (param) {
316 case 1:
317 case 2:
318 case 4:
319 case 8:
320 state->storeUnpack.alignment = param;
321 break;
322 default:
323 __glXSetError(gc, GL_INVALID_VALUE);
324 return;
325 }
326 break;
327 case GL_UNPACK_SWAP_BYTES:
328 state->storeUnpack.swapEndian = (param != 0);
329 break;
330 case GL_UNPACK_LSB_FIRST:
331 state->storeUnpack.lsbFirst = (param != 0);
332 break;
333
334 /* Group all of the pixel store modes that need to be sent to the
335 * server here. Care must be used to only send modes to the server that
336 * won't affect the size of the data sent to or received from the
337 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
338 * future modes may not be.
339 */
340 case GL_PACK_INVERT_MESA:
341 send_PixelStore(gc, X_GLsop_PixelStorei, pname, &param);
342 break;
343
344 default:
345 __glXSetError(gc, GL_INVALID_ENUM);
346 break;
347 }
348 }