Cleaned stuff in the tcl code
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_context.c
1 /**************************************************************************
2
3 Copyright 2006 Stephane Marchesin
4 All Rights Reserved.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
15 Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 **************************************************************************/
26
27 #include "glheader.h"
28 #include "context.h"
29 #include "simple_list.h"
30 #include "imports.h"
31 #include "matrix.h"
32 #include "swrast/swrast.h"
33 #include "swrast_setup/swrast_setup.h"
34 #include "array_cache/acache.h"
35
36 #include "tnl/tnl.h"
37 #include "tnl/t_pipeline.h"
38
39 #include "drivers/common/driverfuncs.h"
40
41 #include "nouveau_context.h"
42 #include "nouveau_ioctl.h"
43 #include "nouveau_driver.h"
44 //#include "nouveau_state.h"
45 #include "nouveau_span.h"
46 #include "nouveau_tex.h"
47 #include "nv10_swtcl.h"
48
49 #include "vblank.h"
50 #include "utils.h"
51 #include "texmem.h"
52 #include "xmlpool.h" /* for symbolic values of enum-type options */
53
54 #ifndef NOUVEAU_DEBUG
55 int NOUVEAU_DEBUG = 0;
56 #endif
57
58 #define NOUVEAU_FALLBACK_DISABLE 1
59
60 static const struct dri_debug_control debug_control[] =
61 {
62 { NULL, 0 }
63 };
64
65 /* Create the device specific context.
66 */
67 GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
68 __DRIcontextPrivate *driContextPriv,
69 void *sharedContextPrivate )
70 {
71 GLcontext *ctx, *shareCtx;
72 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
73 struct dd_function_table functions;
74 nouveauContextPtr nmesa;
75 nouveauScreenPtr screen;
76 int i;
77
78 /* Allocate the context */
79 nmesa = (nouveauContextPtr) CALLOC( sizeof(*nmesa) );
80 if ( !nmesa )
81 return GL_FALSE;
82
83 /* Init default driver functions then plug in our Radeon-specific functions
84 * (the texture functions are especially important)
85 */
86 _mesa_init_driver_functions( &functions );
87 nouveauDriverInitFunctions( &functions );
88 nouveauIoctlInitFunctions( &functions );
89 nouveauTexInitFunctions( &functions );
90
91 /* Allocate the Mesa context */
92 if (sharedContextPrivate)
93 shareCtx = ((nouveauContextPtr) sharedContextPrivate)->glCtx;
94 else
95 shareCtx = NULL;
96 nmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
97 &functions, (void *) nmesa);
98 if (!nmesa->glCtx) {
99 FREE(nmesa);
100 return GL_FALSE;
101 }
102 driContextPriv->driverPrivate = nmesa;
103 ctx = nmesa->glCtx;
104
105 nmesa->driContext = driContextPriv;
106 nmesa->driScreen = sPriv;
107 nmesa->driDrawable = NULL;
108 nmesa->hHWContext = driContextPriv->hHWContext;
109 nmesa->driHwLock = &sPriv->pSAREA->lock;
110 nmesa->driFd = sPriv->fd;
111
112 nmesa->screen = (nouveauScreenPtr)(sPriv->private);
113 screen=nmesa->screen;
114
115 /* Parse configuration files */
116 driParseConfigFiles (&nmesa->optionCache, &screen->optionCache,
117 screen->driScreen->myNum, "nouveau");
118
119 nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA +
120 screen->sarea_priv_offset);
121
122
123 nmesa->current_primitive = -1;
124
125 /* Initialize the swrast */
126 _swrast_CreateContext( ctx );
127 _ac_CreateContext( ctx );
128 _tnl_CreateContext( ctx );
129 _swsetup_CreateContext( ctx );
130
131 switch(nmesa->screen->card_type)
132 {
133 case NV_03:
134 case NV_04:
135 case NV_05:
136 default:
137 //nv03TriInitFunctions( ctx );
138 break;
139 case NV_10:
140 case NV_20:
141 case NV_30:
142 case NV_40:
143 case G_70:
144 nv10TriInitFunctions( ctx );
145 break;
146 }
147 nouveauDDInitStateFuncs( ctx );
148 nouveauSpanInitFunctions( ctx );
149 nouveauDDInitState( nmesa );
150
151 driContextPriv->driverPrivate = (void *)nmesa;
152
153 NOUVEAU_DEBUG = driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
154 debug_control );
155
156 if (driQueryOptionb(&nmesa->optionCache, "no_rast")) {
157 fprintf(stderr, "disabling 3D acceleration\n");
158 FALLBACK(nmesa, NOUVEAU_FALLBACK_DISABLE, 1);
159 }
160
161 return GL_TRUE;
162 }
163
164 /* Destroy the device specific context. */
165 void nouveauDestroyContext( __DRIcontextPrivate *driContextPriv )
166 {
167 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
168
169 assert(nmesa);
170 if ( nmesa ) {
171 /* free the option cache */
172 driDestroyOptionCache (&nmesa->optionCache);
173
174 FREE( nmesa );
175 }
176
177 }
178
179
180 /* Force the context `c' to be the current context and associate with it
181 * buffer `b'.
182 */
183 GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
184 __DRIdrawablePrivate *driDrawPriv,
185 __DRIdrawablePrivate *driReadPriv )
186 {
187 if ( driContextPriv ) {
188 GET_CURRENT_CONTEXT(ctx);
189 nouveauContextPtr oldNOUVEAUCtx = ctx ? NOUVEAU_CONTEXT(ctx) : NULL;
190 nouveauContextPtr newNOUVEAUCtx = (nouveauContextPtr) driContextPriv->driverPrivate;
191
192 driDrawableInitVBlank( driDrawPriv, newNOUVEAUCtx->vblank_flags );
193 newNOUVEAUCtx->driDrawable = driDrawPriv;
194
195 _mesa_make_current( newNOUVEAUCtx->glCtx,
196 (GLframebuffer *) driDrawPriv->driverPrivate,
197 (GLframebuffer *) driReadPriv->driverPrivate );
198
199 } else {
200 _mesa_make_current( NULL, NULL, NULL );
201 }
202
203 return GL_TRUE;
204 }
205
206
207 /* Force the context `c' to be unbound from its buffer.
208 */
209 GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv )
210 {
211 return GL_TRUE;
212 }