1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
/* $XFree86$ */
/**************************************************************************
Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
Cedar Park, Texas.
All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
on the rights to use, copy, modify, merge, publish, distribute, sub
license, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************/
/*
* Authors:
* Kevin E. Martin <kevin@precisioninsight.com>
*
*/
#ifdef GLX_DIRECT_RENDERING
/* r128 DDX driver includes */
#include "r128_dri.h"
#include "r128_reg.h"
/* r128 Mesa driver includes */
#include "r128_init.h"
#include "r128_context.h"
#include "r128_xmesa.h"
#include "r128_dd.h"
#include "r128_state.h"
#include "r128_span.h"
#include "r128_depth.h"
#include "r128_tex.h"
#include "r128_swap.h"
#include "r128_tris.h"
#include "r128_vb.h"
/* Mesa src includes */
#include "context.h"
#if 0
#include "vbxform.h"
#include "matrix.h"
#endif
#ifdef DEBUG_LOCKING
char *prevLockFile = NULL;
int prevLockLine = 0;
#endif
r128ContextPtr r128Context = NULL;
static int count_bits(unsigned int n)
{
int bits = 0;
while (n > 0) {
if (n & 1) bits++;
n >>= 1;
}
return bits;
}
GLboolean XMesaInitDriver(__DRIscreenPrivate *sPriv)
{
r128ScreenPtr r128Screen;
R128DRIPtr r128DRIPriv = (R128DRIPtr)sPriv->pDevPriv;
/* Allocate the private area */
r128Screen = (r128ScreenPtr)Xmalloc(sizeof(*r128Screen));
if (!r128Screen) return GL_FALSE;
r128Screen->mmioRgn.handle = r128DRIPriv->registerHandle;
r128Screen->mmioRgn.size = r128DRIPriv->registerSize;
if (drmMap(sPriv->fd,
r128Screen->mmioRgn.handle,
r128Screen->mmioRgn.size,
(drmAddressPtr)&r128Screen->mmio)) {
Xfree(r128Screen);
return GL_FALSE;
}
r128Screen->agpRgn.handle = r128DRIPriv->agpHandle;
r128Screen->agpRgn.size = r128DRIPriv->agpSize;
if (drmMap(sPriv->fd,
r128Screen->agpRgn.handle,
r128Screen->agpRgn.size,
(drmAddressPtr)&r128Screen->agp)) {
drmUnmap((drmAddress)r128Screen->mmio, r128Screen->mmioRgn.size);
Xfree(r128Screen);
return GL_FALSE;
}
r128Screen->deviceID = r128DRIPriv->deviceID;
r128Screen->width = r128DRIPriv->width;
r128Screen->height = r128DRIPriv->height;
r128Screen->depth = r128DRIPriv->depth;
r128Screen->bpp = r128DRIPriv->bpp;
r128Screen->fb = sPriv->pFB;
r128Screen->fbOffset = sPriv->fbOrigin;
r128Screen->fbStride = sPriv->fbStride;
r128Screen->fbSize = sPriv->fbSize;
r128Screen->fbX = r128DRIPriv->fbX;
r128Screen->fbY = r128DRIPriv->fbY;
r128Screen->backX = r128DRIPriv->backX;
r128Screen->backY = r128DRIPriv->backY;
r128Screen->depthX = r128DRIPriv->depthX;
r128Screen->depthY = r128DRIPriv->depthY;
r128Screen->textureX = r128DRIPriv->textureX;
r128Screen->textureY = r128DRIPriv->textureY;
r128Screen->textureSize = r128DRIPriv->textureSize;
#if 0
r128Screen->backX = 0;
r128Screen->backY = r128DRIPriv->height/2;
r128Screen->depthX = r128DRIPriv->width/2;
r128Screen->depthY = r128DRIPriv->height/2;
#endif
r128Screen->CCEMode = r128DRIPriv->CCEMode;
r128Screen->CCEFifoSize = r128DRIPriv->CCEFifoSize;
r128Screen->ringStart = r128DRIPriv->ringStart;
r128Screen->ringSize = r128DRIPriv->ringSize;
r128Screen->ringWritePtr = &r128DRIPriv->ringWrite;
r128Screen->ringReadPtr = (int *)(r128Screen->agp
+ r128DRIPriv->ringReadOffset);
r128Screen->MMIOFifoSlots = 0;
r128Screen->CCEFifoSlots = 0;
r128Screen->CCEFifoAddr = R128_PM4_FIFO_DATA_EVEN;
r128Screen->driScreen = sPriv;
sPriv->private = (void *)r128Screen;
r128TriangleFuncsInit();
r128SetupInit();
return GL_TRUE;
}
void XMesaResetDriver(__DRIscreenPrivate *sPriv)
{
r128ScreenPtr r128Screen = (r128ScreenPtr)sPriv->private;
drmUnmap((drmAddress)r128Screen->mmio, r128Screen->mmioRgn.size);
drmUnmap((drmAddress)r128Screen->agp, r128Screen->agpRgn.size);
Xfree(r128Screen);
sPriv->private = NULL;
}
XMesaVisual XMesaCreateVisual(XMesaDisplay *display,
XMesaVisualInfo visinfo,
GLboolean rgb_flag,
GLboolean alpha_flag,
GLboolean db_flag,
GLboolean stereo_flag,
GLboolean ximage_flag,
GLint depth_size,
GLint stencil_size,
GLint accum_size,
GLint level)
{
XMesaVisual v;
/* FIXME: Only RGB visuals are currently supported */
if (!rgb_flag) return NULL;
v = (XMesaVisual)Xmalloc(sizeof(*v));
if (!v) return NULL;
v->visinfo = (XVisualInfo *)Xmalloc(sizeof(*visinfo));
if(!v->visinfo) {
Xfree(v);
return NULL;
}
memcpy(v->visinfo, visinfo, sizeof(*visinfo));
v->display = display;
v->level = level;
v->gl_visual = (GLvisual *)Xmalloc(sizeof(*v->gl_visual));
if (!v->gl_visual) {
Xfree(v->visinfo);
XFree(v);
return NULL;
}
v->gl_visual->RGBAflag = rgb_flag;
v->gl_visual->DBflag = db_flag;
v->gl_visual->StereoFlag = stereo_flag;
v->gl_visual->RedBits = count_bits(visinfo->red_mask);
v->gl_visual->GreenBits = count_bits(visinfo->green_mask);
v->gl_visual->BlueBits = count_bits(visinfo->blue_mask);
v->gl_visual->AlphaBits = 0; /* Not currently supported */
v->gl_visual->AccumBits = accum_size;
v->gl_visual->DepthBits = depth_size;
v->gl_visual->StencilBits = stencil_size;
return v;
}
void XMesaDestroyVisual(XMesaVisual v)
{
Xfree(v->gl_visual);
Xfree(v->visinfo);
Xfree(v);
}
XMesaContext XMesaCreateContext(XMesaVisual v, XMesaContext share_list,
__DRIcontextPrivate *driContextPriv)
{
XMesaContext c;
r128ContextPtr r128ctx;
GLcontext *shareCtx, *glCtx;
c = (XMesaContext)Xmalloc(sizeof(*c));
if (!c) {
return NULL;
}
r128ctx = (r128ContextPtr)Xmalloc(sizeof(*r128ctx));
if (!r128ctx) {
Xfree(c);
return NULL;
}
/* Initialize XMesaContext */
c->display = v->display;
c->xm_visual = v;
c->xm_buffer = NULL; /* Set by MakeCurrent */
c->driContextPriv = driContextPriv;
c->private = (void *)r128ctx;
if (share_list)
shareCtx = ((r128ContextPtr)(share_list->private))->glCtx;
else
shareCtx = NULL;
/* Initialize r128Context */
r128ctx->xmCtx = c;
r128ctx->glCtx = gl_create_context(v->gl_visual,
shareCtx,
(void *)r128ctx,
GL_TRUE);
r128ctx->display = v->display;
r128ctx->driContext = driContextPriv;
r128ctx->driDrawable = NULL; /* Set by XMesaMakeCurrent */
r128ctx->dirty = R128_ALL_DIRTY;
r128ctx->needClip = GL_TRUE;
r128ctx->r128Screen =
(r128ScreenPtr)(driContextPriv->driScreenPriv->private);
/* Initialize GLcontext */
glCtx = r128ctx->glCtx;
r128DDInitExtensions(glCtx);
r128DDInitDriverFuncs(glCtx);
r128DDInitStateFuncs(glCtx);
r128DDInitSpanFuncs(glCtx);
r128DDInitDepthFuncs(glCtx);
r128DDInitTextureFuncs(glCtx);
#if 1
/* FIXME: Move to r128_tris.c */
glCtx->Driver.TriangleCaps = (DD_TRI_CULL
| DD_TRI_LIGHT_TWOSIDE
| DD_TRI_OFFSET);
glCtx->TriangleCaps |= DD_CLIP_FOG_COORD;
if (glCtx->VB) r128DDRegisterVB(glCtx->VB);
#endif
r128DDInitState(r128ctx);
return c;
}
void XMesaDestroyContext(XMesaContext c)
{
r128ContextPtr r128ctx = (r128ContextPtr)c->private;
if (r128ctx) {
gl_destroy_context(r128ctx->glCtx);
Xfree(r128ctx);
c->private = NULL;
}
if (c->private == (void *)r128Context) {
r128Context = NULL;
}
}
XMesaBuffer XMesaCreateWindowBuffer(XMesaVisual v,
XMesaWindow w,
__DRIdrawablePrivate *driDrawPriv)
{
XMesaBuffer xm_buf;
xm_buf = (XMesaBuffer)Xmalloc(sizeof(*xm_buf));
xm_buf->gl_buffer = gl_create_framebuffer(v->gl_visual);
xm_buf->driDrawPriv = driDrawPriv;
return xm_buf;
}
XMesaBuffer XMesaCreatePixmapBuffer(XMesaVisual v,
XMesaPixmap p,
XMesaColormap c,
__DRIdrawablePrivate *driDrawPriv)
{
XMesaBuffer xm_buf;
xm_buf = (XMesaBuffer)Xmalloc(sizeof(*xm_buf));
xm_buf->gl_buffer = gl_create_framebuffer(v->gl_visual);
xm_buf->driDrawPriv = driDrawPriv;
return xm_buf;
}
void XMesaDestroyBuffer(XMesaBuffer b)
{
gl_destroy_framebuffer(b->gl_buffer);
Xfree(b);
}
void XMesaSwapBuffers(XMesaBuffer b)
{
/*
** FIXME: This assumes buffer is currently bound to a context.
** This needs to be able to swap buffers when not currently bound.
*/
if (r128Context == NULL) return;
r128SwapBuffers(r128Context);
}
GLboolean XMesaMakeCurrent(XMesaContext c, XMesaBuffer b)
{
if (c) {
r128ContextPtr oldCtx = r128Context;
if (r128Context
&& c->private == (void *)r128Context
&& b->driDrawPriv == r128Context->driDrawable) return GL_TRUE;
r128Context = (r128ContextPtr)c->private;
if (oldCtx) {
r128Context->dirty = R128_REQUIRE_QUIESCENCE | R128_START_CCE;
if (oldCtx != r128Context)
r128Context->dirty |= R128_UPDATE_CONTEXT;
if (oldCtx->driDrawable != b->driDrawPriv)
r128Context->dirty |= R128_UPDATE_CLIPRECTS;
} else {
r128Context->dirty = R128_ALL_DIRTY;
}
r128Context->driDrawable = b->driDrawPriv;
gl_make_current(r128Context->glCtx, b->gl_buffer);
if (!r128Context->glCtx->Viewport.Width) {
gl_Viewport(r128Context->glCtx, 0, 0,
b->driDrawPriv->w, b->driDrawPriv->h);
}
} else {
gl_make_current(0,0);
r128Context = NULL;
}
return GL_TRUE;
}
void XMesaUpdateState(XMesaContext c)
{
r128ContextPtr r128ctx = (r128ContextPtr)c->private;
__DRIdrawablePrivate *dPriv = r128ctx->driDrawable;
__DRIscreenPrivate *sPriv = r128ctx->r128Screen->driScreen;
int stamp = dPriv->lastStamp;
/*
* The window might have moved, so we might need to get new
* cliprects.
*
* NOTE: This releases and regrabs the hw lock, so all state
* checking must be done *after* this call.
*/
XMESA_VALIDATE_DRAWABLE_INFO(r128ctx->display, sPriv, dPriv);
r128ctx->dirty |= R128_ALL_DIRTY; /* FIXME: Optimize this!! */
if (stamp != dPriv->lastStamp) { /* FIXME??: handle window moves */
r128ctx->dirty |= R128_UPDATE_CLIPRECTS;
}
if (r128ctx->dirty) r128UpdateStateLocked(r128ctx);
}
#endif
|