Remove leftover __DRI{screen,drawable,context}Private references
[mesa.git] / src / mesa / drivers / dri / gamma / gamma_span.c
1
2 #include "gammacontext.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 __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 + \
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 __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 + \
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 VALUE_TYPE GLushort
115
116 #define WRITE_DEPTH( _x, _y, d ) \
117 *(GLushort *)(buf + (_x)*2 + (_y)*pitch) = d;
118
119 #define READ_DEPTH( d, _x, _y ) \
120 d = *(GLushort *)(buf + (_x)*2 + (_y)*pitch);
121
122 #define TAG(x) gamma##x##_16
123 #include "depthtmp.h"
124
125
126 #if 0 /* Unused */
127 /* 32 bit depthbuffer functions.
128 */
129 #define VALUE_TYPE GLuint
130
131 #define WRITE_DEPTH( _x, _y, d ) \
132 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = d;
133
134 #define READ_DEPTH( d, _x, _y ) \
135 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch);
136
137 #define TAG(x) gamma##x##_32
138 #include "depthtmp.h"
139 #endif
140
141
142 /* 24/8 bit interleaved depth/stencil functions
143 */
144 #define VALUE_TYPE GLuint
145
146 #define WRITE_DEPTH( _x, _y, d ) { \
147 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*pitch); \
148 tmp &= 0xff; \
149 tmp |= (d) & 0xffffff00; \
150 *(GLuint *)(buf + (_x)*4 + (_y)*pitch) = tmp; \
151 }
152
153 #define READ_DEPTH( d, _x, _y ) \
154 d = *(GLuint *)(buf + (_x)*4 + (_y)*pitch) & ~0xff;
155
156
157 #define TAG(x) gamma##x##_24_8
158 #include "depthtmp.h"
159
160 #if 0
161 #define WRITE_STENCIL( _x, _y, d ) { \
162 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*pitch); \
163 tmp &= 0xffffff00; \
164 tmp |= d & 0xff; \
165 *(GLuint *)(buf + _x*4 + _y*pitch) = tmp; \
166 }
167
168 #define READ_STENCIL( d, _x, _y ) \
169 d = *(GLuint *)(buf + _x*4 + _y*pitch) & 0xff;
170
171 #define TAG(x) gamma##x##_24_8
172 #include "stenciltmp.h"
173
174 static void gammaReadRGBASpan8888( const GLcontext *ctx,
175 GLuint n, GLint x, GLint y,
176 GLubyte rgba[][4])
177 {
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 */
183 uint32_t data;
184
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);
202
203 moredata:
204
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));
207
208 if (dwords1) {
209 memcpy(src, (char*)gammascrn->regions[1].map + 0x1000, dwords1 << 2);
210 src += dwords1 << 2;
211 read -= dwords1 << 2;
212 }
213 if (dwords2) {
214 memcpy(src, (char*)gammascrn->regions[3].map + 0x1000, dwords2 << 2);
215 src += dwords2 << 2;
216 read -= dwords2 << 2;
217 }
218
219 if (read)
220 goto moredata;
221
222 done:
223
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);
231 }
232 #endif
233
234 static void gammaSetBuffer( GLcontext *ctx,
235 GLframebuffer *colorBuffer,
236 GLuint bufferBit )
237 {
238 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
239
240 switch ( bufferBit ) {
241 case BUFFER_BIT_FRONT_LEFT:
242 gmesa->readOffset = 0;
243 break;
244 case BUFFER_BIT_BACK_LEFT:
245 gmesa->readOffset = gmesa->driScreen->fbHeight * gmesa->driScreen->fbWidth * gmesa->gammaScreen->cpp;
246 break;
247 default:
248 _mesa_problem(ctx, "Unexpected buffer 0x%x in gammaSetBuffer()", bufferBit);
249 }
250 }
251
252
253 void gammaDDInitSpanFuncs( GLcontext *ctx )
254 {
255 gammaContextPtr gmesa = GAMMA_CONTEXT(ctx);
256 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
257
258 swdd->SetBuffer = gammaSetBuffer;
259
260 switch ( gmesa->gammaScreen->cpp ) {
261 case 2:
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;
269 break;
270
271 case 4:
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;
277 #if 1
278 swdd->ReadRGBASpan = gammaReadRGBASpan_ARGB8888;
279 #else
280 swdd->ReadRGBASpan = gammaReadRGBASpan8888;
281 #endif
282 swdd->ReadRGBAPixels = gammaReadRGBAPixels_ARGB8888;
283 break;
284
285 default:
286 break;
287 }
288
289 switch ( gmesa->glCtx->Visual.depthBits ) {
290 case 16:
291 swdd->ReadDepthSpan = gammaReadDepthSpan_16;
292 swdd->WriteDepthSpan = gammaWriteDepthSpan_16;
293 swdd->ReadDepthPixels = gammaReadDepthPixels_16;
294 swdd->WriteDepthPixels = gammaWriteDepthPixels_16;
295 break;
296
297 case 24:
298 swdd->ReadDepthSpan = gammaReadDepthSpan_24_8;
299 swdd->WriteDepthSpan = gammaWriteDepthSpan_24_8;
300 swdd->ReadDepthPixels = gammaReadDepthPixels_24_8;
301 swdd->WriteDepthPixels = gammaWriteDepthPixels_24_8;
302
303 #if 0
304 swdd->ReadStencilSpan = gammaReadStencilSpan_24_8;
305 swdd->WriteStencilSpan = gammaWriteStencilSpan_24_8;
306 swdd->ReadStencilPixels = gammaReadStencilPixels_24_8;
307 swdd->WriteStencilPixels = gammaWriteStencilPixels_24_8;
308 #endif
309 break;
310
311 default:
312 break;
313 }
314 }