Merge branch 'gallium-vertex-linear' into gallium-tex-surfaces
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_span.c
1
2 #include "gamma_context.h"
3 #include "gamma_lock.h"
4 #include "colormac.h"
5
6 #include "swrast/swrast.h"
7
8 #define DBG 0
9
10 #define LOCAL_VARS \
11 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx); \
12 gammaScreenPtr gammascrn = gmesa->gammaScreen; \
13 __DRIscreenPrivate *sPriv = gmesa->driScreen; \
14 __DRIdrawablePrivate *dPriv = gmesa->driDrawable; \
15 GLuint pitch = sPriv->fbWidth * gammascrn->cpp; \
16 GLuint height = dPriv->h; \
17 char *buf = (char *)(sPriv->pFB + \
18 gmesa->drawOffset + \
19 (dPriv->x * gammascrn->cpp) + \
20 (dPriv->y * pitch)); \
21 GLuint p; \
22 (void) buf; (void) p
23
24 /* FIXME! Depth/Stencil read/writes don't work ! */
25 #define LOCAL_DEPTH_VARS \
26 gammaScreenPtr gammascrn = gmesa->gammaScreen; \
27 __DRIdrawablePrivate *dPriv = gmesa->driDrawable; \
28 __DRIscreenPrivate *sPriv = gmesa->driScreen; \
29 GLuint pitch = gammascrn->depthPitch; \
30 GLuint height = dPriv->h; \
31 char *buf = (char *)(sPriv->pFB + \
32 gammascrn->depthOffset + \
33 dPriv->x * gammascrn->cpp + \
34 dPriv->y * pitch)
35
36 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
37
38 #define Y_FLIP( _y ) (height - _y - 1)
39
40 #define HW_LOCK() \
41 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx); \
42 FLUSH_DMA_BUFFER(gmesa); \
43 gammaGetLock( gmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT ); \
44 GAMMAHW_LOCK( gmesa );
45
46 #define HW_UNLOCK() GAMMAHW_UNLOCK( gmesa )
47
48
49
50 /* ================================================================
51 * Color buffer
52 */
53
54 /* 16 bit, RGB565 color spanline and pixel functions
55 */
56 #define INIT_MONO_PIXEL(p, color) \
57 p = PACK_COLOR_565( color[0], color[1], color[2] )
58
59 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
60 *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)r & 0xf8) << 8) | \
61 (((int)g & 0xfc) << 3) | \
62 (((int)b & 0xf8) >> 3))
63
64 #define WRITE_PIXEL( _x, _y, p ) \
65 *(GLushort *)(buf + _x*2 + _y*pitch) = p
66
67 #define READ_RGBA( rgba, _x, _y ) \
68 do { \
69 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
70 rgba[0] = (p >> 8) & 0xf8; \
71 rgba[1] = (p >> 3) & 0xfc; \
72 rgba[2] = (p << 3) & 0xf8; \
73 rgba[3] = 0xff; \
74 if ( rgba[0] & 0x08 ) rgba[0] |= 0x07; \
75 if ( rgba[1] & 0x04 ) rgba[1] |= 0x03; \
76 if ( rgba[2] & 0x08 ) rgba[2] |= 0x07; \
77 } while (0)
78
79 #define TAG(x) gamma##x##_RGB565
80 #include "spantmp.h"
81
82
83 /* 32 bit, ARGB8888 color spanline and pixel functions
84 */
85
86 #undef INIT_MONO_PIXEL
87 #define INIT_MONO_PIXEL(p, color) \
88 p = PACK_COLOR_8888( color[3], color[0], color[1], color[2] )
89
90 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
91 *(GLuint *)(buf + _x*4 + _y*pitch) = ((b << 0) | \
92 (g << 8) | \
93 (r << 16) | \
94 (a << 24) )
95
96 #define WRITE_PIXEL( _x, _y, p ) \
97 *(GLuint *)(buf + _x*4 + _y*pitch) = p
98
99 #define READ_RGBA( rgba, _x, _y ) \
100 do { \
101 GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \
102 rgba[0] = (p >> 16) & 0xff; \
103 rgba[1] = (p >> 8) & 0xff; \
104 rgba[2] = (p >> 0) & 0xff; \
105 rgba[3] = (p >> 24) & 0xff; \
106 } while (0)
107
108 #define TAG(x) gamma##x##_ARGB8888
109 #include "spantmp.h"
110
111
112 /* 16 bit depthbuffer functions.
113 */
114 #define WRITE_DEPTH( _x, _y, d ) \
115 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
116
117 #define READ_DEPTH( d, _x, _y ) \
118 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
119
120 #define TAG(x) gamma##x##_16
121 #include "depthtmp.h"
122
123
124 #if 0 /* Unused */
125 /* 32 bit depthbuffer functions.
126 */
127 #define WRITE_DEPTH( _x, _y, d ) \
128 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
129
130 #define READ_DEPTH( d, _x, _y ) \
131 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
132
133 #define TAG(x) gamma##x##_32
134 #include "depthtmp.h"
135 #endif
136
137
138 /* 24/8 bit interleaved depth/stencil functions
139 */
140 #define WRITE_DEPTH( _x, _y, d ) { \
141 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
142 tmp &= 0xff; \
143 tmp |= (d) & 0xffffff00; \
144 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
145 }
146
147 #define READ_DEPTH( d, _x, _y ) \
148 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff;
149
150
151 #define TAG(x) gamma##x##_24_8
152 #include "depthtmp.h"
153
154 #if 0
155 #define WRITE_STENCIL( _x, _y, d ) { \
156 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
157 tmp &= 0xffffff00; \
158 tmp |= d & 0xff; \
159 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
160 }
161
162 #define READ_STENCIL( d, _x, _y ) \
163 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
164
165 #define TAG(x) gamma##x##_24_8
166 #include "stenciltmp.h"
167
168 static void gammaReadRGBASpan8888( const GLcontext *ctx,
169 GLuint n, GLint x, GLint y,
170 GLubyte rgba[][4])
171 {
172 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
173 gammaScreenPtr gammascrn = gmesa->gammaScreen;
174 u_int32_t dwords1, dwords2, i = 0;
175 char *src = (char *)rgba[0];
176 GLuint read = n * gammascrn->cpp; /* Number of bytes we are expecting */
177 u_int32_t data;
178
179 FLUSH_DMA_BUFFER(gmesa);
180 CHECK_DMA_BUFFER(gmesa, 16);
181 WRITE(gmesa->buf, LBReadMode, gmesa->LBReadMode & ~(LBReadSrcEnable | LBReadDstEnable));
182 WRITE(gmesa->buf, ColorDDAMode, ColorDDAEnable);
183 WRITE(gmesa->buf, LBWriteMode, LBWriteModeDisable);
184 WRITE(gmesa->buf, FBReadMode, (gmesa->FBReadMode & ~FBReadSrcEnable) | FBReadDstEnable | FBDataTypeColor);
185 WRITE(gmesa->buf, FilterMode, 0x200); /* Pass FBColorData */
186 WRITE(gmesa->buf, FBWriteMode, FBW_UploadColorData | FBWriteModeDisable);
187 WRITE(gmesa->buf, StartXSub, (x+n)<<16);
188 WRITE(gmesa->buf, StartXDom, x<<16);
189 WRITE(gmesa->buf, StartY, y<<16);
190 WRITE(gmesa->buf, GLINTCount, 1);
191 WRITE(gmesa->buf, dXDom, 0<<16);
192 WRITE(gmesa->buf, dXSub, 0<<16);
193 WRITE(gmesa->buf, dY, 1<<16);
194 WRITE(gmesa->buf, Render, PrimitiveTrapezoid);
195 FLUSH_DMA_BUFFER(gmesa);
196
197 moredata:
198
199 dwords1 = *(volatile u_int32_t*)(void *)(((u_int8_t*)gammascrn->regions[0].map) + (GlintOutFIFOWords));
200 dwords2 = *(volatile u_int32_t*)(void *)(((u_int8_t*)gammascrn->regions[2].map) + (GlintOutFIFOWords));
201
202 if (dwords1) {
203 memcpy(src, (char*)gammascrn->regions[1].map + 0x1000, dwords1 << 2);
204 src += dwords1 << 2;
205 read -= dwords1 << 2;
206 }
207 if (dwords2) {
208 memcpy(src, (char*)gammascrn->regions[3].map + 0x1000, dwords2 << 2);
209 src += dwords2 << 2;
210 read -= dwords2 << 2;
211 }
212
213 if (read)
214 goto moredata;
215
216 done:
217
218 CHECK_DMA_BUFFER(gmesa, 6);
219 WRITE(gmesa->buf, ColorDDAMode, gmesa->ColorDDAMode);
220 WRITE(gmesa->buf, LBWriteMode, LBWriteModeEnable);
221 WRITE(gmesa->buf, LBReadMode, gmesa->LBReadMode);
222 WRITE(gmesa->buf, FBReadMode, gmesa->FBReadMode);
223 WRITE(gmesa->buf, FBWriteMode, FBWriteModeEnable);
224 WRITE(gmesa->buf, FilterMode, 0x400);
225 }
226 #endif
227
228 static void gammaSetBuffer( GLcontext *ctx,
229 GLframebuffer *colorBuffer,
230 GLuint bufferBit )
231 {
232 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
233
234 switch ( bufferBit ) {
235 case BUFFER_BIT_FRONT_LEFT:
236 gmesa->readOffset = 0;
237 break;
238 case BUFFER_BIT_BACK_LEFT:
239 gmesa->readOffset = gmesa->driScreen->fbHeight * gmesa->driScreen->fbWidth * gmesa->gammaScreen->cpp;
240 break;
241 default:
242 _mesa_problem(ctx, "Unexpected buffer 0x%x in gammaSetBuffer()", bufferBit);
243 }
244 }
245
246
247 void gammaDDInitSpanFuncs( GLcontext *ctx )
248 {
249 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
250 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
251
252 swdd->SetBuffer = gammaSetBuffer;
253
254 switch ( gmesa->gammaScreen->cpp ) {
255 case 2:
256 swdd->WriteRGBASpan = gammaWriteRGBASpan_RGB565;
257 swdd->WriteRGBSpan = gammaWriteRGBSpan_RGB565;
258 swdd->WriteMonoRGBASpan = gammaWriteMonoRGBASpan_RGB565;
259 swdd->WriteRGBAPixels = gammaWriteRGBAPixels_RGB565;
260 swdd->WriteMonoRGBAPixels = gammaWriteMonoRGBAPixels_RGB565;
261 swdd->ReadRGBASpan = gammaReadRGBASpan_RGB565;
262 swdd->ReadRGBAPixels = gammaReadRGBAPixels_RGB565;
263 break;
264
265 case 4:
266 swdd->WriteRGBASpan = gammaWriteRGBASpan_ARGB8888;
267 swdd->WriteRGBSpan = gammaWriteRGBSpan_ARGB8888;
268 swdd->WriteMonoRGBASpan = gammaWriteMonoRGBASpan_ARGB8888;
269 swdd->WriteRGBAPixels = gammaWriteRGBAPixels_ARGB8888;
270 swdd->WriteMonoRGBAPixels = gammaWriteMonoRGBAPixels_ARGB8888;
271 #if 1
272 swdd->ReadRGBASpan = gammaReadRGBASpan_ARGB8888;
273 #else
274 swdd->ReadRGBASpan = gammaReadRGBASpan8888;
275 #endif
276 swdd->ReadRGBAPixels = gammaReadRGBAPixels_ARGB8888;
277 break;
278
279 default:
280 break;
281 }
282
283 switch ( gmesa->glCtx->Visual.depthBits ) {
284 case 16:
285 swdd->ReadDepthSpan = gammaReadDepthSpan_16;
286 swdd->WriteDepthSpan = gammaWriteDepthSpan_16;
287 swdd->ReadDepthPixels = gammaReadDepthPixels_16;
288 swdd->WriteDepthPixels = gammaWriteDepthPixels_16;
289 break;
290
291 case 24:
292 swdd->ReadDepthSpan = gammaReadDepthSpan_24_8;
293 swdd->WriteDepthSpan = gammaWriteDepthSpan_24_8;
294 swdd->ReadDepthPixels = gammaReadDepthPixels_24_8;
295 swdd->WriteDepthPixels = gammaWriteDepthPixels_24_8;
296
297 #if 0
298 swdd->ReadStencilSpan = gammaReadStencilSpan_24_8;
299 swdd->WriteStencilSpan = gammaWriteStencilSpan_24_8;
300 swdd->ReadStencilPixels = gammaReadStencilPixels_24_8;
301 swdd->WriteStencilPixels = gammaWriteStencilPixels_24_8;
302 #endif
303 break;
304
305 default:
306 break;
307 }
308 }