glx: add a line of Emacs helping variables
[mesa.git] / src / glx / x11 / singlepix.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 "packsingle.h"
33 #include "indirect.h"
34 #include "dispatch.h"
35 #include "glapi.h"
36 #include "glthread.h"
37 #include "glapioffsets.h"
38 #include <GL/glxproto.h>
39
40 void __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
41 GLvoid *row, GLvoid *column, GLvoid *span)
42 {
43 __GLX_SINGLE_DECLARE_VARIABLES();
44 const __GLXattribute * state;
45 xGLXGetSeparableFilterReply reply;
46 GLubyte *rowBuf, *colBuf;
47
48 if (!dpy) return;
49 __GLX_SINGLE_LOAD_VARIABLES();
50 state = gc->client_state_private;
51
52 /* Send request */
53 __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13));
54 __GLX_SINGLE_PUT_LONG(0,target);
55 __GLX_SINGLE_PUT_LONG(4,format);
56 __GLX_SINGLE_PUT_LONG(8,type);
57 __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
58 __GLX_SINGLE_READ_XREPLY();
59 compsize = reply.length << 2;
60
61 if (compsize != 0) {
62 GLint width, height;
63 GLint widthsize, heightsize;
64
65 width = reply.width;
66 height = reply.height;
67
68 widthsize = __glImageSize(width,1,1,format, type, 0);
69 heightsize = __glImageSize(height,1,1,format, type, 0);
70
71 /* Allocate a holding buffer to transform the data from */
72 rowBuf = (GLubyte*) Xmalloc(widthsize);
73 if (!rowBuf) {
74 /* Throw data away */
75 _XEatData(dpy, compsize);
76 __glXSetError(gc, GL_OUT_OF_MEMORY);
77 UnlockDisplay(dpy);
78 SyncHandle();
79 return;
80 } else {
81 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)rowBuf),widthsize);
82 __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
83 Xfree((char*) rowBuf);
84 }
85 colBuf = (GLubyte*) Xmalloc(heightsize);
86 if (!colBuf) {
87 /* Throw data away */
88 _XEatData(dpy, compsize - __GLX_PAD(widthsize));
89 __glXSetError(gc, GL_OUT_OF_MEMORY);
90 UnlockDisplay(dpy);
91 SyncHandle();
92 return;
93 } else {
94 __GLX_SINGLE_GET_CHAR_ARRAY(((char*)colBuf),heightsize);
95 __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column);
96 Xfree((char*) colBuf);
97 }
98 } else {
99 /*
100 ** don't modify user's buffer.
101 */
102 }
103 __GLX_SINGLE_END();
104
105 }
106
107
108 #define CONCAT(a,b) a ## b
109 #define NAME(o) CONCAT(gl_dispatch_stub_, o)
110
111 void NAME(_gloffset_GetSeparableFilter)(GLenum target, GLenum format, GLenum type,
112 GLvoid *row, GLvoid *column, GLvoid *span)
113 {
114 __GLXcontext * const gc = __glXGetCurrentContext();
115
116 #ifdef GLX_DIRECT_RENDERING
117 if (gc->driContext) {
118 CALL_GetSeparableFilter(GET_DISPATCH(),
119 (target, format, type, row, column, span));
120 return;
121 } else
122 #endif
123 {
124 Display *const dpy = gc->currentDpy;
125 const GLuint cmdlen = __GLX_PAD(13);
126
127 if (dpy != NULL) {
128 const __GLXattribute * const state = gc->client_state_private;
129 xGLXGetSeparableFilterReply reply;
130 GLubyte const *pc =
131 __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply,
132 X_GLvop_GetSeparableFilterEXT, cmdlen);
133 unsigned compsize;
134
135
136 (void) memcpy((void *) (pc + 0), (void *) (&target), 4);
137 (void) memcpy((void *) (pc + 4), (void *) (&format), 4);
138 (void) memcpy((void *) (pc + 8), (void *) (&type), 4);
139 *(int8_t *) (pc + 12) = state->storePack.swapEndian;
140
141 (void) _XReply(dpy, (xReply *) & reply, 0, False);
142
143 compsize = reply.length << 2;
144
145 if (compsize != 0) {
146 const GLint width = reply.width;
147 const GLint height = reply.height;
148 const GLint widthsize =
149 __glImageSize(width, 1, 1, format, type, 0);
150 const GLint heightsize =
151 __glImageSize(height, 1, 1, format, type, 0);
152 GLubyte * const buf =
153 (GLubyte*) Xmalloc((widthsize > heightsize) ? widthsize : heightsize);
154
155 if (buf == NULL) {
156 /* Throw data away */
157 _XEatData(dpy, compsize);
158 __glXSetError(gc, GL_OUT_OF_MEMORY);
159
160 UnlockDisplay(dpy);
161 SyncHandle();
162 return;
163 } else {
164 int extra;
165
166 extra = 4 - (widthsize & 3);
167 _XRead(dpy, (char *)buf, widthsize);
168 if (extra < 4) {
169 _XEatData(dpy, extra);
170 }
171
172 __glEmptyImage(gc, 1, width, 1, 1, format, type, buf,
173 row);
174
175 extra = 4 - (heightsize & 3);
176 _XRead(dpy, (char *)buf, heightsize);
177 if (extra < 4) {
178 _XEatData(dpy, extra);
179 }
180
181 __glEmptyImage(gc, 1, height, 1, 1, format, type, buf,
182 column);
183
184 Xfree((char*) buf);
185 }
186 }
187 }
188 }
189 }