1 /* $XFree86: xc/lib/GL/glx/renderpix.c,v 1.5 2003/09/28 20:15:04 alanh Exp $ */
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:
11 ** http://oss.sgi.com/projects/FreeB
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.
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.
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.
38 * (C) Copyright IBM Corporation 2005
39 * All Rights Reserved.
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:
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
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
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
62 #include "packrender.h"
65 * Send a large image to the server. If necessary, a buffer is allocated
66 * to hold the unpacked data that is copied from the clients memory.
68 * \param gc Current GLX context
69 * \param compsize Size, in bytes, of the image portion
70 * \param dim Number of dimensions of the image
71 * \param width Width of the image
72 * \param height Height of the image, must be 1 for 1D images
73 * \param depth Depth of the image, must be 1 for 1D or 2D images
74 * \param format Format of the image
75 * \param type Data type of the image
76 * \param src Pointer to the image data
77 * \param pc Pointer to end of the command header
78 * \param modes Pointer to the pixel unpack data
81 * Modify this function so that \c NULL images are sent using
82 * \c __glXSendLargeChunk instead of __glXSendLargeCommand. Doing this
83 * will eliminate the need to allocate a buffer for that case.
86 * The \c fastImageUnpack path, which is thankfully never used, is completely
90 __glXSendLargeImage(__GLXcontext
*gc
, GLint compsize
, GLint dim
,
91 GLint width
, GLint height
, GLint depth
,
92 GLenum format
, GLenum type
, const GLvoid
*src
,
93 GLubyte
*pc
, GLubyte
*modes
)
95 if ( !gc
->fastImageUnpack
|| (src
== NULL
) ) {
96 /* Allocate a temporary holding buffer */
97 GLubyte
*buf
= (GLubyte
*) Xmalloc(compsize
);
99 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
103 /* Apply pixel store unpack modes to copy data into buf */
105 (*gc
->fillImage
)(gc
, dim
, width
, height
, depth
, format
, type
,
110 (void) memcpy( modes
, __glXDefaultPixelStore
+ 4, 20 );
113 (void) memcpy( modes
, __glXDefaultPixelStore
+ 0, 36 );
117 /* Send large command */
118 __glXSendLargeCommand(gc
, gc
->pc
, pc
- gc
->pc
, buf
, compsize
);
123 /* Just send the data straight as is */
124 __glXSendLargeCommand(gc
, gc
->pc
, pc
- gc
->pc
, pc
, compsize
);
128 /************************************************************************/
131 * Implement GLX protocol for \c glSeparableFilter2D.
134 * The \c fastImageUnpack path, which is thankfully never used, is completely
137 void __indirect_glSeparableFilter2D(GLenum target
, GLenum internalformat
,
138 GLsizei width
, GLsizei height
, GLenum format
,
139 GLenum type
, const GLvoid
*row
,
140 const GLvoid
*column
)
142 __GLX_DECLARE_VARIABLES();
143 GLuint compsize2
, hdrlen
, totalhdrlen
, image1len
, image2len
;
145 __GLX_LOAD_VARIABLES();
146 compsize
= __glImageSize(width
, 1, 1, format
, type
, 0);
147 compsize2
= __glImageSize(height
, 1, 1, format
, type
, 0);
148 totalhdrlen
= __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE
);
149 hdrlen
= __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE
);
150 image1len
= __GLX_PAD(compsize
);
151 image2len
= __GLX_PAD(compsize2
);
152 cmdlen
= totalhdrlen
+ image1len
+ image2len
;
153 if (!gc
->currentDpy
) return;
155 if (cmdlen
<= gc
->maxSmallRenderCommandSize
) {
156 /* Use GLXRender protocol to send small command */
157 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D
, cmdlen
);
158 __GLX_PUT_LONG(0,target
);
159 __GLX_PUT_LONG(4,internalformat
);
160 __GLX_PUT_LONG(8,width
);
161 __GLX_PUT_LONG(12,height
);
162 __GLX_PUT_LONG(16,format
);
163 __GLX_PUT_LONG(20,type
);
166 (*gc
->fillImage
)(gc
, 1, width
, 1, 1, format
, type
,
167 row
, pc
, pixelHeaderPC
);
171 (*gc
->fillImage
)(gc
, 1, height
, 1, 1, format
, type
,
175 if ((compsize
== 0) && (compsize2
== 0)) {
176 /* Setup default store modes */
177 (void) memcpy( pixelHeaderPC
, __glXDefaultPixelStore
+ 4, 20 );
181 const GLint bufsize
= image1len
+ image2len
;
183 /* Use GLXRenderLarge protocol to send command */
184 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D
,cmdlen
+4);
185 __GLX_PUT_LONG(0,target
);
186 __GLX_PUT_LONG(4,internalformat
);
187 __GLX_PUT_LONG(8,width
);
188 __GLX_PUT_LONG(12,height
);
189 __GLX_PUT_LONG(16,format
);
190 __GLX_PUT_LONG(20,type
);
193 if (!gc
->fastImageUnpack
) {
194 /* Allocate a temporary holding buffer */
195 GLubyte
*buf
= (GLubyte
*) Xmalloc(bufsize
);
197 __glXSetError(gc
, GL_OUT_OF_MEMORY
);
200 (*gc
->fillImage
)(gc
, 1, width
, 1, 1, format
, type
, row
, buf
, pixelHeaderPC
);
202 (*gc
->fillImage
)(gc
, 1, height
, 1, 1, format
, type
, column
,
203 buf
+ image1len
, pixelHeaderPC
);
205 /* Send large command */
206 __glXSendLargeCommand(gc
, gc
->pc
, (GLint
)(pc
- gc
->pc
), buf
, bufsize
);
210 /* Just send the data straight as is */
211 __glXSendLargeCommand(gc
, gc
->pc
, (GLint
)(pc
- gc
->pc
), pc
, bufsize
);