1 /* $XFree86: xc/lib/GL/mesa/src/drv/gamma/gamma_span.c,v 1.4 2002/11/05 17:46:07 tsi Exp $ */
3 #include "gamma_context.h"
4 #include "gamma_lock.h"
7 #include "swrast/swrast.h"
12 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx); \
13 gammaScreenPtr gammascrn = gmesa->gammaScreen; \
14 __DRIscreenPrivate *sPriv = gmesa->driScreen; \
15 __DRIdrawablePrivate *dPriv = gmesa->driDrawable; \
16 GLuint pitch = sPriv->fbWidth * gammascrn->cpp; \
17 GLuint height = dPriv->h; \
18 char *buf = (char *)(sPriv->pFB + \
20 (dPriv->x * gammascrn->cpp) + \
21 (dPriv->y * pitch)); \
25 /* FIXME! Depth/Stencil read/writes don't work ! */
26 #define LOCAL_DEPTH_VARS \
27 gammaScreenPtr gammascrn = gmesa->gammaScreen; \
28 __DRIdrawablePrivate *dPriv = gmesa->driDrawable; \
29 __DRIscreenPrivate *sPriv = gmesa->driScreen; \
30 GLuint pitch = gammascrn->depthPitch; \
31 GLuint height = dPriv->h; \
32 char *buf = (char *)(sPriv->pFB + \
33 gammascrn->depthOffset + \
34 dPriv->x * gammascrn->cpp + \
37 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
39 #define Y_FLIP( _y ) (height - _y - 1)
42 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx); \
43 FLUSH_DMA_BUFFER(gmesa); \
44 gammaGetLock( gmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT ); \
45 GAMMAHW_LOCK( gmesa );
47 #define HW_UNLOCK() GAMMAHW_UNLOCK( gmesa )
51 /* ================================================================
55 /* 16 bit, RGB565 color spanline and pixel functions
57 #define INIT_MONO_PIXEL(p, color) \
58 p = PACK_COLOR_565( color[0], color[1], color[2] )
60 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
61 *(GLushort *)(buf + _x*2 + _y*pitch) = ((((int)r & 0xf8) << 8) | \
62 (((int)g & 0xfc) << 3) | \
63 (((int)b & 0xf8) >> 3))
65 #define WRITE_PIXEL( _x, _y, p ) \
66 *(GLushort *)(buf + _x*2 + _y*pitch) = p
68 #define READ_RGBA( rgba, _x, _y ) \
70 GLushort p = *(GLushort *)(buf + _x*2 + _y*pitch); \
71 rgba[0] = (p >> 8) & 0xf8; \
72 rgba[1] = (p >> 3) & 0xfc; \
73 rgba[2] = (p << 3) & 0xf8; \
75 if ( rgba[0] & 0x08 ) rgba[0] |= 0x07; \
76 if ( rgba[1] & 0x04 ) rgba[1] |= 0x03; \
77 if ( rgba[2] & 0x08 ) rgba[2] |= 0x07; \
80 #define TAG(x) gamma##x##_RGB565
84 /* 32 bit, ARGB8888 color spanline and pixel functions
87 #undef INIT_MONO_PIXEL
88 #define INIT_MONO_PIXEL(p, color) \
89 p = PACK_COLOR_8888( color[3], color[0], color[1], color[2] )
91 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
92 *(GLuint *)(buf + _x*4 + _y*pitch) = ((b << 0) | \
97 #define WRITE_PIXEL( _x, _y, p ) \
98 *(GLuint *)(buf + _x*4 + _y*pitch) = p
100 #define READ_RGBA( rgba, _x, _y ) \
102 GLuint p = *(GLuint *)(buf + _x*4 + _y*pitch); \
103 rgba[0] = (p >> 16) & 0xff; \
104 rgba[1] = (p >> 8) & 0xff; \
105 rgba[2] = (p >> 0) & 0xff; \
106 rgba[3] = (p >> 24) & 0xff; \
109 #define TAG(x) gamma##x##_ARGB8888
113 /* 16 bit depthbuffer functions.
115 #define WRITE_DEPTH( _x, _y, d ) \
116 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
118 #define READ_DEPTH( d, _x, _y ) \
119 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
121 #define TAG(x) gamma##x##_16
122 #include "depthtmp.h"
126 /* 32 bit depthbuffer functions.
128 #define WRITE_DEPTH( _x, _y, d ) \
129 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
131 #define READ_DEPTH( d, _x, _y ) \
132 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
134 #define TAG(x) gamma##x##_32
135 #include "depthtmp.h"
139 /* 24/8 bit interleaved depth/stencil functions
141 #define WRITE_DEPTH( _x, _y, d ) { \
142 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
144 tmp |= (d) & 0xffffff00; \
145 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
148 #define READ_DEPTH( d, _x, _y ) \
149 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff;
152 #define TAG(x) gamma##x##_24_8
153 #include "depthtmp.h"
156 #define WRITE_STENCIL( _x, _y, d ) { \
157 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
160 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
163 #define READ_STENCIL( d, _x, _y ) \
164 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
166 #define TAG(x) gamma##x##_24_8
167 #include "stenciltmp.h"
169 static void gammaReadRGBASpan8888( const GLcontext
*ctx
,
170 GLuint n
, GLint x
, GLint y
,
173 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
174 gammaScreenPtr gammascrn
= gmesa
->gammaScreen
;
175 u_int32_t dwords1
, dwords2
, i
= 0;
176 char *src
= (char *)rgba
[0];
177 GLuint read
= n
* gammascrn
->cpp
; /* Number of bytes we are expecting */
180 FLUSH_DMA_BUFFER(gmesa
);
181 CHECK_DMA_BUFFER(gmesa
, 16);
182 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
& ~(LBReadSrcEnable
| LBReadDstEnable
));
183 WRITE(gmesa
->buf
, ColorDDAMode
, ColorDDAEnable
);
184 WRITE(gmesa
->buf
, LBWriteMode
, LBWriteModeDisable
);
185 WRITE(gmesa
->buf
, FBReadMode
, (gmesa
->FBReadMode
& ~FBReadSrcEnable
) | FBReadDstEnable
| FBDataTypeColor
);
186 WRITE(gmesa
->buf
, FilterMode
, 0x200); /* Pass FBColorData */
187 WRITE(gmesa
->buf
, FBWriteMode
, FBW_UploadColorData
| FBWriteModeDisable
);
188 WRITE(gmesa
->buf
, StartXSub
, (x
+n
)<<16);
189 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
190 WRITE(gmesa
->buf
, StartY
, y
<<16);
191 WRITE(gmesa
->buf
, GLINTCount
, 1);
192 WRITE(gmesa
->buf
, dXDom
, 0<<16);
193 WRITE(gmesa
->buf
, dXSub
, 0<<16);
194 WRITE(gmesa
->buf
, dY
, 1<<16);
195 WRITE(gmesa
->buf
, Render
, PrimitiveTrapezoid
);
196 FLUSH_DMA_BUFFER(gmesa
);
200 dwords1
= *(volatile u_int32_t
*)(void *)(((u_int8_t
*)gammascrn
->regions
[0].map
) + (GlintOutFIFOWords
));
201 dwords2
= *(volatile u_int32_t
*)(void *)(((u_int8_t
*)gammascrn
->regions
[2].map
) + (GlintOutFIFOWords
));
204 memcpy(src
, (char*)gammascrn
->regions
[1].map
+ 0x1000, dwords1
<< 2);
206 read
-= dwords1
<< 2;
209 memcpy(src
, (char*)gammascrn
->regions
[3].map
+ 0x1000, dwords2
<< 2);
211 read
-= dwords2
<< 2;
219 CHECK_DMA_BUFFER(gmesa
, 6);
220 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
221 WRITE(gmesa
->buf
, LBWriteMode
, LBWriteModeEnable
);
222 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
223 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
);
224 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
225 WRITE(gmesa
->buf
, FilterMode
, 0x400);
229 static void gammaSetBuffer( GLcontext
*ctx
,
230 GLframebuffer
*colorBuffer
,
233 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
235 switch ( bufferBit
) {
236 case BUFFER_BIT_FRONT_LEFT
:
237 gmesa
->readOffset
= 0;
239 case BUFFER_BIT_BACK_LEFT
:
240 gmesa
->readOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
243 _mesa_problem(ctx
, "Unexpected buffer 0x%x in gammaSetBuffer()", bufferBit
);
248 void gammaDDInitSpanFuncs( GLcontext
*ctx
)
250 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
251 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
253 swdd
->SetBuffer
= gammaSetBuffer
;
255 switch ( gmesa
->gammaScreen
->cpp
) {
257 swdd
->WriteRGBASpan
= gammaWriteRGBASpan_RGB565
;
258 swdd
->WriteRGBSpan
= gammaWriteRGBSpan_RGB565
;
259 swdd
->WriteMonoRGBASpan
= gammaWriteMonoRGBASpan_RGB565
;
260 swdd
->WriteRGBAPixels
= gammaWriteRGBAPixels_RGB565
;
261 swdd
->WriteMonoRGBAPixels
= gammaWriteMonoRGBAPixels_RGB565
;
262 swdd
->ReadRGBASpan
= gammaReadRGBASpan_RGB565
;
263 swdd
->ReadRGBAPixels
= gammaReadRGBAPixels_RGB565
;
267 swdd
->WriteRGBASpan
= gammaWriteRGBASpan_ARGB8888
;
268 swdd
->WriteRGBSpan
= gammaWriteRGBSpan_ARGB8888
;
269 swdd
->WriteMonoRGBASpan
= gammaWriteMonoRGBASpan_ARGB8888
;
270 swdd
->WriteRGBAPixels
= gammaWriteRGBAPixels_ARGB8888
;
271 swdd
->WriteMonoRGBAPixels
= gammaWriteMonoRGBAPixels_ARGB8888
;
273 swdd
->ReadRGBASpan
= gammaReadRGBASpan_ARGB8888
;
275 swdd
->ReadRGBASpan
= gammaReadRGBASpan8888
;
277 swdd
->ReadRGBAPixels
= gammaReadRGBAPixels_ARGB8888
;
284 switch ( gmesa
->glCtx
->Visual
.depthBits
) {
286 swdd
->ReadDepthSpan
= gammaReadDepthSpan_16
;
287 swdd
->WriteDepthSpan
= gammaWriteDepthSpan_16
;
288 swdd
->ReadDepthPixels
= gammaReadDepthPixels_16
;
289 swdd
->WriteDepthPixels
= gammaWriteDepthPixels_16
;
293 swdd
->ReadDepthSpan
= gammaReadDepthSpan_24_8
;
294 swdd
->WriteDepthSpan
= gammaWriteDepthSpan_24_8
;
295 swdd
->ReadDepthPixels
= gammaReadDepthPixels_24_8
;
296 swdd
->WriteDepthPixels
= gammaWriteDepthPixels_24_8
;
299 swdd
->ReadStencilSpan
= gammaReadStencilSpan_24_8
;
300 swdd
->WriteStencilSpan
= gammaWriteStencilSpan_24_8
;
301 swdd
->ReadStencilPixels
= gammaReadStencilPixels_24_8
;
302 swdd
->WriteStencilPixels
= gammaWriteStencilPixels_24_8
;