1cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson/*
2dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson *
5dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Permission is hereby granted, free of charge, to any person obtaining a
6dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * copy of this software and associated documentation files (the "Software"),
7dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * to deal in the Software without restriction, including without limitation
8dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * and/or sell copies of the Software, and to permit persons to whom the
10dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Software is furnished to do so, subject to the following conditions:
11dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson *
12dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * The above copyright notice including the dates of first publication and
13dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * either this permission notice or a reference to
14dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * http://oss.sgi.com/projects/FreeB/
15dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * shall be included in all copies or substantial portions of the Software.
16dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson *
17dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * SOFTWARE.
24dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson *
25dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Except as contained in this notice, the name of Silicon Graphics, Inc.
26dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * shall not be used in advertising or otherwise to promote the sale, use or
27dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * other dealings in this Software without prior written authorization from
28dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Silicon Graphics, Inc.
29dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson */
30cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
31cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson#include "glxclient.h"
32f434e07a6ac849cd127d70eee8b3349da7cfb360Ian Romanick#include "indirect.h"
33cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
34016fc30839f0fb67bb37d4a7353a7e38749deab5Ian Romanick#if !defined(__GNUC__)
35707c017af68df24441e86b8a69831633a4106ca3Alan Coopersmith#  define __builtin_expect(x, y) x
36707c017af68df24441e86b8a69831633a4106ca3Alan Coopersmith#endif
37707c017af68df24441e86b8a69831633a4106ca3Alan Coopersmith
382e823f29e41d395c38804919076ba30f563266b5Ian Romanick/**
392e823f29e41d395c38804919076ba30f563266b5Ian Romanick * Send glPixelStore command to the server
402e823f29e41d395c38804919076ba30f563266b5Ian Romanick *
412e823f29e41d395c38804919076ba30f563266b5Ian Romanick * \param gc     Current GLX context
422e823f29e41d395c38804919076ba30f563266b5Ian Romanick * \param sop    Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
432e823f29e41d395c38804919076ba30f563266b5Ian Romanick * \param pname  Selector of which pixel parameter is to be set.
442e823f29e41d395c38804919076ba30f563266b5Ian Romanick * \param param  Value that \c pname is set to.
452e823f29e41d395c38804919076ba30f563266b5Ian Romanick *
462e823f29e41d395c38804919076ba30f563266b5Ian Romanick * \sa __indirect_glPixelStorei,  __indirect_glPixelStoref
472e823f29e41d395c38804919076ba30f563266b5Ian Romanick */
482e823f29e41d395c38804919076ba30f563266b5Ian Romanickstatic void
49c356f5867f2c1fad7155df538b9affa8dbdcf869Kristian Høgsbergsend_PixelStore(struct glx_context * gc, unsigned sop, GLenum pname,
5040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf                const void *param)
512e823f29e41d395c38804919076ba30f563266b5Ian Romanick{
5240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   Display *const dpy = gc->currentDpy;
5340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   const GLuint cmdlen = 8;
5440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   if (__builtin_expect(dpy != NULL, 1)) {
5540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      GLubyte const *pc = __glXSetupSingleRequest(gc, sop, cmdlen);
5640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      (void) memcpy((void *) (pc + 0), (void *) (&pname), 4);
5740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      (void) memcpy((void *) (pc + 4), param, 4);
5840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      UnlockDisplay(dpy);
5940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      SyncHandle();
6040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   }
6140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   return;
622e823f29e41d395c38804919076ba30f563266b5Ian Romanick}
632e823f29e41d395c38804919076ba30f563266b5Ian Romanick
64cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson/*
65cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson** Specify parameters that control the storage format of pixel arrays.
66cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson*/
6740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristófvoid
6840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf__indirect_glPixelStoref(GLenum pname, GLfloat param)
69cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson{
70c356f5867f2c1fad7155df538b9affa8dbdcf869Kristian Høgsberg   struct glx_context *gc = __glXGetCurrentContext();
7140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   __GLXattribute *state = gc->client_state_private;
7240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   Display *dpy = gc->currentDpy;
7340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   GLuint a;
74cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
7540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   if (!dpy)
7640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      return;
77cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
7840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   switch (pname) {
7940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_ROW_LENGTH:
8040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
8140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
8240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
8340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
8440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
8540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.rowLength = a;
8640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
8740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_IMAGE_HEIGHT:
8840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
8940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
9040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
9140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
9240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
9340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.imageHeight = a;
9440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
9540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SKIP_ROWS:
9640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
9740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
9840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
9940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
10040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
10140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.skipRows = a;
10240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
10340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SKIP_PIXELS:
10440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
10540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
10640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
10740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
10840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
10940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.skipPixels = a;
11040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
11140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SKIP_IMAGES:
11240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
11340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
11440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
11540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
11640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
11740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.skipImages = a;
11840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
11940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_ALIGNMENT:
12040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLint) (param + 0.5);
12140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      switch (a) {
12240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 1:
12340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 2:
12440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 4:
12540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 8:
12640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         state->storePack.alignment = a;
12740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         break;
12840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      default:
12940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
13040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
13140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
13240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
13340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SWAP_BYTES:
13440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.swapEndian = (param != 0);
13540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
13640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_LSB_FIRST:
13740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.lsbFirst = (param != 0);
13840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
139cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
14040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_ROW_LENGTH:
14140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
14240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
14340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
14440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
14540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
14640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.rowLength = a;
14740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
14840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_IMAGE_HEIGHT:
14940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
15040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
15140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
15240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
15340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
15440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.imageHeight = a;
15540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
15640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SKIP_ROWS:
15740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
15840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
15940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
16040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
16140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
16240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.skipRows = a;
16340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
16440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SKIP_PIXELS:
16540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
16640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
16740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
16840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
16940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
17040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.skipPixels = a;
17140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
17240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SKIP_IMAGES:
17340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLuint) (param + 0.5);
17440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (((GLint) a) < 0) {
17540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
17640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
17740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
17840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.skipImages = a;
17940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
18040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_ALIGNMENT:
18140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      a = (GLint) (param + 0.5);
18240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      switch (a) {
18340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 1:
18440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 2:
18540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 4:
18640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 8:
18740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         state->storeUnpack.alignment = a;
18840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         break;
18940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      default:
19040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
19140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
19240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
19340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
19440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SWAP_BYTES:
19540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.swapEndian = (param != 0);
19640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
19740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_LSB_FIRST:
19840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.lsbFirst = (param != 0);
19940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
2002e823f29e41d395c38804919076ba30f563266b5Ian Romanick
2012e823f29e41d395c38804919076ba30f563266b5Ian Romanick      /* Group all of the pixel store modes that need to be sent to the
2022e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * server here.  Care must be used to only send modes to the server that
2032e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * won't affect the size of the data sent to or received from the
2042e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * server.  GL_PACK_INVERT_MESA is safe in this respect, but other,
2052e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * future modes may not be.
2062e823f29e41d395c38804919076ba30f563266b5Ian Romanick       */
20740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_INVERT_MESA:
20840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      send_PixelStore(gc, X_GLsop_PixelStoref, pname, &param);
20940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
2102e823f29e41d395c38804919076ba30f563266b5Ian Romanick
21140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   default:
21240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      __glXSetError(gc, GL_INVALID_ENUM);
21340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
21440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   }
215cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson}
216cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
21740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristófvoid
21840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf__indirect_glPixelStorei(GLenum pname, GLint param)
219cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson{
220c356f5867f2c1fad7155df538b9affa8dbdcf869Kristian Høgsberg   struct glx_context *gc = __glXGetCurrentContext();
22140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   __GLXattribute *state = gc->client_state_private;
22240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   Display *dpy = gc->currentDpy;
223cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
22440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   if (!dpy)
22540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      return;
226cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
22740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   switch (pname) {
22840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_ROW_LENGTH:
22940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
23040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
23140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
23240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
23340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.rowLength = param;
23440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
23540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_IMAGE_HEIGHT:
23640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
23740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
23840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
23940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
24040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.imageHeight = param;
24140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
24240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SKIP_ROWS:
24340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
24440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
24540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
24640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
24740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.skipRows = param;
24840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
24940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SKIP_PIXELS:
25040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
25140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
25240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
25340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
25440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.skipPixels = param;
25540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
25640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SKIP_IMAGES:
25740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
25840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
25940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
26040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
26140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.skipImages = param;
26240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
26340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_ALIGNMENT:
26440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      switch (param) {
26540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 1:
26640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 2:
26740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 4:
26840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 8:
26940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         state->storePack.alignment = param;
27040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         break;
27140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      default:
27240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
27340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
27440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
27540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
27640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_SWAP_BYTES:
27740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.swapEndian = (param != 0);
27840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
27940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_LSB_FIRST:
28040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storePack.lsbFirst = (param != 0);
28140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
282cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson
28340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_ROW_LENGTH:
28440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
28540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
28640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
28740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
28840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.rowLength = param;
28940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
29040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_IMAGE_HEIGHT:
29140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
29240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
29340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
29440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
29540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.imageHeight = param;
29640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
29740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SKIP_ROWS:
29840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
29940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
30040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
30140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
30240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.skipRows = param;
30340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
30440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SKIP_PIXELS:
30540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
30640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
30740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
30840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
30940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.skipPixels = param;
31040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
31140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SKIP_IMAGES:
31240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      if (param < 0) {
31340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
31440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
31540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
31640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.skipImages = param;
31740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
31840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_ALIGNMENT:
31940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      switch (param) {
32040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 1:
32140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 2:
32240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 4:
32340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      case 8:
32440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         state->storeUnpack.alignment = param;
32540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         break;
32640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      default:
32740c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         __glXSetError(gc, GL_INVALID_VALUE);
32840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf         return;
32940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      }
33040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
33140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_SWAP_BYTES:
33240c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.swapEndian = (param != 0);
33340c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
33440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_UNPACK_LSB_FIRST:
33540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      state->storeUnpack.lsbFirst = (param != 0);
33640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
3372e823f29e41d395c38804919076ba30f563266b5Ian Romanick
3382e823f29e41d395c38804919076ba30f563266b5Ian Romanick      /* Group all of the pixel store modes that need to be sent to the
3392e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * server here.  Care must be used to only send modes to the server that
3402e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * won't affect the size of the data sent to or received from the
3412e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * server.  GL_PACK_INVERT_MESA is safe in this respect, but other,
3422e823f29e41d395c38804919076ba30f563266b5Ian Romanick       * future modes may not be.
3432e823f29e41d395c38804919076ba30f563266b5Ian Romanick       */
34440c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   case GL_PACK_INVERT_MESA:
34540c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      send_PixelStore(gc, X_GLsop_PixelStorei, pname, &param);
34640c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
3472e823f29e41d395c38804919076ba30f563266b5Ian Romanick
34840c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   default:
34940c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      __glXSetError(gc, GL_INVALID_ENUM);
35040c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf      break;
35140c481dc915909531dbcba2ae775dd9025b1a27eRALOVICH, Kristóf   }
352cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson}
353