2 #include "gammacontext.h"
3 #include "gamma_lock.h"
6 #include "swrast/swrast.h"
11 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx); \
12 gammaScreenPtr gammascrn = gmesa->gammaScreen; \
13 __DRIscreen *sPriv = gmesa->driScreen; \
14 __DRIdrawable *dPriv = gmesa->driDrawable; \
15 GLuint pitch = sPriv->fbWidth * gammascrn->cpp; \
16 GLuint height = dPriv->h; \
17 char *buf = (char *)(sPriv->pFB + \
19 (dPriv->x * gammascrn->cpp) + \
20 (dPriv->y * pitch)); \
24 /* FIXME! Depth/Stencil read/writes don't work ! */
25 #define LOCAL_DEPTH_VARS \
26 gammaScreenPtr gammascrn = gmesa->gammaScreen; \
27 __DRIdrawable *dPriv = gmesa->driDrawable; \
28 __DRIscreen *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 + \
36 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
38 #define Y_FLIP( _y ) (height - _y - 1)
41 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx); \
42 FLUSH_DMA_BUFFER(gmesa); \
43 gammaGetLock( gmesa, DRM_LOCK_FLUSH | DRM_LOCK_QUIESCENT ); \
44 GAMMAHW_LOCK( gmesa );
46 #define HW_UNLOCK() GAMMAHW_UNLOCK( gmesa )
50 /* ================================================================
54 /* 16 bit, RGB565 color spanline and pixel functions
56 #define INIT_MONO_PIXEL(p, color) \
57 p = PACK_COLOR_565( color[0], color[1], color[2] )
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))
64 #define WRITE_PIXEL( _x, _y, p ) \
65 *(GLushort *)(buf + _x*2 + _y*pitch) = p
67 #define READ_RGBA( rgba, _x, _y ) \
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; \
74 if ( rgba[0] & 0x08 ) rgba[0] |= 0x07; \
75 if ( rgba[1] & 0x04 ) rgba[1] |= 0x03; \
76 if ( rgba[2] & 0x08 ) rgba[2] |= 0x07; \
79 #define TAG(x) gamma##x##_RGB565
83 /* 32 bit, ARGB8888 color spanline and pixel functions
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] )
90 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
91 *(GLuint *)(buf + _x*4 + _y*pitch) = ((b << 0) | \
96 #define WRITE_PIXEL( _x, _y, p ) \
97 *(GLuint *)(buf + _x*4 + _y*pitch) = p
99 #define READ_RGBA( rgba, _x, _y ) \
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; \
108 #define TAG(x) gamma##x##_ARGB8888
112 /* 16 bit depthbuffer functions.
114 #define VALUE_TYPE GLushort
116 #define WRITE_DEPTH( _x, _y, d ) \
117 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
119 #define READ_DEPTH( d, _x, _y ) \
120 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
122 #define TAG(x) gamma##x##_16
123 #include "depthtmp.h"
127 /* 32 bit depthbuffer functions.
129 #define VALUE_TYPE GLuint
131 #define WRITE_DEPTH( _x, _y, d ) \
132 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
134 #define READ_DEPTH( d, _x, _y ) \
135 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
137 #define TAG(x) gamma##x##_32
138 #include "depthtmp.h"
142 /* 24/8 bit interleaved depth/stencil functions
144 #define VALUE_TYPE GLuint
146 #define WRITE_DEPTH( _x, _y, d ) { \
147 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
149 tmp |= (d) & 0xffffff00; \
150 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
153 #define READ_DEPTH( d, _x, _y ) \
154 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff;
157 #define TAG(x) gamma##x##_24_8
158 #include "depthtmp.h"
161 #define WRITE_STENCIL( _x, _y, d ) { \
162 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
165 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
168 #define READ_STENCIL( d, _x, _y ) \
169 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
171 #define TAG(x) gamma##x##_24_8
172 #include "stenciltmp.h"
174 static void gammaReadRGBASpan8888( const GLcontext
*ctx
,
175 GLuint n
, GLint x
, GLint y
,
178 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
179 gammaScreenPtr gammascrn
= gmesa
->gammaScreen
;
180 uint32_t dwords1
, dwords2
, i
= 0;
181 char *src
= (char *)rgba
[0];
182 GLuint read
= n
* gammascrn
->cpp
; /* Number of bytes we are expecting */
185 FLUSH_DMA_BUFFER(gmesa
);
186 CHECK_DMA_BUFFER(gmesa
, 16);
187 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
& ~(LBReadSrcEnable
| LBReadDstEnable
));
188 WRITE(gmesa
->buf
, ColorDDAMode
, ColorDDAEnable
);
189 WRITE(gmesa
->buf
, LBWriteMode
, LBWriteModeDisable
);
190 WRITE(gmesa
->buf
, FBReadMode
, (gmesa
->FBReadMode
& ~FBReadSrcEnable
) | FBReadDstEnable
| FBDataTypeColor
);
191 WRITE(gmesa
->buf
, FilterMode
, 0x200); /* Pass FBColorData */
192 WRITE(gmesa
->buf
, FBWriteMode
, FBW_UploadColorData
| FBWriteModeDisable
);
193 WRITE(gmesa
->buf
, StartXSub
, (x
+n
)<<16);
194 WRITE(gmesa
->buf
, StartXDom
, x
<<16);
195 WRITE(gmesa
->buf
, StartY
, y
<<16);
196 WRITE(gmesa
->buf
, GLINTCount
, 1);
197 WRITE(gmesa
->buf
, dXDom
, 0<<16);
198 WRITE(gmesa
->buf
, dXSub
, 0<<16);
199 WRITE(gmesa
->buf
, dY
, 1<<16);
200 WRITE(gmesa
->buf
, Render
, PrimitiveTrapezoid
);
201 FLUSH_DMA_BUFFER(gmesa
);
205 dwords1
= *(volatile uint32_t*)(void *)(((uint8_t*)gammascrn
->regions
[0].map
) + (GlintOutFIFOWords
));
206 dwords2
= *(volatile uint32_t*)(void *)(((uint8_t*)gammascrn
->regions
[2].map
) + (GlintOutFIFOWords
));
209 memcpy(src
, (char*)gammascrn
->regions
[1].map
+ 0x1000, dwords1
<< 2);
211 read
-= dwords1
<< 2;
214 memcpy(src
, (char*)gammascrn
->regions
[3].map
+ 0x1000, dwords2
<< 2);
216 read
-= dwords2
<< 2;
224 CHECK_DMA_BUFFER(gmesa
, 6);
225 WRITE(gmesa
->buf
, ColorDDAMode
, gmesa
->ColorDDAMode
);
226 WRITE(gmesa
->buf
, LBWriteMode
, LBWriteModeEnable
);
227 WRITE(gmesa
->buf
, LBReadMode
, gmesa
->LBReadMode
);
228 WRITE(gmesa
->buf
, FBReadMode
, gmesa
->FBReadMode
);
229 WRITE(gmesa
->buf
, FBWriteMode
, FBWriteModeEnable
);
230 WRITE(gmesa
->buf
, FilterMode
, 0x400);
234 static void gammaSetBuffer( GLcontext
*ctx
,
235 GLframebuffer
*colorBuffer
,
238 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
240 switch ( bufferBit
) {
241 case BUFFER_BIT_FRONT_LEFT
:
242 gmesa
->readOffset
= 0;
244 case BUFFER_BIT_BACK_LEFT
:
245 gmesa
->readOffset
= gmesa
->driScreen
->fbHeight
* gmesa
->driScreen
->fbWidth
* gmesa
->gammaScreen
->cpp
;
248 _mesa_problem(ctx
, "Unexpected buffer 0x%x in gammaSetBuffer()", bufferBit
);
253 void gammaDDInitSpanFuncs( GLcontext
*ctx
)
255 gammaContextPtr gmesa
= GAMMA_CONTEXT(ctx
);
256 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
258 swdd
->SetBuffer
= gammaSetBuffer
;
260 switch ( gmesa
->gammaScreen
->cpp
) {
262 swdd
->WriteRGBASpan
= gammaWriteRGBASpan_RGB565
;
263 swdd
->WriteRGBSpan
= gammaWriteRGBSpan_RGB565
;
264 swdd
->WriteMonoRGBASpan
= gammaWriteMonoRGBASpan_RGB565
;
265 swdd
->WriteRGBAPixels
= gammaWriteRGBAPixels_RGB565
;
266 swdd
->WriteMonoRGBAPixels
= gammaWriteMonoRGBAPixels_RGB565
;
267 swdd
->ReadRGBASpan
= gammaReadRGBASpan_RGB565
;
268 swdd
->ReadRGBAPixels
= gammaReadRGBAPixels_RGB565
;
272 swdd
->WriteRGBASpan
= gammaWriteRGBASpan_ARGB8888
;
273 swdd
->WriteRGBSpan
= gammaWriteRGBSpan_ARGB8888
;
274 swdd
->WriteMonoRGBASpan
= gammaWriteMonoRGBASpan_ARGB8888
;
275 swdd
->WriteRGBAPixels
= gammaWriteRGBAPixels_ARGB8888
;
276 swdd
->WriteMonoRGBAPixels
= gammaWriteMonoRGBAPixels_ARGB8888
;
278 swdd
->ReadRGBASpan
= gammaReadRGBASpan_ARGB8888
;
280 swdd
->ReadRGBASpan
= gammaReadRGBASpan8888
;
282 swdd
->ReadRGBAPixels
= gammaReadRGBAPixels_ARGB8888
;
289 switch ( gmesa
->glCtx
->Visual
.depthBits
) {
291 swdd
->ReadDepthSpan
= gammaReadDepthSpan_16
;
292 swdd
->WriteDepthSpan
= gammaWriteDepthSpan_16
;
293 swdd
->ReadDepthPixels
= gammaReadDepthPixels_16
;
294 swdd
->WriteDepthPixels
= gammaWriteDepthPixels_16
;
298 swdd
->ReadDepthSpan
= gammaReadDepthSpan_24_8
;
299 swdd
->WriteDepthSpan
= gammaWriteDepthSpan_24_8
;
300 swdd
->ReadDepthPixels
= gammaReadDepthPixels_24_8
;
301 swdd
->WriteDepthPixels
= gammaWriteDepthPixels_24_8
;
304 swdd
->ReadStencilSpan
= gammaReadStencilSpan_24_8
;
305 swdd
->WriteStencilSpan
= gammaWriteStencilSpan_24_8
;
306 swdd
->ReadStencilPixels
= gammaReadStencilPixels_24_8
;
307 swdd
->WriteStencilPixels
= gammaWriteStencilPixels_24_8
;