b7d01dc67957a0dc5059846390cf3a5aed93f6a6
[mesa.git] / src / glx / x11 / renderpix.c
1 /* $XFree86: xc/lib/GL/glx/renderpix.c,v 1.5 2003/09/28 20:15:04 alanh Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 /*
38 * (C) Copyright IBM Corporation 2005
39 * All Rights Reserved.
40 *
41 * Permission is hereby granted, free of charge, to any person obtaining a
42 * copy of this software and associated documentation files (the "Software"),
43 * to deal in the Software without restriction, including without limitation
44 * the rights to use, copy, modify, merge, publish, distribute, sub license,
45 * and/or sell copies of the Software, and to permit persons to whom the
46 * Software is furnished to do so, subject to the following conditions:
47 *
48 * The above copyright notice and this permission notice (including the next
49 * paragraph) shall be included in all copies or substantial portions of the
50 * Software.
51 *
52 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
55 * IBM,
56 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
57 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
58 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
59 * SOFTWARE.
60 */
61
62 #include "packrender.h"
63 #include "indirect.h"
64
65 /**
66 * Send a large image to the server. If necessary, a buffer is allocated
67 * to hold the unpacked data that is copied from the clients memory.
68 *
69 * \param gc Current GLX context
70 * \param compsize Size, in bytes, of the image portion
71 * \param dim Number of dimensions of the image
72 * \param width Width of the image
73 * \param height Height of the image, must be 1 for 1D images
74 * \param depth Depth of the image, must be 1 for 1D or 2D images
75 * \param format Format of the image
76 * \param type Data type of the image
77 * \param src Pointer to the image data
78 * \param pc Pointer to end of the command header
79 * \param modes Pointer to the pixel unpack data
80 *
81 * \todo
82 * Modify this function so that \c NULL images are sent using
83 * \c __glXSendLargeChunk instead of __glXSendLargeCommand. Doing this
84 * will eliminate the need to allocate a buffer for that case.
85 *
86 * \bugs
87 * The \c fastImageUnpack path, which is thankfully never used, is completely
88 * broken.
89 */
90 void
91 __glXSendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim,
92 GLint width, GLint height, GLint depth,
93 GLenum format, GLenum type, const GLvoid *src,
94 GLubyte *pc, GLubyte *modes)
95 {
96 if ( !gc->fastImageUnpack || (src == NULL) ) {
97 /* Allocate a temporary holding buffer */
98 GLubyte *buf = (GLubyte *) Xmalloc(compsize);
99 if (!buf) {
100 __glXSetError(gc, GL_OUT_OF_MEMORY);
101 return;
102 }
103
104 /* Apply pixel store unpack modes to copy data into buf */
105 if ( src != NULL ) {
106 (*gc->fillImage)(gc, dim, width, height, depth, format, type,
107 src, buf, modes);
108 }
109 else {
110 if ( dim < 3 ) {
111 (void) memcpy( modes, __glXDefaultPixelStore + 4, 20 );
112 }
113 else {
114 (void) memcpy( modes, __glXDefaultPixelStore + 0, 36 );
115 }
116 }
117
118 /* Send large command */
119 __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize);
120
121 /* Free buffer */
122 Xfree((char*) buf);
123 } else {
124 /* Just send the data straight as is */
125 __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, pc, compsize);
126 }
127 }
128
129 /************************************************************************/
130
131 /**
132 * Implement GLX protocol for \c glSeparableFilter2D.
133 *
134 * \bugs
135 * The \c fastImageUnpack path, which is thankfully never used, is completely
136 * broken.
137 */
138 void __indirect_glSeparableFilter2D(GLenum target, GLenum internalformat,
139 GLsizei width, GLsizei height, GLenum format,
140 GLenum type, const GLvoid *row,
141 const GLvoid *column)
142 {
143 __GLX_DECLARE_VARIABLES();
144 GLuint compsize2, hdrlen, totalhdrlen, image1len, image2len;
145
146 __GLX_LOAD_VARIABLES();
147 compsize = __glImageSize(width, 1, 1, format, type, 0);
148 compsize2 = __glImageSize(height, 1, 1, format, type, 0);
149 totalhdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE);
150 hdrlen = __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE);
151 image1len = __GLX_PAD(compsize);
152 image2len = __GLX_PAD(compsize2);
153 cmdlen = totalhdrlen + image1len + image2len;
154 if (!gc->currentDpy) return;
155
156 if (cmdlen <= gc->maxSmallRenderCommandSize) {
157 /* Use GLXRender protocol to send small command */
158 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D, cmdlen);
159 __GLX_PUT_LONG(0,target);
160 __GLX_PUT_LONG(4,internalformat);
161 __GLX_PUT_LONG(8,width);
162 __GLX_PUT_LONG(12,height);
163 __GLX_PUT_LONG(16,format);
164 __GLX_PUT_LONG(20,type);
165 pc += hdrlen;
166 if (compsize > 0) {
167 (*gc->fillImage)(gc, 1, width, 1, 1, format, type,
168 row, pc, pixelHeaderPC);
169 pc += image1len;
170 }
171 if (compsize2 > 0) {
172 (*gc->fillImage)(gc, 1, height, 1, 1, format, type,
173 column, pc, NULL);
174 pc += image2len;
175 }
176 if ((compsize == 0) && (compsize2 == 0)) {
177 /* Setup default store modes */
178 (void) memcpy( pixelHeaderPC, __glXDefaultPixelStore + 4, 20 );
179 }
180 __GLX_END(0);
181 } else {
182 const GLint bufsize = image1len + image2len;
183
184 /* Use GLXRenderLarge protocol to send command */
185 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D,cmdlen+4);
186 __GLX_PUT_LONG(0,target);
187 __GLX_PUT_LONG(4,internalformat);
188 __GLX_PUT_LONG(8,width);
189 __GLX_PUT_LONG(12,height);
190 __GLX_PUT_LONG(16,format);
191 __GLX_PUT_LONG(20,type);
192 pc += hdrlen;
193
194 if (!gc->fastImageUnpack) {
195 /* Allocate a temporary holding buffer */
196 GLubyte *buf = (GLubyte *) Xmalloc(bufsize);
197 if (!buf) {
198 __glXSetError(gc, GL_OUT_OF_MEMORY);
199 return;
200 }
201 (*gc->fillImage)(gc, 1, width, 1, 1, format, type, row, buf, pixelHeaderPC);
202
203 (*gc->fillImage)(gc, 1, height, 1, 1, format, type, column,
204 buf + image1len, pixelHeaderPC);
205
206 /* Send large command */
207 __glXSendLargeCommand(gc, gc->pc, (GLint)(pc - gc->pc), buf, bufsize);
208 /* Free buffer */
209 Xfree((char*) buf);
210 } else {
211 /* Just send the data straight as is */
212 __glXSendLargeCommand(gc, gc->pc, (GLint)(pc - gc->pc), pc, bufsize);
213 }
214 }
215 }