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 VALUE_TYPE GLushort
117 #define WRITE_DEPTH( _x, _y, d ) \
118 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
120 #define READ_DEPTH( d, _x, _y ) \
121 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
123 #define TAG(x) gamma##x##_16
124 #include "depthtmp.h"
128 /* 32 bit depthbuffer functions.
130 #define VALUE_TYPE GLuint
132 #define WRITE_DEPTH( _x, _y, d ) \
133 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
135 #define READ_DEPTH( d, _x, _y ) \
136 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
138 #define TAG(x) gamma##x##_32
139 #include "depthtmp.h"
143 /* 24/8 bit interleaved depth/stencil functions
145 #define VALUE_TYPE GLuint
147 #define WRITE_DEPTH( _x, _y, d ) { \
148 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
150 tmp |= (d) & 0xffffff00; \
151 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
154 #define READ_DEPTH( d, _x, _y ) \
155 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff;
158 #define TAG(x) gamma##x##_24_8
159 #include "depthtmp.h"
162 #define WRITE_STENCIL( _x, _y, d ) { \
163 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
166 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
169 #define READ_STENCIL( d, _x, _y ) \
170 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
172 #define TAG(x) gamma##x##_24_8
173 #include "stenciltmp.h"
175 static void gammaReadRGBASpan8888( const GLcontext
*ctx
,
176 GLuint n
, GLint x
, GLint y
,
179 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
180 gammaScreenPtr gammascrn
= gmesa
->gammaScreen
;
181 u_int32_t dwords1
, dwords2
, i
= 0;
182 char *src
= (char *)rgba
[0];
183 GLuint read
= n
* gammascrn
->cpp
; /* Number of bytes we are expecting */
186 FLUSH_DMA_BUFFER(gmesa
);
187 CHECK_DMA_BUFFER(gmesa
, 16);
188 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
& ~(LBReadSrcEnable
| LBReadDstEnable
));
189 WRITE(gmesa
->buf
, ColorDDAMode
, ColorDDAEnable
);
190 WRITE(gmesa
->buf
, LBWriteMode
, LBWriteModeDisable
);
191 WRITE(gmesa
->buf
, FBReadMode
, (gmesa
->FBReadMode
& ~FBReadSrcEnable
) | FBReadDstEnable
| FBDataTypeColor
);
192 WRITE(gmesa
->buf
, FilterMode
, 0x200); /* Pass FBColorData */
193 WRITE(gmesa
->buf
, FBWriteMode
, FBW_UploadColorData
| FBWriteModeDisable
);
194 WRITE(gmesa
->buf
, StartXSub
, (x
+n
)<<16);
195 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
196 WRITE(gmesa
->buf
, StartY
, y
<<16);
197 WRITE(gmesa
->buf
, GLINTCount
, 1);
198 WRITE(gmesa
->buf
, dXDom
, 0<<16);
199 WRITE(gmesa
->buf
, dXSub
, 0<<16);
200 WRITE(gmesa
->buf
, dY
, 1<<16);
201 WRITE(gmesa
->buf
, Render
, PrimitiveTrapezoid
);
202 FLUSH_DMA_BUFFER(gmesa
);
206 dwords1
= *(volatile u_int32_t
*)(void *)(((u_int8_t
*)gammascrn
->regions
[0].map
) + (GlintOutFIFOWords
));
207 dwords2
= *(volatile u_int32_t
*)(void *)(((u_int8_t
*)gammascrn
->regions
[2].map
) + (GlintOutFIFOWords
));
210 memcpy(src
, (char*)gammascrn
->regions
[1].map
+ 0x1000, dwords1
<< 2);
212 read
-= dwords1
<< 2;
215 memcpy(src
, (char*)gammascrn
->regions
[3].map
+ 0x1000, dwords2
<< 2);
217 read
-= dwords2
<< 2;
225 CHECK_DMA_BUFFER(gmesa
, 6);
226 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
227 WRITE(gmesa
->buf
, LBWriteMode
, LBWriteModeEnable
);
228 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
229 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
);
230 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
231 WRITE(gmesa
->buf
, FilterMode
, 0x400);
235 static void gammaSetBuffer( GLcontext
*ctx
,
236 GLframebuffer
*colorBuffer
,
239 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
241 switch ( bufferBit
) {
242 case BUFFER_BIT_FRONT_LEFT
:
243 gmesa
->readOffset
= 0;
245 case BUFFER_BIT_BACK_LEFT
:
246 gmesa
->readOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
249 _mesa_problem(ctx
, "Unexpected buffer 0x%x in gammaSetBuffer()", bufferBit
);
254 void gammaDDInitSpanFuncs( GLcontext
*ctx
)
256 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
257 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
259 swdd
->SetBuffer
= gammaSetBuffer
;
261 switch ( gmesa
->gammaScreen
->cpp
) {
263 swdd
->WriteRGBASpan
= gammaWriteRGBASpan_RGB565
;
264 swdd
->WriteRGBSpan
= gammaWriteRGBSpan_RGB565
;
265 swdd
->WriteMonoRGBASpan
= gammaWriteMonoRGBASpan_RGB565
;
266 swdd
->WriteRGBAPixels
= gammaWriteRGBAPixels_RGB565
;
267 swdd
->WriteMonoRGBAPixels
= gammaWriteMonoRGBAPixels_RGB565
;
268 swdd
->ReadRGBASpan
= gammaReadRGBASpan_RGB565
;
269 swdd
->ReadRGBAPixels
= gammaReadRGBAPixels_RGB565
;
273 swdd
->WriteRGBASpan
= gammaWriteRGBASpan_ARGB8888
;
274 swdd
->WriteRGBSpan
= gammaWriteRGBSpan_ARGB8888
;
275 swdd
->WriteMonoRGBASpan
= gammaWriteMonoRGBASpan_ARGB8888
;
276 swdd
->WriteRGBAPixels
= gammaWriteRGBAPixels_ARGB8888
;
277 swdd
->WriteMonoRGBAPixels
= gammaWriteMonoRGBAPixels_ARGB8888
;
279 swdd
->ReadRGBASpan
= gammaReadRGBASpan_ARGB8888
;
281 swdd
->ReadRGBASpan
= gammaReadRGBASpan8888
;
283 swdd
->ReadRGBAPixels
= gammaReadRGBAPixels_ARGB8888
;
290 switch ( gmesa
->glCtx
->Visual
.depthBits
) {
292 swdd
->ReadDepthSpan
= gammaReadDepthSpan_16
;
293 swdd
->WriteDepthSpan
= gammaWriteDepthSpan_16
;
294 swdd
->ReadDepthPixels
= gammaReadDepthPixels_16
;
295 swdd
->WriteDepthPixels
= gammaWriteDepthPixels_16
;
299 swdd
->ReadDepthSpan
= gammaReadDepthSpan_24_8
;
300 swdd
->WriteDepthSpan
= gammaWriteDepthSpan_24_8
;
301 swdd
->ReadDepthPixels
= gammaReadDepthPixels_24_8
;
302 swdd
->WriteDepthPixels
= gammaWriteDepthPixels_24_8
;
305 swdd
->ReadStencilSpan
= gammaReadStencilSpan_24_8
;
306 swdd
->WriteStencilSpan
= gammaWriteStencilSpan_24_8
;
307 swdd
->ReadStencilPixels
= gammaReadStencilPixels_24_8
;
308 swdd
->WriteStencilPixels
= gammaWriteStencilPixels_24_8
;