Tizen 2.0 Release
[profile/ivi/osmesa.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( struct gl_context *glCtx, GLint x, GLint y, GLvoid *p )
41 {
42     __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
43     __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer)->dPriv;
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( struct gl_context *glCtx, GLint x, GLint y, GLubyte *p )
55 {
56     __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
57     __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer)->dPriv;
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( struct gl_context *glCtx, GLint x, GLint y, GLuint n, char *row )
67 {
68     __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
69     __DRIdrawable *draw = swrast_drawable(glCtx->DrawBuffer)->dPriv;
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( struct gl_context *glCtx, GLint x, GLint y, GLuint n, char *row )
80 {
81     __DRIcontext *ctx = swrast_context(glCtx)->cPriv;
82     __DRIdrawable *read = swrast_drawable(glCtx->ReadBuffer)->dPriv;
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  *   SPAN_VARS  to declare any local variables
102  *   INIT_PIXEL_PTR(P, X, Y)  to initialize a pointer to a pixel
103  *   INC_PIXEL_PTR(P)  to increment a pixel pointer by one pixel
104  *   STORE_PIXEL(DST, X, Y, VALUE)  to store pixel values in buffer
105  *   FETCH_PIXEL(DST, SRC)  to fetch pixel values from buffer
106  *
107  * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
108  * for the pixels to be stored.  This is useful when dithering and probably
109  * ignored otherwise.
110  */
111
112 #include "main/macros.h"
113
114
115 #if !defined(RB_COMPONENTS)
116 #define RB_COMPONENTS 4
117 #endif
118
119
120 static void
121 NAME(get_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
122                GLuint count, GLint x, GLint y, void *values )
123 {
124 #ifdef SPAN_VARS
125    SPAN_VARS
126 #endif
127    RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
128    GLuint i;
129    char *row = swrast_drawable(ctx->ReadBuffer)->row;
130    INIT_PIXEL_PTR(pixel, x, y);
131    GET_ROW( ctx, x, YFLIP(xrb, y), count, row );
132    for (i = 0; i < count; i++) {
133       FETCH_PIXEL(dest[i], pixel);
134       INC_PIXEL_PTR(pixel);
135    }
136    (void) rb;
137 }
138
139
140 static void
141 NAME(get_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
142                   GLuint count, const GLint x[], const GLint y[], void *values )
143 {
144 #ifdef SPAN_VARS
145    SPAN_VARS
146 #endif
147    RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
148    GLuint i;
149    for (i = 0; i < count; i++) {
150       RB_TYPE pixel[4];
151       GET_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
152       FETCH_PIXEL(dest[i], pixel);
153    }
154    (void) rb;
155 }
156
157
158 static void
159 NAME(put_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
160                GLuint count, GLint x, GLint y,
161                const void *values, const GLubyte mask[] )
162 {
163 #ifdef SPAN_VARS
164    SPAN_VARS
165 #endif
166    const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
167    GLuint i;
168    if (mask) {
169       for (i = 0; i < count; i++) {
170          if (mask[i]) {
171             RB_TYPE row[4];
172             INIT_PIXEL_PTR(pixel, x, y);
173             STORE_PIXEL(pixel, x + i, y, src[i]);
174             PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
175          }
176       }
177    }
178    else {
179       char *row = swrast_drawable(ctx->DrawBuffer)->row;
180       INIT_PIXEL_PTR(pixel, x, y);
181       for (i = 0; i < count; i++) {
182          STORE_PIXEL(pixel, x + i, y, src[i]);
183          INC_PIXEL_PTR(pixel);
184       }
185       PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
186    }
187    (void) rb;
188 }
189
190
191 static void
192 NAME(put_row_rgb)( struct gl_context *ctx, struct gl_renderbuffer *rb,
193                    GLuint count, GLint x, GLint y,
194                    const void *values, const GLubyte mask[] )
195 {
196 #ifdef SPAN_VARS
197    SPAN_VARS
198 #endif
199    const RB_TYPE (*src)[3] = (const RB_TYPE (*)[3]) values;
200    GLuint i;
201    if (mask) {
202       for (i = 0; i < count; i++) {
203          if (mask[i]) {
204             RB_TYPE row[4];
205             INIT_PIXEL_PTR(pixel, x, y);
206 #ifdef STORE_PIXEL_RGB
207             STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
208 #else
209             STORE_PIXEL(pixel, x + i, y, src[i]);
210 #endif
211             PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
212          }
213       }
214    }
215    else {
216       char *row = swrast_drawable(ctx->DrawBuffer)->row;
217       INIT_PIXEL_PTR(pixel, x, y);
218       for (i = 0; i < count; i++) {
219 #ifdef STORE_PIXEL_RGB
220          STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
221 #else
222          STORE_PIXEL(pixel, x + i, y, src[i]);
223 #endif
224          INC_PIXEL_PTR(pixel);
225       }
226       PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
227    }
228    (void) rb;
229 }
230
231
232 static void
233 NAME(put_mono_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
234                     GLuint count, GLint x, GLint y,
235                     const void *value, const GLubyte mask[] )
236 {
237 #ifdef SPAN_VARS
238    SPAN_VARS
239 #endif
240    const RB_TYPE *src = (const RB_TYPE *) value;
241    GLuint i;
242    if (mask) {
243       for (i = 0; i < count; i++) {
244          if (mask[i]) {
245             RB_TYPE row[4];
246             INIT_PIXEL_PTR(pixel, x, y);
247             STORE_PIXEL(pixel, x + i, y, src);
248             PUT_PIXEL(ctx, x + i, YFLIP(xrb, y), pixel);
249          }
250       }
251    }
252    else {
253       char *row = swrast_drawable(ctx->DrawBuffer)->row;
254       INIT_PIXEL_PTR(pixel, x, y);
255       for (i = 0; i < count; i++) {
256          STORE_PIXEL(pixel, x + i, y, src);
257          INC_PIXEL_PTR(pixel);
258       }
259       PUT_ROW( ctx, x, YFLIP(xrb, y), count, row );
260    }
261    (void) rb;
262 }
263
264
265 static void
266 NAME(put_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
267                   GLuint count, const GLint x[], const GLint y[],
268                   const void *values, const GLubyte mask[] )
269 {
270 #ifdef SPAN_VARS
271    SPAN_VARS
272 #endif
273    const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
274    GLuint i;
275    ASSERT(mask);
276    for (i = 0; i < count; i++) {
277       if (mask[i]) {
278          RB_TYPE row[4];
279          INIT_PIXEL_PTR(pixel, x, y);
280          STORE_PIXEL(pixel, x[i], y[i], src[i]);
281          PUT_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
282       }
283    }
284    (void) rb;
285 }
286
287
288 static void
289 NAME(put_mono_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
290                        GLuint count, const GLint x[], const GLint y[],
291                        const void *value, const GLubyte mask[] )
292 {
293 #ifdef SPAN_VARS
294    SPAN_VARS
295 #endif
296    const RB_TYPE *src = (const RB_TYPE *) value;
297    GLuint i;
298    ASSERT(mask);
299    for (i = 0; i < count; i++) {
300       if (mask[i]) {
301          RB_TYPE row[4];
302          INIT_PIXEL_PTR(pixel, x, y);
303          STORE_PIXEL(pixel, x[i], y[i], src);
304          PUT_PIXEL(ctx, x[i], YFLIP(xrb, y[i]), pixel);
305       }
306    }
307    (void) rb;
308 }
309
310
311 #undef NAME
312 #undef RB_TYPE
313 #undef RB_COMPONENTS
314 #undef SPAN_VARS
315 #undef INIT_PIXEL_PTR
316 #undef INC_PIXEL_PTR
317 #undef STORE_PIXEL
318 #undef STORE_PIXEL_RGB
319 #undef FETCH_PIXEL