Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / mesa / drivers / dri / common / spantmp.h
1 /*
2  * Copyright 2000-2001 VA Linux Systems, Inc.
3  * (C) Copyright IBM Corporation 2002, 2003
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * on the rights to use, copy, modify, merge, publish, distribute, sub
10  * license, and/or sell copies of the Software, and to permit persons to whom
11  * the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
20  * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23  * USE OR OTHER DEALINGS IN THE SOFTWARE.
24  *
25  * Authors:
26  *    Keith Whitwell <keithw@tungstengraphics.com>
27  *    Gareth Hughes <gareth@nvidia.com>
28  */
29
30 #include "spantmp_common.h"
31
32 #ifndef DBG
33 #define DBG 0
34 #endif
35
36 #ifndef HW_READ_CLIPLOOP
37 #define HW_READ_CLIPLOOP()      HW_CLIPLOOP()
38 #endif
39
40 #ifndef HW_WRITE_CLIPLOOP
41 #define HW_WRITE_CLIPLOOP()     HW_CLIPLOOP()
42 #endif
43
44
45 static void TAG(WriteRGBASpan)( struct gl_context *ctx,
46                                 struct gl_renderbuffer *rb,
47                                 GLuint n, GLint x, GLint y,
48                                 const void *values, const GLubyte mask[] )
49 {
50    HW_WRITE_LOCK()
51       {
52          const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
53          GLint x1;
54          GLint n1;
55          LOCAL_VARS;
56
57          y = Y_FLIP(y);
58
59          HW_WRITE_CLIPLOOP()
60             {
61                GLint i = 0;
62                CLIPSPAN(x,y,n,x1,n1,i);
63
64                if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
65                                 (int)i, (int)n1, (int)x1);
66
67                if (mask)
68                {
69                   for (;n1>0;i++,x1++,n1--)
70                      if (mask[i])
71                         WRITE_RGBA( x1, y,
72                                     rgba[i][0], rgba[i][1],
73                                     rgba[i][2], rgba[i][3] );
74                }
75                else
76                {
77                   for (;n1>0;i++,x1++,n1--)
78                      WRITE_RGBA( x1, y,
79                                  rgba[i][0], rgba[i][1],
80                                  rgba[i][2], rgba[i][3] );
81                }
82             }
83          HW_ENDCLIPLOOP();
84       }
85    HW_WRITE_UNLOCK();
86 }
87
88 static void TAG(WriteRGBSpan)( struct gl_context *ctx,
89                                struct gl_renderbuffer *rb,
90                                GLuint n, GLint x, GLint y,
91                                const void *values, const GLubyte mask[] )
92 {
93    HW_WRITE_LOCK()
94       {
95          const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
96          GLint x1;
97          GLint n1;
98          LOCAL_VARS;
99
100          y = Y_FLIP(y);
101
102          HW_WRITE_CLIPLOOP()
103             {
104                GLint i = 0;
105                CLIPSPAN(x,y,n,x1,n1,i);
106
107                if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
108                                 (int)i, (int)n1, (int)x1);
109
110                if (mask)
111                {
112                   for (;n1>0;i++,x1++,n1--)
113                      if (mask[i])
114                         WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
115                }
116                else
117                {
118                   for (;n1>0;i++,x1++,n1--)
119                      WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
120                }
121             }
122          HW_ENDCLIPLOOP();
123       }
124    HW_WRITE_UNLOCK();
125 }
126
127 static void TAG(WriteRGBAPixels)( struct gl_context *ctx,
128                                   struct gl_renderbuffer *rb,
129                                   GLuint n, const GLint x[], const GLint y[],
130                                   const void *values, const GLubyte mask[] )
131 {
132    HW_WRITE_LOCK()
133       {
134          const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
135          GLuint i;
136          LOCAL_VARS;
137
138          if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
139
140          HW_WRITE_CLIPLOOP()
141             {
142                if (mask)
143                {
144                   for (i=0;i<n;i++)
145                   {
146                      if (mask[i]) {
147                         const int fy = Y_FLIP(y[i]);
148                         if (CLIPPIXEL(x[i],fy))
149                            WRITE_RGBA( x[i], fy,
150                                        rgba[i][0], rgba[i][1],
151                                        rgba[i][2], rgba[i][3] );
152                      }
153                   }
154                }
155                else
156                {
157                   for (i=0;i<n;i++)
158                   {
159                      const int fy = Y_FLIP(y[i]);
160                      if (CLIPPIXEL(x[i],fy))
161                         WRITE_RGBA( x[i], fy,
162                                     rgba[i][0], rgba[i][1],
163                                     rgba[i][2], rgba[i][3] );
164                   }
165                }
166             }
167          HW_ENDCLIPLOOP();
168       }
169    HW_WRITE_UNLOCK();
170 }
171
172
173 static void TAG(WriteMonoRGBASpan)( struct gl_context *ctx,     
174                                     struct gl_renderbuffer *rb,
175                                     GLuint n, GLint x, GLint y, 
176                                     const void *value,
177                                     const GLubyte mask[] )
178 {
179    HW_WRITE_LOCK()
180       {
181          const GLubyte *color = (const GLubyte *) value;
182          GLint x1;
183          GLint n1;
184          LOCAL_VARS;
185          INIT_MONO_PIXEL(p, color);
186
187          y = Y_FLIP( y );
188
189          if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
190
191          HW_WRITE_CLIPLOOP()
192             {
193                GLint i = 0;
194                CLIPSPAN(x,y,n,x1,n1,i);
195                if (mask)
196                {
197                   for (;n1>0;i++,x1++,n1--)
198                      if (mask[i])
199                         WRITE_PIXEL( x1, y, p );
200                }
201                else
202                {
203                   for (;n1>0;i++,x1++,n1--)
204                      WRITE_PIXEL( x1, y, p );
205                }
206             }
207          HW_ENDCLIPLOOP();
208       }
209    HW_WRITE_UNLOCK();
210 }
211
212
213 static void TAG(WriteMonoRGBAPixels)( struct gl_context *ctx,
214                                       struct gl_renderbuffer *rb,
215                                       GLuint n,
216                                       const GLint x[], const GLint y[],
217                                       const void *value,
218                                       const GLubyte mask[] ) 
219 {
220    HW_WRITE_LOCK()
221       {
222          const GLubyte *color = (const GLubyte *) value;
223          GLuint i;
224          LOCAL_VARS;
225          INIT_MONO_PIXEL(p, color);
226
227          if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
228
229          HW_WRITE_CLIPLOOP()
230             {
231                if (mask)
232                {
233                   for (i=0;i<n;i++)
234                      if (mask[i]) {
235                         int fy = Y_FLIP(y[i]);
236                         if (CLIPPIXEL( x[i], fy ))
237                            WRITE_PIXEL( x[i], fy, p );
238                      }
239                }
240                else
241                {
242                   for (i=0;i<n;i++) {
243                      int fy = Y_FLIP(y[i]);
244                      if (CLIPPIXEL( x[i], fy ))
245                         WRITE_PIXEL( x[i], fy, p );
246                   }
247                }
248             }
249          HW_ENDCLIPLOOP();
250       }
251    HW_WRITE_UNLOCK();
252 }
253
254
255 static void TAG(ReadRGBASpan)( struct gl_context *ctx,
256                                struct gl_renderbuffer *rb,
257                                GLuint n, GLint x, GLint y,
258                                void *values)
259 {
260    HW_READ_LOCK()
261       {
262          GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
263          GLint x1,n1;
264          LOCAL_VARS;
265
266          y = Y_FLIP(y);
267
268          if (DBG) fprintf(stderr, "ReadRGBASpan\n");
269
270          HW_READ_CLIPLOOP()
271             {
272                GLint i = 0;
273                CLIPSPAN(x,y,n,x1,n1,i);
274                for (;n1>0;i++,x1++,n1--)
275                   READ_RGBA( rgba[i], x1, y );
276             }
277          HW_ENDCLIPLOOP();
278       }
279    HW_READ_UNLOCK();
280 }
281
282
283 static void TAG(ReadRGBAPixels)( struct gl_context *ctx,
284                                  struct gl_renderbuffer *rb,
285                                  GLuint n, const GLint x[], const GLint y[],
286                                  void *values )
287 {
288    HW_READ_LOCK()
289       {
290          GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
291          GLuint i;
292          LOCAL_VARS;
293
294          if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
295
296          HW_READ_CLIPLOOP()
297             {
298                for (i=0;i<n;i++) {
299                   int fy = Y_FLIP( y[i] );
300                   if (CLIPPIXEL( x[i], fy ))
301                      READ_RGBA( rgba[i], x[i], fy );
302                }
303             }
304          HW_ENDCLIPLOOP();
305       }
306    HW_READ_UNLOCK();
307 }
308
309
310 static void TAG(InitPointers)(struct gl_renderbuffer *rb)
311 {
312    rb->PutRow = TAG(WriteRGBASpan);
313    rb->PutRowRGB = TAG(WriteRGBSpan);
314    rb->PutMonoRow = TAG(WriteMonoRGBASpan);
315    rb->PutValues = TAG(WriteRGBAPixels);
316    rb->PutMonoValues = TAG(WriteMonoRGBAPixels);
317    rb->GetValues = TAG(ReadRGBAPixels);
318    rb->GetRow = TAG(ReadRGBASpan);
319 }
320
321
322 #undef WRITE_PIXEL
323 #undef WRITE_RGBA
324 #undef READ_RGBA
325 #undef TAG