summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/r128/r128_context.c
blob: 5cf776d5f98ed15a79ce49cf5ace9880d9170183 (plain)
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
/* $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>
 *
 */

#include "r128_init.h"
#include "r128_mesa.h"
#include "r128_xmesa.h"
#include "r128_context.h"
#include "r128_dd.h"
#include "r128_state.h"
#include "r128_span.h"
#include "r128_tex.h"
#include "r128_vb.h"
#include "r128_pipeline.h"

#include "context.h"
#include "simple_list.h"

/* Create the device specific context */
r128ContextPtr r128CreateContext(GLvisual *glVisual,
				 XMesaContext c,
				 XMesaContext share_list)
{
    r128ContextPtr  r128ctx;
    r128ScreenPtr   r128scrn;
    GLcontext      *shareCtx, *glCtx;
    int             i;

    r128ctx = (r128ContextPtr)Xmalloc(sizeof(*r128ctx));
    if (!r128ctx) return NULL;

    if (share_list)
	shareCtx = ((r128ContextPtr)(share_list->private))->glCtx;
    else
	shareCtx = NULL;

    /* Initialize r128Context */
    r128ctx->xmCtx         = c;
    r128ctx->glCtx         = gl_create_context(glVisual,
					       shareCtx,
					       (void *)r128ctx,
					       GL_TRUE);
    r128ctx->display       = c->display;
    r128ctx->driContext    = c->driContextPriv;
    r128ctx->driDrawable   = NULL; /* Set by XMesaMakeCurrent */
    r128ctx->dirty         = R128_ALL_DIRTY;
    r128ctx->dirty_context = R128_CTX_ALL_DIRTY;

    if (getenv("LIBGL_SOFTWARE_RENDERING"))
	r128ctx->SWonly    = GL_TRUE;
    else
	r128ctx->SWonly    = GL_FALSE;
    if (getenv("LIBGL_NO_SOFTWARE_FALLBACKS"))
	r128ctx->SWfallbackDisable = GL_TRUE;
    else
	r128ctx->SWfallbackDisable = GL_FALSE;
    r128scrn = r128ctx->r128Screen =
	(r128ScreenPtr)(c->driContextPriv->driScreenPriv->private);

    r128ctx->CurrentTexObj[0] = NULL;
    r128ctx->CurrentTexObj[1] = NULL;
    make_empty_list(&r128ctx->SwappedOut);
    for (i = 0; i < R128_NR_TEX_HEAPS; i++) {
	make_empty_list(&r128ctx->TexObjList[i]);
	r128ctx->texHeap[i] = mmInit(0, r128scrn->texSize[i]);
	r128ctx->lastTexAge[i] = -1;
    }

    r128ctx->lastSwapAge      = 0;

    r128ctx->useFastPath      = GL_FALSE;

    r128ctx->vb.start         = 0;
    r128ctx->vb.count         = 0;
    r128ctx->vb.size          = 0;
    r128ctx->vb.index         = 0;
    r128ctx->vb.buf           = NULL;
    r128ctx->vb.done          = GL_TRUE;

    if (getenv("LIBGL_DISABLE_VERTEX_BUFFERS"))
	r128ctx->disableVB    = GL_TRUE;
    else
	r128ctx->disableVB    = GL_FALSE;

    r128ctx->CCEbuf           = (CARD32 *)malloc(sizeof(*r128ctx->CCEbuf) *
						 r128scrn->ringEntries);
    r128ctx->CCEcount         = 0;

    /* Initialize GLcontext */
    glCtx = r128ctx->glCtx;

    r128DDInitExtensions(glCtx);

    r128DDInitDriverFuncs(glCtx);
    r128DDInitStateFuncs(glCtx);
    r128DDInitSpanFuncs(glCtx);
    r128DDInitTextureFuncs(glCtx);

    glCtx->Driver.TriangleCaps = (DD_TRI_CULL
				  | DD_TRI_LIGHT_TWOSIDE
				  | DD_TRI_OFFSET);
#if 0
    /* FIXME */
    glCtx->TriangleCaps |= DD_CLIP_FOG_COORD;
#endif

    /* Reset Mesa's current 2D texture pointers to the driver's textures */
    glCtx->Shared->DefaultD[2][0].DriverData = NULL;
    glCtx->Shared->DefaultD[2][1].DriverData = NULL;

    /* If Mesa has current a vertex buffer, make sure the driver's VB
       data is up to date */
    if (glCtx->VB) r128DDRegisterVB(glCtx->VB);

    /* Register the fast path */
    if (glCtx->NrPipelineStages)
	glCtx->NrPipelineStages =
	    r128RegisterPipelineStages(glCtx->PipelineStage,
				       glCtx->PipelineStage,
				       glCtx->NrPipelineStages);

    r128DDInitState(r128ctx);

    return r128ctx;
}

/* Destroy the device specific context */
void r128DestroyContext(r128ContextPtr r128ctx)
{
    if (r128ctx) {
	r128TexObjPtr t, next_t;
	int           i;

	free(r128ctx->CCEbuf);

	for (i = 0; i < R128_NR_TEX_HEAPS; i++) {
	    foreach_s (t, next_t, &r128ctx->TexObjList[i])
		r128DestroyTexObj(r128ctx, t);
	}

	foreach_s (t, next_t, &r128ctx->SwappedOut)
	    r128DestroyTexObj(r128ctx, t);

	gl_destroy_context(r128ctx->glCtx);
	Xfree(r128ctx);
    }
}

/* Load the device specific context into the hardware.  The actual
   setting of the hardware state is done in the r128UpdateHWState(). */
r128ContextPtr r128MakeCurrent(r128ContextPtr oldCtx,
			       r128ContextPtr newCtx,
			       __DRIdrawablePrivate *dPriv)
{
    if (oldCtx) {
	newCtx->dirty = R128_REQUIRE_QUIESCENCE;
	if (oldCtx != newCtx) {
	    newCtx->dirty         |= R128_UPDATE_CONTEXT;
	    newCtx->dirty_context  = R128_CTX_ALL_DIRTY;
	}
	if (oldCtx->driDrawable != dPriv)
	    newCtx->dirty |= R128_UPDATE_WINPOS;
    } else {
	newCtx->dirty         = R128_ALL_DIRTY;
	newCtx->dirty_context = R128_CTX_ALL_DIRTY;
    }

    newCtx->driDrawable = dPriv;

    return newCtx;
}