1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/*
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the "Software"),
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to deal in the Software without restriction, including without limitation
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * and/or sell copies of the Software, and to permit persons to whom the
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Software is furnished to do so, subject to the following conditions:
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice including the dates of first publication and
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * either this permission notice or a reference to
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * http://oss.sgi.com/projects/FreeB/
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * shall be included in all copies or substantial portions of the Software.
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE.
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Except as contained in this notice, the name of Silicon Graphics, Inc.
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * shall not be used in advertising or otherwise to promote the sale, use or
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * other dealings in this Software without prior written authorization from
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Silicon Graphics, Inc.
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "packsingle.h"
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "indirect.h"
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glapi.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "glthread.h"
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <GL/glxproto.h>
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org__indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                GLvoid * row, GLvoid * column, GLvoid * span)
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_DECLARE_VARIABLES();
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const __GLXattribute *state;
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   xGLXGetSeparableFilterReply reply;
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   GLubyte *rowBuf, *colBuf;
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!dpy)
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_LOAD_VARIABLES();
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   state = gc->client_state_private;
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Send request */
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13));
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_PUT_LONG(0, target);
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_PUT_LONG(4, format);
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_PUT_LONG(8, type);
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_PUT_CHAR(12, state->storePack.swapEndian);
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_READ_XREPLY();
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   compsize = reply.length << 2;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (compsize != 0) {
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint width, height;
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      GLint widthsize, heightsize;
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      width = reply.width;
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      height = reply.height;
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      widthsize = __glImageSize(width, 1, 1, format, type, 0);
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      heightsize = __glImageSize(height, 1, 1, format, type, 0);
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* Allocate a holding buffer to transform the data from */
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      rowBuf = (GLubyte *) Xmalloc(widthsize);
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!rowBuf) {
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         /* Throw data away */
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         _XEatData(dpy, compsize);
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         __glXSetError(gc, GL_OUT_OF_MEMORY);
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         UnlockDisplay(dpy);
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         SyncHandle();
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return;
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      else {
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         __GLX_SINGLE_GET_CHAR_ARRAY(((char *) rowBuf), widthsize);
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         Xfree((char *) rowBuf);
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      colBuf = (GLubyte *) Xmalloc(heightsize);
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (!colBuf) {
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         /* Throw data away */
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         _XEatData(dpy, compsize - __GLX_PAD(widthsize));
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         __glXSetError(gc, GL_OUT_OF_MEMORY);
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         UnlockDisplay(dpy);
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         SyncHandle();
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         return;
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      else {
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         __GLX_SINGLE_GET_CHAR_ARRAY(((char *) colBuf), heightsize);
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column);
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         Xfree((char *) colBuf);
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else {
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /*
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       ** don't modify user's buffer.
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       */
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   __GLX_SINGLE_END();
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* it is defined to gl_dispatch_stub_NNN in indirect.h */
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid gl_dispatch_stub_GetSeparableFilterEXT (GLenum target, GLenum format,
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             GLenum type, GLvoid * row,
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                             GLvoid * column, GLvoid * span)
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct glx_context *const gc = __glXGetCurrentContext();
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (gc->isDirect) {
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const _glapi_proc *const table = (_glapi_proc *) GET_DISPATCH();
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      PFNGLGETSEPARABLEFILTEREXTPROC p =
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         (PFNGLGETSEPARABLEFILTEREXTPROC) table[359];
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      p(target, format, type, row, column, span);
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return;
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   else
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   {
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      Display *const dpy = gc->currentDpy;
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      const GLuint cmdlen = __GLX_PAD(13);
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (dpy != NULL) {
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         const __GLXattribute *const state = gc->client_state_private;
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         xGLXGetSeparableFilterReply reply;
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         GLubyte const *pc =
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply,
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                    X_GLvop_GetSeparableFilterEXT, cmdlen);
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         unsigned compsize;
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         (void) memcpy((void *) (pc + 0), (void *) (&target), 4);
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         (void) memcpy((void *) (pc + 4), (void *) (&format), 4);
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         (void) memcpy((void *) (pc + 8), (void *) (&type), 4);
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         *(int8_t *) (pc + 12) = state->storePack.swapEndian;
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         (void) _XReply(dpy, (xReply *) & reply, 0, False);
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         compsize = reply.length << 2;
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         if (compsize != 0) {
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const GLint width = reply.width;
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const GLint height = reply.height;
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const GLint widthsize =
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               __glImageSize(width, 1, 1, format, type, 0);
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            const GLint heightsize =
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               __glImageSize(height, 1, 1, format, type, 0);
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            GLubyte *const buf =
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               (GLubyte *) Xmalloc((widthsize > heightsize) ? widthsize :
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                   heightsize);
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            if (buf == NULL) {
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               /* Throw data away */
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               _XEatData(dpy, compsize);
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               __glXSetError(gc, GL_OUT_OF_MEMORY);
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               UnlockDisplay(dpy);
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               SyncHandle();
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               return;
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            else {
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               int extra;
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               extra = 4 - (widthsize & 3);
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               _XRead(dpy, (char *) buf, widthsize);
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               if (extra < 4) {
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                  _XEatData(dpy, extra);
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               }
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, row);
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               extra = 4 - (heightsize & 3);
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               _XRead(dpy, (char *) buf, heightsize);
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               if (extra < 4) {
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                  _XEatData(dpy, extra);
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               }
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               __glEmptyImage(gc, 1, height, 1, 1, format, type, buf, column);
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               Xfree((char *) buf);
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org            }
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         }
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
195