Some more nouveau_screen.c setup, not sure how correct it is yet though..
[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_driver.h"
43 //#include "nouveau_state.h"
44 #include "nouveau_span.h"
45 #include "nouveau_object.h"
46 #include "nouveau_fifo.h"
47 #include "nouveau_tex.h"
48 #include "nv10_swtcl.h"
49
50 #include "vblank.h"
51 #include "utils.h"
52 #include "texmem.h"
53 #include "xmlpool.h" /* for symbolic values of enum-type options */
54
55 #ifndef NOUVEAU_DEBUG
56 int NOUVEAU_DEBUG = 0;
57 #endif
58
59 static const struct dri_debug_control debug_control[] =
60 {
61 { NULL, 0 }
62 };
63
64 const struct dri_extension common_extensions[] =
65 {
66 { NULL, 0 }
67 };
68
69 /* Create the device specific context.
70 */
71 GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
72 __DRIcontextPrivate *driContextPriv,
73 void *sharedContextPrivate )
74 {
75 GLcontext *ctx, *shareCtx;
76 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
77 struct dd_function_table functions;
78 nouveauContextPtr nmesa;
79 nouveauScreenPtr screen;
80
81 /* Allocate the context */
82 nmesa = (nouveauContextPtr) CALLOC( sizeof(*nmesa) );
83 if ( !nmesa )
84 return GL_FALSE;
85
86 nmesa->driContext = driContextPriv;
87 nmesa->driScreen = sPriv;
88 nmesa->driDrawable = NULL;
89 nmesa->hHWContext = driContextPriv->hHWContext;
90 nmesa->driHwLock = &sPriv->pSAREA->lock;
91 nmesa->driFd = sPriv->fd;
92
93 nmesa->screen = (nouveauScreenPtr)(sPriv->private);
94 screen=nmesa->screen;
95
96 /* Create the hardware context */
97 if (!nouveauFifoInit(nmesa))
98 return GL_FALSE;
99 nouveauObjectInit(nmesa);
100
101 /* Init default driver functions then plug in our nouveau-specific functions
102 * (the texture functions are especially important)
103 */
104 _mesa_init_driver_functions( &functions );
105 nouveauDriverInitFunctions( &functions );
106 nouveauTexInitFunctions( &functions );
107
108 /* Allocate the Mesa context */
109 if (sharedContextPrivate)
110 shareCtx = ((nouveauContextPtr) sharedContextPrivate)->glCtx;
111 else
112 shareCtx = NULL;
113 nmesa->glCtx = _mesa_create_context(glVisual, shareCtx,
114 &functions, (void *) nmesa);
115 if (!nmesa->glCtx) {
116 FREE(nmesa);
117 return GL_FALSE;
118 }
119 driContextPriv->driverPrivate = nmesa;
120 ctx = nmesa->glCtx;
121
122 /* Parse configuration files */
123 driParseConfigFiles (&nmesa->optionCache, &screen->optionCache,
124 screen->driScreen->myNum, "nouveau");
125
126 nmesa->sarea = (drm_nouveau_sarea_t *)((char *)sPriv->pSAREA +
127 screen->sarea_priv_offset);
128
129
130 nmesa->current_primitive = -1;
131
132 /* Initialize the swrast */
133 _swrast_CreateContext( ctx );
134 _ac_CreateContext( ctx );
135 _tnl_CreateContext( ctx );
136 _swsetup_CreateContext( ctx );
137
138 switch(nmesa->screen->card->type)
139 {
140 case NV_03:
141 //nv03TriInitFunctions( ctx );
142 break;
143 case NV_04:
144 case NV_05:
145 //nv04TriInitFunctions( ctx );
146 break;
147 case NV_10:
148 case NV_20:
149 case NV_30:
150 case NV_40:
151 case G_70:
152 default:
153 nv10TriInitFunctions( ctx );
154 break;
155 }
156 nouveauDDInitStateFuncs( ctx );
157 nouveauSpanInitFunctions( ctx );
158 nouveauDDInitState( nmesa );
159
160 driContextPriv->driverPrivate = (void *)nmesa;
161
162 NOUVEAU_DEBUG = driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
163 debug_control );
164
165 if (driQueryOptionb(&nmesa->optionCache, "no_rast")) {
166 fprintf(stderr, "disabling 3D acceleration\n");
167 FALLBACK(nmesa, NOUVEAU_FALLBACK_DISABLE, 1);
168 }
169
170 return GL_TRUE;
171 }
172
173 /* Destroy the device specific context. */
174 void nouveauDestroyContext( __DRIcontextPrivate *driContextPriv )
175 {
176 nouveauContextPtr nmesa = (nouveauContextPtr) driContextPriv->driverPrivate;
177
178 assert(nmesa);
179 if ( nmesa ) {
180 /* free the option cache */
181 driDestroyOptionCache (&nmesa->optionCache);
182
183 FREE( nmesa );
184 }
185
186 }
187
188
189 /* Force the context `c' to be the current context and associate with it
190 * buffer `b'.
191 */
192 GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
193 __DRIdrawablePrivate *driDrawPriv,
194 __DRIdrawablePrivate *driReadPriv )
195 {
196 if ( driContextPriv ) {
197 GET_CURRENT_CONTEXT(ctx);
198 nouveauContextPtr oldNOUVEAUCtx = ctx ? NOUVEAU_CONTEXT(ctx) : NULL;
199 nouveauContextPtr newNOUVEAUCtx = (nouveauContextPtr) driContextPriv->driverPrivate;
200
201 driDrawableInitVBlank(driDrawPriv, newNOUVEAUCtx->vblank_flags, &newNOUVEAUCtx->vblank_seq );
202 newNOUVEAUCtx->driDrawable = driDrawPriv;
203
204 _mesa_make_current( newNOUVEAUCtx->glCtx,
205 (GLframebuffer *) driDrawPriv->driverPrivate,
206 (GLframebuffer *) driReadPriv->driverPrivate );
207
208 } else {
209 _mesa_make_current( NULL, NULL, NULL );
210 }
211
212 return GL_TRUE;
213 }
214
215
216 /* Force the context `c' to be unbound from its buffer.
217 */
218 GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv )
219 {
220 return GL_TRUE;
221 }
222
223 void nouveauSwapBuffers(__DRIdrawablePrivate *dPriv)
224 {
225 }
226
227 void nouveauCopySubBuffer(__DRIdrawablePrivate *dPriv,
228 int x, int y, int w, int h)
229 {
230 }
231