d11d1d36aef0630770fd17f179467bdfffb837ee
[mesa.git] / src / mesa / drivers / dri / swrast / swrast_span.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 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 * Authors:
27 * George Sapountzis <gsap7@yahoo.gr>
28 */
29
30 #include "swrast_priv.h"
31
32 #define YFLIP(_xrb, Y) ((_xrb)->Base.Height - (Y) - 1)
33
34 /*
35 * Pixel macros shared across front/back buffer span functions.
36 */
37
38 /* 32-bit BGRA */
39 #define STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE) \
40 DST[3] = VALUE[ACOMP]; \
41 DST[2] = VALUE[RCOMP]; \
42 DST[1] = VALUE[GCOMP]; \
43 DST[0] = VALUE[BCOMP]
44 #define STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE) \
45 DST[3] = 0xff; \
46 DST[2] = VALUE[RCOMP]; \
47 DST[1] = VALUE[GCOMP]; \
48 DST[0] = VALUE[BCOMP]
49 #define FETCH_PIXEL_A8R8G8B8(DST, SRC) \
50 DST[ACOMP] = SRC[3]; \
51 DST[RCOMP] = SRC[2]; \
52 DST[GCOMP] = SRC[1]; \
53 DST[BCOMP] = SRC[0]
54
55
56 /* 16-bit BGR */
57 #define STORE_PIXEL_R5G6B5(DST, X, Y, VALUE) \
58 do { \
59 GLushort *p = (GLushort *)DST; \
60 *p = ( (((VALUE[RCOMP]) & 0xf8) << 8) | \
61 (((VALUE[GCOMP]) & 0xfc) << 3) | \
62 (((VALUE[BCOMP]) & 0xf8) >> 3) ); \
63 } while(0)
64 #define FETCH_PIXEL_R5G6B5(DST, SRC) \
65 do { \
66 GLushort p = *(GLushort *)SRC; \
67 DST[ACOMP] = 0xff; \
68 DST[RCOMP] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
69 DST[GCOMP] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
70 DST[BCOMP] = ((p << 3) & 0xf8) * 255 / 0xf8; \
71 } while(0)
72
73
74 /*
75 * Generate code for image span functions.
76 */
77
78 /* 32-bit BGRA */
79 #define NAME(FUNC) FUNC##_A8R8G8B8
80 #define RB_TYPE GLubyte
81 #define SPAN_VARS \
82 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
83 #define INIT_PIXEL_PTR(P, X, Y) \
84 GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X) * 4;
85 #define INC_PIXEL_PTR(P) P += 4
86 #define STORE_PIXEL(DST, X, Y, VALUE) \
87 STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE)
88 #define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
89 STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE)
90 #define FETCH_PIXEL(DST, SRC) \
91 FETCH_PIXEL_A8R8G8B8(DST, SRC)
92
93 #include "swrast/s_spantemp.h"
94
95
96 /* 16-bit BGR */
97 #define NAME(FUNC) FUNC##_R5G6B5
98 #define RB_TYPE GLubyte
99 #define SPAN_VARS \
100 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
101 #define INIT_PIXEL_PTR(P, X, Y) \
102 GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X) * 2;
103 #define INC_PIXEL_PTR(P) P += 2
104 #define STORE_PIXEL(DST, X, Y, VALUE) \
105 STORE_PIXEL_R5G6B5(DST, X, Y, VALUE)
106 #define FETCH_PIXEL(DST, SRC) \
107 FETCH_PIXEL_R5G6B5(DST, SRC)
108
109 #include "swrast/s_spantemp.h"
110
111
112 /* 8-bit color index */
113 #define NAME(FUNC) FUNC##_CI8
114 #define CI_MODE
115 #define RB_TYPE GLubyte
116 #define SPAN_VARS \
117 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
118 #define INIT_PIXEL_PTR(P, X, Y) \
119 GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X);
120 #define INC_PIXEL_PTR(P) P += 1
121 #define STORE_PIXEL(DST, X, Y, VALUE) \
122 *DST = VALUE[0]
123 #define FETCH_PIXEL(DST, SRC) \
124 DST = SRC[0]
125
126 #include "swrast/s_spantemp.h"
127
128
129 /*
130 * Generate code for pixmap span functions.
131 */
132
133 /* 32-bit BGRA */
134 #define NAME(FUNC) FUNC##_A8R8G8B8_pixmap
135 #define RB_TYPE GLubyte
136 #define SPAN_VARS \
137 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
138 #define INIT_PIXEL_PTR(P, X, Y) \
139 GLubyte *P = (GLubyte *)row;
140 #define INC_PIXEL_PTR(P) P += 4
141 #define STORE_PIXEL(DST, X, Y, VALUE) \
142 STORE_PIXEL_A8R8G8B8(DST, X, Y, VALUE)
143 #define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
144 STORE_PIXEL_RGB_A8R8G8B8(DST, X, Y, VALUE)
145 #define FETCH_PIXEL(DST, SRC) \
146 FETCH_PIXEL_A8R8G8B8(DST, SRC)
147
148 #include "swrast_spantemp.h"
149
150
151 /* 16-bit BGR */
152 #define NAME(FUNC) FUNC##_R5G6B5_pixmap
153 #define RB_TYPE GLubyte
154 #define SPAN_VARS \
155 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
156 #define INIT_PIXEL_PTR(P, X, Y) \
157 GLubyte *P = (GLubyte *)row;
158 #define INC_PIXEL_PTR(P) P += 2
159 #define STORE_PIXEL(DST, X, Y, VALUE) \
160 STORE_PIXEL_R5G6B5(DST, X, Y, VALUE)
161 #define FETCH_PIXEL(DST, SRC) \
162 FETCH_PIXEL_R5G6B5(DST, SRC)
163
164 #include "swrast_spantemp.h"
165
166
167 /* 8-bit color index */
168 #define NAME(FUNC) FUNC##_CI8_pixmap
169 #define CI_MODE
170 #define RB_TYPE GLubyte
171 #define SPAN_VARS \
172 struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
173 #define INIT_PIXEL_PTR(P, X, Y) \
174 GLubyte *P = (GLubyte *)row;
175 #define INC_PIXEL_PTR(P) P += 1
176 #define STORE_PIXEL(DST, X, Y, VALUE) \
177 *DST = VALUE[0]
178 #define FETCH_PIXEL(DST, SRC) \
179 DST = SRC[0]
180
181 #include "swrast_spantemp.h"
182
183
184 /*
185 * Images are malloced memory used for private back-buffers.
186 *
187 * BACK_PIXMAP (not supported)
188 * BACK_XIMAGE
189 */
190 void
191 swrast_set_span_funcs_ximage(struct swrast_renderbuffer *xrb,
192 GLuint pixel_format)
193 {
194 switch (pixel_format) {
195 case PF_A8R8G8B8:
196 xrb->Base.GetRow = get_row_A8R8G8B8;
197 xrb->Base.GetValues = get_values_A8R8G8B8;
198 xrb->Base.PutRow = put_row_A8R8G8B8;
199 xrb->Base.PutRowRGB = put_row_rgb_A8R8G8B8;
200 xrb->Base.PutMonoRow = put_mono_row_A8R8G8B8;
201 xrb->Base.PutValues = put_values_A8R8G8B8;
202 xrb->Base.PutMonoValues = put_mono_values_A8R8G8B8;
203 break;
204 case PF_R5G6B5:
205 xrb->Base.GetRow = get_row_R5G6B5;
206 xrb->Base.GetValues = get_values_R5G6B5;
207 xrb->Base.PutRow = put_row_R5G6B5;
208 xrb->Base.PutRowRGB = put_row_rgb_R5G6B5;
209 xrb->Base.PutMonoRow = put_mono_row_R5G6B5;
210 xrb->Base.PutValues = put_values_R5G6B5;
211 xrb->Base.PutMonoValues = put_mono_values_R5G6B5;
212 break;
213 case PF_CI8:
214 xrb->Base.GetRow = get_row_CI8;
215 xrb->Base.GetValues = get_values_CI8;
216 xrb->Base.PutRow = put_row_CI8;
217 xrb->Base.PutMonoRow = put_mono_row_CI8;
218 xrb->Base.PutValues = put_values_CI8;
219 xrb->Base.PutMonoValues = put_mono_values_CI8;
220 break;
221 default:
222 assert(0);
223 return;
224 }
225 }
226
227
228 /*
229 * Pixmaps are used for front-buffers.
230 *
231 * WINDOW, An X window
232 * GLXWINDOW, GLX window
233 * PIXMAP, GLX pixmap
234 * PBUFFER GLX Pbuffer
235 */
236 void
237 swrast_set_span_funcs_pixmap(struct swrast_renderbuffer *xrb,
238 GLuint pixel_format)
239 {
240 switch (pixel_format) {
241 case PF_A8R8G8B8:
242 xrb->Base.GetRow = get_row_A8R8G8B8_pixmap;
243 xrb->Base.GetValues = get_values_A8R8G8B8_pixmap;
244 xrb->Base.PutRow = put_row_A8R8G8B8_pixmap;
245 xrb->Base.PutRowRGB = put_row_rgb_A8R8G8B8_pixmap;
246 xrb->Base.PutMonoRow = put_mono_row_A8R8G8B8_pixmap;
247 xrb->Base.PutValues = put_values_A8R8G8B8_pixmap;
248 xrb->Base.PutMonoValues = put_mono_values_A8R8G8B8_pixmap;
249 break;
250 case PF_R5G6B5:
251 xrb->Base.GetRow = get_row_R5G6B5_pixmap;
252 xrb->Base.GetValues = get_values_R5G6B5_pixmap;
253 xrb->Base.PutRow = put_row_R5G6B5_pixmap;
254 xrb->Base.PutRowRGB = put_row_rgb_R5G6B5_pixmap;
255 xrb->Base.PutMonoRow = put_mono_row_R5G6B5_pixmap;
256 xrb->Base.PutValues = put_values_R5G6B5_pixmap;
257 xrb->Base.PutMonoValues = put_mono_values_R5G6B5_pixmap;
258 break;
259 case PF_CI8:
260 xrb->Base.GetRow = get_row_CI8_pixmap;
261 xrb->Base.GetValues = get_values_CI8_pixmap;
262 xrb->Base.PutRow = put_row_CI8_pixmap;
263 xrb->Base.PutMonoRow = put_mono_row_CI8_pixmap;
264 xrb->Base.PutValues = put_values_CI8_pixmap;
265 xrb->Base.PutMonoValues = put_mono_values_CI8_pixmap;
266 break;
267 default:
268 assert(0);
269 return;
270 }
271 }