gallium/draw: initial code to properly support llvm in the draw module
[mesa.git] / src / mesa / drivers / dri / swrast / swrast_spantemp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /*
27 * Modified version of swrast/s_spantemp.h for front-buffer rendering. The
28 * no-mask paths use a scratch row to avoid repeated calls to the loader.
29 *
30 * For the mask paths we always use an array of 4 elements of RB_TYPE. This is
31 * to satisfy the xorg loader requirement of an image pitch of 32 bits and
32 * should be ok for other loaders also.
33 */
34
35
36 #ifndef _SWRAST_SPANTEMP_ONCE
37 #define _SWRAST_SPANTEMP_ONCE
38
39 static INLINE void
40 PUT_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p )
41 {
42 __DRIcontext *ctx = swrast_context(glCtx);
43 __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer);
44
45 __DRIscreen *screen = ctx->driScreenPriv;
46
47 screen->swrast_loader->putImage(draw, __DRI_SWRAST_IMAGE_OP_DRAW,
48 x, y, 1, 1, (char *)p,
49 draw->loaderPrivate);
50 }
51
52
53 static INLINE void
54 GET_PIXEL( GLcontext *glCtx, GLint x, GLint y, GLubyte *p )
55 {
56 __DRIcontext *ctx = swrast_context(glCtx);
57 __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer);
58
59 __DRIscreen *screen = ctx->driScreenPriv;
60
61 screen->swrast_loader->getImage(read, x, y, 1, 1, (char *)p,
62 read->loaderPrivate);
63 }
64
65 static INLINE void
66 PUT_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row )
67 {
68 __DRIcontext *ctx = swrast_context(glCtx);
69 __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer);
70
71 __DRIscreen *screen = ctx->driScreenPriv;
72
73 screen->swrast_loader->putImage(draw, __DRI_SWRAST_IMAGE_OP_DRAW,
74 x, y, n, 1, row,
75 draw->loaderPrivate);
76 }
77
78 static INLINE void
79 GET_ROW( GLcontext *glCtx, GLint x, GLint y, GLuint n, char *row )
80 {
81 __DRIcontext *ctx = swrast_context(glCtx);
82 __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer);
83
84 __DRIscreen *screen = ctx->driScreenPriv;
85
86 screen->swrast_loader->getImage(read, x, y, n, 1, row,
87 read->loaderPrivate);
88 }
89
90 #endif /* _SWRAST_SPANTEMP_ONCE */
91
92
93 /*
94 * Templates for the span/pixel-array write/read functions called via
95 * the gl_renderbuffer's GetRow, GetValues, PutRow, PutMonoRow, PutValues
96 * and PutMonoValues functions.
97 *
98 * Define the following macros before including this file:
99 * NAME(BASE) to generate the function name (i.e. add prefix or suffix)
100 * RB_TYPE the renderbuffer DataType
101 * CI_MODE if set, color index mode, else RGBA
102 * SPAN_VARS to declare any local variables
103 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
104 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
105 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
106 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
107 *
108 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
109 * for the pixels to be stored. This is useful when dithering and probably
110 * ignored otherwise.
111 */
112
113 #include "main/macros.h"
114
115
116 #ifdef CI_MODE
117 #define RB_COMPONENTS 1
118 #elif !defined(RB_COMPONENTS)
119 #define RB_COMPONENTS 4
120 #endif
121
122
123 static void
124 NAME(get_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
125 GLuint count, GLint x, GLint y, void *values )
126 {
127 #ifdef SPAN_VARS
128 SPAN_VARS
129 #endif
130 #ifdef CI_MODE
131 RB_TYPE *dest = (RB_TYPE *) values;
132 #else
133 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
134 #endif
135 GLuint i;
136 char *row = swrast_drawable(ctx->ReadBuffer)->row;
137 INIT_PIXEL_PTR(pixel, x, y);
138 GET_ROW( ctx, x, YFLIP(xrb, y), count, row );
139 for (i = 0; i < count; i++) {
140 FETCH_PIXEL(dest[i], pixel);
141 INC_PIXEL_PTR(pixel);
142 }
143 (void) rb;
144 }
145
146
147 static void
148 NAME(get_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
149 GLuint count, const GLint x[], const GLint y[], void *values )
150 {
151 #ifdef SPAN_VARS
152 SPAN_VARS
153 #endif
154 #ifdef CI_MODE
155 RB_TYPE *dest = (RB_TYPE *) values;
156 #else
157 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
158 #endif
159 GLuint i;
160 for (i = 0; i < count; i++) {
161 RB_TYPE pixel[4];
162 GET_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
163 FETCH_PIXEL(dest[i], pixel);
164 }
165 (void) rb;
166 }
167
168
169 static void
170 NAME(put_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
171 GLuint count, GLint x, GLint y,
172 const void *values, const GLubyte mask[] )
173 {
174 #ifdef SPAN_VARS
175 SPAN_VARS
176 #endif
177 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
178 GLuint i;
179 if (mask) {
180 for (i = 0; i < count; i++) {
181 if (mask[i]) {
182 RB_TYPE pixel[4];
183 STORE_PIXEL(pixel, x + i, y, src[i]);
184 PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
185 }
186 }
187 }
188 else {
189 char *row = swrast_drawable(ctx->DrawBuffer)->row;
190 INIT_PIXEL_PTR(pixel, x, y);
191 for (i = 0; i < count; i++) {
192 STORE_PIXEL(pixel, x + i, y, src[i]);
193 INC_PIXEL_PTR(pixel);
194 }
195 PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
196 }
197 (void) rb;
198 }
199
200
201 #if !defined(CI_MODE)
202 static void
203 NAME(put_row_rgb)( GLcontext *ctx, struct gl_renderbuffer *rb,
204 GLuint count, GLint x, GLint y,
205 const void *values, const GLubyte mask[] )
206 {
207 #ifdef SPAN_VARS
208 SPAN_VARS
209 #endif
210 const RB_TYPE (*src)[3] = (const RB_TYPE (*)[3]) values;
211 GLuint i;
212 if (mask) {
213 for (i = 0; i < count; i++) {
214 if (mask[i]) {
215 RB_TYPE pixel[4];
216 #ifdef STORE_PIXEL_RGB
217 STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
218 #else
219 STORE_PIXEL(pixel, x + i, y, src[i]);
220 #endif
221 PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
222 }
223 }
224 }
225 else {
226 char *row = swrast_drawable(ctx->DrawBuffer)->row;
227 INIT_PIXEL_PTR(pixel, x, y);
228 for (i = 0; i < count; i++) {
229 #ifdef STORE_PIXEL_RGB
230 STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
231 #else
232 STORE_PIXEL(pixel, x + i, y, src[i]);
233 #endif
234 INC_PIXEL_PTR(pixel);
235 }
236 PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
237 }
238 (void) rb;
239 }
240 #endif
241
242
243 static void
244 NAME(put_mono_row)( GLcontext *ctx, struct gl_renderbuffer *rb,
245 GLuint count, GLint x, GLint y,
246 const void *value, const GLubyte mask[] )
247 {
248 #ifdef SPAN_VARS
249 SPAN_VARS
250 #endif
251 const RB_TYPE *src = (const RB_TYPE *) value;
252 GLuint i;
253 if (mask) {
254 for (i = 0; i < count; i++) {
255 if (mask[i]) {
256 RB_TYPE pixel[4];
257 STORE_PIXEL(pixel, x + i, y, src);
258 PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
259 }
260 }
261 }
262 else {
263 char *row = swrast_drawable(ctx->DrawBuffer)->row;
264 INIT_PIXEL_PTR(pixel, x, y);
265 for (i = 0; i < count; i++) {
266 STORE_PIXEL(pixel, x + i, y, src);
267 INC_PIXEL_PTR(pixel);
268 }
269 PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
270 }
271 (void) rb;
272 }
273
274
275 static void
276 NAME(put_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
277 GLuint count, const GLint x[], const GLint y[],
278 const void *values, const GLubyte mask[] )
279 {
280 #ifdef SPAN_VARS
281 SPAN_VARS
282 #endif
283 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
284 GLuint i;
285 ASSERT(mask);
286 for (i = 0; i < count; i++) {
287 if (mask[i]) {
288 RB_TYPE pixel[4];
289 STORE_PIXEL(pixel, x[i], y[i], src[i]);
290 PUT_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
291 }
292 }
293 (void) rb;
294 }
295
296
297 static void
298 NAME(put_mono_values)( GLcontext *ctx, struct gl_renderbuffer *rb,
299 GLuint count, const GLint x[], const GLint y[],
300 const void *value, const GLubyte mask[] )
301 {
302 #ifdef SPAN_VARS
303 SPAN_VARS
304 #endif
305 const RB_TYPE *src = (const RB_TYPE *) value;
306 GLuint i;
307 ASSERT(mask);
308 for (i = 0; i < count; i++) {
309 if (mask[i]) {
310 RB_TYPE pixel[4];
311 STORE_PIXEL(pixel, x[i], y[i], src);
312 PUT_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
313 }
314 }
315 (void) rb;
316 }
317
318
319 #undef NAME
320 #undef RB_TYPE
321 #undef RB_COMPONENTS
322 #undef CI_MODE
323 #undef SPAN_VARS
324 #undef INIT_PIXEL_PTR
325 #undef INC_PIXEL_PTR
326 #undef STORE_PIXEL
327 #undef STORE_PIXEL_RGB
328 #undef FETCH_PIXEL