2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
36 #include "glxserver.h"
37 #include "GL/glxproto.h"
39 #include "indirect_size.h"
40 #include "indirect_reqsize.h"
43 (((a & 0xff000000U)>>24) | ((a & 0xff0000U)>>8) | \
44 ((a & 0xff00U)<<8) | ((a & 0xffU)<<24))
47 Map1Size(GLint k
, GLint order
)
49 if (order
<= 0 || k
< 0)
55 __glXMap1dReqSize(const GLbyte
* pc
, Bool swap
)
60 target
= *(GLenum
*) (pc
+ 16);
61 order
= *(GLint
*) (pc
+ 20);
63 target
= SWAPL(target
);
66 k
= __glMap1d_size(target
);
67 return 8 * Map1Size(k
, order
);
71 __glXMap1fReqSize(const GLbyte
* pc
, Bool swap
)
76 target
= *(GLenum
*) (pc
+ 0);
77 order
= *(GLint
*) (pc
+ 12);
79 target
= SWAPL(target
);
82 k
= __glMap1f_size(target
);
83 return 4 * Map1Size(k
, order
);
87 Map2Size(int k
, int majorOrder
, int minorOrder
)
89 if (majorOrder
<= 0 || minorOrder
<= 0 || k
< 0)
91 return k
* majorOrder
* minorOrder
;
95 __glXMap2dReqSize(const GLbyte
* pc
, Bool swap
)
98 GLint uorder
, vorder
, k
;
100 target
= *(GLenum
*) (pc
+ 32);
101 uorder
= *(GLint
*) (pc
+ 36);
102 vorder
= *(GLint
*) (pc
+ 40);
104 target
= SWAPL(target
);
105 uorder
= SWAPL(uorder
);
106 vorder
= SWAPL(vorder
);
108 k
= __glMap2d_size(target
);
109 return 8 * Map2Size(k
, uorder
, vorder
);
113 __glXMap2fReqSize(const GLbyte
* pc
, Bool swap
)
116 GLint uorder
, vorder
, k
;
118 target
= *(GLenum
*) (pc
+ 0);
119 uorder
= *(GLint
*) (pc
+ 12);
120 vorder
= *(GLint
*) (pc
+ 24);
122 target
= SWAPL(target
);
123 uorder
= SWAPL(uorder
);
124 vorder
= SWAPL(vorder
);
126 k
= __glMap2f_size(target
);
127 return 4 * Map2Size(k
, uorder
, vorder
);
131 * Calculate the size of an image.
133 * The size of an image sent to the server from the client or sent from the
134 * server to the client is calculated. The size is based on the dimensions
135 * of the image, the type of pixel data, padding in the image, and the
136 * alignment requirements of the image.
138 * \param format Format of the pixels. Same as the \c format parameter
140 * \param type Type of the pixel data. Same as the \c type parameter
142 * \param target Typically the texture target of the image. If the
143 * target is one of \c GL_PROXY_*, the size returned is
144 * always zero. For uses that do not have a texture target
145 * (e.g, glDrawPixels), zero should be specified.
146 * \param w Width of the image data. Must be >= 1.
147 * \param h Height of the image data. Must be >= 1, even for 1D
149 * \param d Depth of the image data. Must be >= 1, even for 1D or
151 * \param imageHeight If non-zero, defines the true height of a volumetric
152 * image. This value will be used instead of \c h for
153 * calculating the size of the image.
154 * \param rowLength If non-zero, defines the true width of an image. This
155 * value will be used instead of \c w for calculating the
157 * \param skipImages Number of extra layers of image data in a volumtric
158 * image that are to be skipped before the real data.
159 * \param skipRows Number of extra rows of image data in an image that are
160 * to be skipped before the real data.
161 * \param alignment Specifies the alignment for the start of each pixel row
162 * in memory. This value must be one of 1, 2, 4, or 8.
165 * The size of the image is returned. If the specified \c format and \c type
166 * are invalid, -1 is returned. If \c target is one of \c GL_PROXY_*, zero
170 __glXImageSize(GLenum format
, GLenum type
, GLenum target
,
171 GLsizei w
, GLsizei h
, GLsizei d
,
172 GLint imageHeight
, GLint rowLength
,
173 GLint skipImages
, GLint skipRows
, GLint alignment
)
175 GLint bytesPerElement
, elementsPerGroup
, groupsPerRow
;
176 GLint groupSize
, rowSize
, padding
, imageSize
;
178 if (w
< 0 || h
< 0 || d
< 0 ||
179 (type
== GL_BITMAP
&&
180 (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
))) {
183 if (w
== 0 || h
== 0 || d
== 0)
187 case GL_PROXY_TEXTURE_1D
:
188 case GL_PROXY_TEXTURE_2D
:
189 case GL_PROXY_TEXTURE_3D
:
190 case GL_PROXY_TEXTURE_4D_SGIS
:
191 case GL_PROXY_TEXTURE_CUBE_MAP
:
192 case GL_PROXY_TEXTURE_RECTANGLE_ARB
:
193 case GL_PROXY_HISTOGRAM
:
194 case GL_PROXY_COLOR_TABLE
:
195 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
196 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
197 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
198 case GL_PROXY_POST_IMAGE_TRANSFORM_COLOR_TABLE_HP
:
202 if (type
== GL_BITMAP
) {
204 groupsPerRow
= rowLength
;
209 rowSize
= bits_to_bytes(groupsPerRow
);
210 padding
= (rowSize
% alignment
);
212 rowSize
+= alignment
- padding
;
214 return ((h
+ skipRows
) * rowSize
);
219 case GL_STENCIL_INDEX
:
220 case GL_DEPTH_COMPONENT
:
227 elementsPerGroup
= 1;
231 case GL_422_AVERAGE_EXT
:
232 case GL_422_REV_AVERAGE_EXT
:
233 case GL_DEPTH_STENCIL_NV
:
234 case GL_DEPTH_STENCIL_MESA
:
236 case GL_LUMINANCE_ALPHA
:
237 elementsPerGroup
= 2;
241 elementsPerGroup
= 3;
246 elementsPerGroup
= 4;
252 case GL_UNSIGNED_BYTE
:
256 case GL_UNSIGNED_BYTE_3_3_2
:
257 case GL_UNSIGNED_BYTE_2_3_3_REV
:
259 elementsPerGroup
= 1;
261 case GL_UNSIGNED_SHORT
:
265 case GL_UNSIGNED_SHORT_5_6_5
:
266 case GL_UNSIGNED_SHORT_5_6_5_REV
:
267 case GL_UNSIGNED_SHORT_4_4_4_4
:
268 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
269 case GL_UNSIGNED_SHORT_5_5_5_1
:
270 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
271 case GL_UNSIGNED_SHORT_8_8_APPLE
:
272 case GL_UNSIGNED_SHORT_8_8_REV_APPLE
:
273 case GL_UNSIGNED_SHORT_15_1_MESA
:
274 case GL_UNSIGNED_SHORT_1_15_REV_MESA
:
276 elementsPerGroup
= 1;
279 case GL_UNSIGNED_INT
:
283 case GL_UNSIGNED_INT_8_8_8_8
:
284 case GL_UNSIGNED_INT_8_8_8_8_REV
:
285 case GL_UNSIGNED_INT_10_10_10_2
:
286 case GL_UNSIGNED_INT_2_10_10_10_REV
:
287 case GL_UNSIGNED_INT_24_8_NV
:
288 case GL_UNSIGNED_INT_24_8_MESA
:
289 case GL_UNSIGNED_INT_8_24_REV_MESA
:
291 elementsPerGroup
= 1;
296 groupSize
= bytesPerElement
* elementsPerGroup
;
298 groupsPerRow
= rowLength
;
303 rowSize
= groupsPerRow
* groupSize
;
304 padding
= (rowSize
% alignment
);
306 rowSize
+= alignment
- padding
;
308 if (imageHeight
> 0) {
309 imageSize
= (imageHeight
+ skipRows
) * rowSize
;
312 imageSize
= (h
+ skipRows
) * rowSize
;
314 return ((d
+ skipImages
) * imageSize
);
318 /* XXX this is used elsewhere - should it be exported from glxserver.h? */
320 __glXTypeSize(GLenum enm
)
324 return sizeof(GLbyte
);
325 case GL_UNSIGNED_BYTE
:
326 return sizeof(GLubyte
);
328 return sizeof(GLshort
);
329 case GL_UNSIGNED_SHORT
:
330 return sizeof(GLushort
);
332 return sizeof(GLint
);
333 case GL_UNSIGNED_INT
:
334 return sizeof(GLint
);
336 return sizeof(GLfloat
);
338 return sizeof(GLdouble
);
345 __glXDrawArraysReqSize(const GLbyte
* pc
, Bool swap
)
347 __GLXdispatchDrawArraysHeader
*hdr
= (__GLXdispatchDrawArraysHeader
*) pc
;
348 __GLXdispatchDrawArraysComponentHeader
*compHeader
;
349 GLint numVertexes
= hdr
->numVertexes
;
350 GLint numComponents
= hdr
->numComponents
;
351 GLint arrayElementSize
= 0;
355 numVertexes
= SWAPL(numVertexes
);
356 numComponents
= SWAPL(numComponents
);
359 pc
+= sizeof(__GLXdispatchDrawArraysHeader
);
360 compHeader
= (__GLXdispatchDrawArraysComponentHeader
*) pc
;
362 for (i
= 0; i
< numComponents
; i
++) {
363 GLenum datatype
= compHeader
[i
].datatype
;
364 GLint numVals
= compHeader
[i
].numVals
;
365 GLint component
= compHeader
[i
].component
;
368 datatype
= SWAPL(datatype
);
369 numVals
= SWAPL(numVals
);
370 component
= SWAPL(component
);
374 case GL_VERTEX_ARRAY
:
376 case GL_TEXTURE_COORD_ARRAY
:
378 case GL_SECONDARY_COLOR_ARRAY
:
379 case GL_NORMAL_ARRAY
:
385 case GL_FOG_COORD_ARRAY
:
392 case GL_EDGE_FLAG_ARRAY
:
393 if ((numVals
!= 1) && (datatype
!= GL_UNSIGNED_BYTE
)) {
394 /* bad size or bad type */
399 /* unknown component type */
403 arrayElementSize
+= __GLX_PAD(numVals
* __glXTypeSize(datatype
));
405 pc
+= sizeof(__GLXdispatchDrawArraysComponentHeader
);
408 return ((numComponents
* sizeof(__GLXdispatchDrawArraysComponentHeader
)) +
409 (numVertexes
* arrayElementSize
));
413 __glXSeparableFilter2DReqSize(const GLbyte
* pc
, Bool swap
)
415 __GLXdispatchConvolutionFilterHeader
*hdr
=
416 (__GLXdispatchConvolutionFilterHeader
*) pc
;
418 GLint image1size
, image2size
;
419 GLenum format
= hdr
->format
;
420 GLenum type
= hdr
->type
;
421 GLint w
= hdr
->width
;
422 GLint h
= hdr
->height
;
423 GLint rowLength
= hdr
->rowLength
;
424 GLint alignment
= hdr
->alignment
;
427 format
= SWAPL(format
);
431 rowLength
= SWAPL(rowLength
);
432 alignment
= SWAPL(alignment
);
435 /* XXX Should rowLength be used for either or both image? */
436 image1size
= __glXImageSize(format
, type
, 0, w
, 1, 1,
437 0, rowLength
, 0, 0, alignment
);
438 image1size
= __GLX_PAD(image1size
);
439 image2size
= __glXImageSize(format
, type
, 0, h
, 1, 1,
440 0, rowLength
, 0, 0, alignment
);
441 return image1size
+ image2size
;