glx: indent -br -i3 -npcs --no-tabs xf86dri.h
[mesa.git] / src / glx / x11 / pixelstore.c
1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
2 /*
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 *
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
30 */
31
32 #include "glxclient.h"
33 #include "indirect.h"
34
35 /**
36 * Send glPixelStore command to the server
37 *
38 * \param gc Current GLX context
39 * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
40 * \param pname Selector of which pixel parameter is to be set.
41 * \param param Value that \c pname is set to.
42 *
43 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
44 */
45 static void
46 send_PixelStore(__GLXcontext * gc, unsigned sop, GLenum pname,
47 const void *param)
48 {
49 Display *const dpy = gc->currentDpy;
50 const GLuint cmdlen = 8;
51 if (__builtin_expect(dpy != NULL, 1)) {
52 GLubyte const *pc = __glXSetupSingleRequest(gc, sop, cmdlen);
53 (void) memcpy((void *) (pc + 0), (void *) (&pname), 4);
54 (void) memcpy((void *) (pc + 4), param, 4);
55 UnlockDisplay(dpy);
56 SyncHandle();
57 }
58 return;
59 }
60
61 /*
62 ** Specify parameters that control the storage format of pixel arrays.
63 */
64 void
65 __indirect_glPixelStoref(GLenum pname, GLfloat param)
66 {
67 __GLXcontext *gc = __glXGetCurrentContext();
68 __GLXattribute *state = gc->client_state_private;
69 Display *dpy = gc->currentDpy;
70 GLuint a;
71
72 if (!dpy)
73 return;
74
75 switch (pname) {
76 case GL_PACK_ROW_LENGTH:
77 a = (GLuint) (param + 0.5);
78 if (((GLint) a) < 0) {
79 __glXSetError(gc, GL_INVALID_VALUE);
80 return;
81 }
82 state->storePack.rowLength = a;
83 break;
84 case GL_PACK_IMAGE_HEIGHT:
85 a = (GLuint) (param + 0.5);
86 if (((GLint) a) < 0) {
87 __glXSetError(gc, GL_INVALID_VALUE);
88 return;
89 }
90 state->storePack.imageHeight = a;
91 break;
92 case GL_PACK_SKIP_ROWS:
93 a = (GLuint) (param + 0.5);
94 if (((GLint) a) < 0) {
95 __glXSetError(gc, GL_INVALID_VALUE);
96 return;
97 }
98 state->storePack.skipRows = a;
99 break;
100 case GL_PACK_SKIP_PIXELS:
101 a = (GLuint) (param + 0.5);
102 if (((GLint) a) < 0) {
103 __glXSetError(gc, GL_INVALID_VALUE);
104 return;
105 }
106 state->storePack.skipPixels = a;
107 break;
108 case GL_PACK_SKIP_IMAGES:
109 a = (GLuint) (param + 0.5);
110 if (((GLint) a) < 0) {
111 __glXSetError(gc, GL_INVALID_VALUE);
112 return;
113 }
114 state->storePack.skipImages = a;
115 break;
116 case GL_PACK_ALIGNMENT:
117 a = (GLint) (param + 0.5);
118 switch (a) {
119 case 1:
120 case 2:
121 case 4:
122 case 8:
123 state->storePack.alignment = a;
124 break;
125 default:
126 __glXSetError(gc, GL_INVALID_VALUE);
127 return;
128 }
129 break;
130 case GL_PACK_SWAP_BYTES:
131 state->storePack.swapEndian = (param != 0);
132 break;
133 case GL_PACK_LSB_FIRST:
134 state->storePack.lsbFirst = (param != 0);
135 break;
136
137 case GL_UNPACK_ROW_LENGTH:
138 a = (GLuint) (param + 0.5);
139 if (((GLint) a) < 0) {
140 __glXSetError(gc, GL_INVALID_VALUE);
141 return;
142 }
143 state->storeUnpack.rowLength = a;
144 break;
145 case GL_UNPACK_IMAGE_HEIGHT:
146 a = (GLuint) (param + 0.5);
147 if (((GLint) a) < 0) {
148 __glXSetError(gc, GL_INVALID_VALUE);
149 return;
150 }
151 state->storeUnpack.imageHeight = a;
152 break;
153 case GL_UNPACK_SKIP_ROWS:
154 a = (GLuint) (param + 0.5);
155 if (((GLint) a) < 0) {
156 __glXSetError(gc, GL_INVALID_VALUE);
157 return;
158 }
159 state->storeUnpack.skipRows = a;
160 break;
161 case GL_UNPACK_SKIP_PIXELS:
162 a = (GLuint) (param + 0.5);
163 if (((GLint) a) < 0) {
164 __glXSetError(gc, GL_INVALID_VALUE);
165 return;
166 }
167 state->storeUnpack.skipPixels = a;
168 break;
169 case GL_UNPACK_SKIP_IMAGES:
170 a = (GLuint) (param + 0.5);
171 if (((GLint) a) < 0) {
172 __glXSetError(gc, GL_INVALID_VALUE);
173 return;
174 }
175 state->storeUnpack.skipImages = a;
176 break;
177 case GL_UNPACK_ALIGNMENT:
178 a = (GLint) (param + 0.5);
179 switch (a) {
180 case 1:
181 case 2:
182 case 4:
183 case 8:
184 state->storeUnpack.alignment = a;
185 break;
186 default:
187 __glXSetError(gc, GL_INVALID_VALUE);
188 return;
189 }
190 break;
191 case GL_UNPACK_SWAP_BYTES:
192 state->storeUnpack.swapEndian = (param != 0);
193 break;
194 case GL_UNPACK_LSB_FIRST:
195 state->storeUnpack.lsbFirst = (param != 0);
196 break;
197
198 /* Group all of the pixel store modes that need to be sent to the
199 * server here. Care must be used to only send modes to the server that
200 * won't affect the size of the data sent to or received from the
201 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
202 * future modes may not be.
203 */
204 case GL_PACK_INVERT_MESA:
205 send_PixelStore(gc, X_GLsop_PixelStoref, pname, &param);
206 break;
207
208 default:
209 __glXSetError(gc, GL_INVALID_ENUM);
210 break;
211 }
212 }
213
214 void
215 __indirect_glPixelStorei(GLenum pname, GLint param)
216 {
217 __GLXcontext *gc = __glXGetCurrentContext();
218 __GLXattribute *state = gc->client_state_private;
219 Display *dpy = gc->currentDpy;
220
221 if (!dpy)
222 return;
223
224 switch (pname) {
225 case GL_PACK_ROW_LENGTH:
226 if (param < 0) {
227 __glXSetError(gc, GL_INVALID_VALUE);
228 return;
229 }
230 state->storePack.rowLength = param;
231 break;
232 case GL_PACK_IMAGE_HEIGHT:
233 if (param < 0) {
234 __glXSetError(gc, GL_INVALID_VALUE);
235 return;
236 }
237 state->storePack.imageHeight = param;
238 break;
239 case GL_PACK_SKIP_ROWS:
240 if (param < 0) {
241 __glXSetError(gc, GL_INVALID_VALUE);
242 return;
243 }
244 state->storePack.skipRows = param;
245 break;
246 case GL_PACK_SKIP_PIXELS:
247 if (param < 0) {
248 __glXSetError(gc, GL_INVALID_VALUE);
249 return;
250 }
251 state->storePack.skipPixels = param;
252 break;
253 case GL_PACK_SKIP_IMAGES:
254 if (param < 0) {
255 __glXSetError(gc, GL_INVALID_VALUE);
256 return;
257 }
258 state->storePack.skipImages = param;
259 break;
260 case GL_PACK_ALIGNMENT:
261 switch (param) {
262 case 1:
263 case 2:
264 case 4:
265 case 8:
266 state->storePack.alignment = param;
267 break;
268 default:
269 __glXSetError(gc, GL_INVALID_VALUE);
270 return;
271 }
272 break;
273 case GL_PACK_SWAP_BYTES:
274 state->storePack.swapEndian = (param != 0);
275 break;
276 case GL_PACK_LSB_FIRST:
277 state->storePack.lsbFirst = (param != 0);
278 break;
279
280 case GL_UNPACK_ROW_LENGTH:
281 if (param < 0) {
282 __glXSetError(gc, GL_INVALID_VALUE);
283 return;
284 }
285 state->storeUnpack.rowLength = param;
286 break;
287 case GL_UNPACK_IMAGE_HEIGHT:
288 if (param < 0) {
289 __glXSetError(gc, GL_INVALID_VALUE);
290 return;
291 }
292 state->storeUnpack.imageHeight = param;
293 break;
294 case GL_UNPACK_SKIP_ROWS:
295 if (param < 0) {
296 __glXSetError(gc, GL_INVALID_VALUE);
297 return;
298 }
299 state->storeUnpack.skipRows = param;
300 break;
301 case GL_UNPACK_SKIP_PIXELS:
302 if (param < 0) {
303 __glXSetError(gc, GL_INVALID_VALUE);
304 return;
305 }
306 state->storeUnpack.skipPixels = param;
307 break;
308 case GL_UNPACK_SKIP_IMAGES:
309 if (param < 0) {
310 __glXSetError(gc, GL_INVALID_VALUE);
311 return;
312 }
313 state->storeUnpack.skipImages = param;
314 break;
315 case GL_UNPACK_ALIGNMENT:
316 switch (param) {
317 case 1:
318 case 2:
319 case 4:
320 case 8:
321 state->storeUnpack.alignment = param;
322 break;
323 default:
324 __glXSetError(gc, GL_INVALID_VALUE);
325 return;
326 }
327 break;
328 case GL_UNPACK_SWAP_BYTES:
329 state->storeUnpack.swapEndian = (param != 0);
330 break;
331 case GL_UNPACK_LSB_FIRST:
332 state->storeUnpack.lsbFirst = (param != 0);
333 break;
334
335 /* Group all of the pixel store modes that need to be sent to the
336 * server here. Care must be used to only send modes to the server that
337 * won't affect the size of the data sent to or received from the
338 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
339 * future modes may not be.
340 */
341 case GL_PACK_INVERT_MESA:
342 send_PixelStore(gc, X_GLsop_PixelStorei, pname, &param);
343 break;
344
345 default:
346 __glXSetError(gc, GL_INVALID_ENUM);
347 break;
348 }
349 }