1 /**************************************************************************
3 Copyright 2006 Stephane Marchesin
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:
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
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.
25 **************************************************************************/
29 #include "simple_list.h"
32 #include "swrast/swrast.h"
33 #include "swrast_setup/swrast_setup.h"
34 #include "array_cache/acache.h"
37 #include "tnl/t_pipeline.h"
39 #include "drivers/common/driverfuncs.h"
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 "nv30_tris.h"
52 #include "xmlpool.h" /* for symbolic values of enum-type options */
55 int NOUVEAU_DEBUG
= 0;
58 static const struct dri_debug_control debug_control
[] =
63 /* Create the device specific context.
65 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
66 __DRIcontextPrivate
*driContextPriv
,
67 void *sharedContextPrivate
)
69 GLcontext
*ctx
, *shareCtx
;
70 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
71 struct dd_function_table functions
;
72 nouveauContextPtr nmesa
;
73 nouveauScreenPtr screen
;
76 /* Allocate the context */
77 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
81 /* Init default driver functions then plug in our Radeon-specific functions
82 * (the texture functions are especially important)
84 _mesa_init_driver_functions( &functions
);
85 nouveauDriverInitFunctions( &functions
);
86 nouveauIoctlInitFunctions( &functions
);
87 nouveauTexInitFunctions( &functions
);
89 /* Allocate the Mesa context */
90 if (sharedContextPrivate
)
91 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
94 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
95 &functions
, (void *) nmesa
);
100 driContextPriv
->driverPrivate
= nmesa
;
103 nmesa
->driContext
= driContextPriv
;
104 nmesa
->driScreen
= sPriv
;
105 nmesa
->driDrawable
= NULL
;
106 nmesa
->hHWContext
= driContextPriv
->hHWContext
;
107 nmesa
->driHwLock
= &sPriv
->pSAREA
->lock
;
108 nmesa
->driFd
= sPriv
->fd
;
110 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
111 screen
=nmesa
->screen
;
113 /* Parse configuration files */
114 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
115 screen
->driScreen
->myNum
, "nouveau");
117 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
118 screen
->sarea_priv_offset
);
121 nmesa
->current_primitive
= -1;
123 /* Initialize the swrast */
124 _swrast_CreateContext( ctx
);
125 _ac_CreateContext( ctx
);
126 _tnl_CreateContext( ctx
);
127 _swsetup_CreateContext( ctx
);
129 switch(nmesa
->screen
->card_type
)
141 nv30TriInitFunctions( ctx
);
144 nouveauDDInitStateFuncs( ctx
);
145 nouveauSpanInitFunctions( ctx
);
146 nouveauDDInitState( nmesa
);
148 driContextPriv
->driverPrivate
= (void *)nmesa
;
150 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
153 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
154 fprintf(stderr
, "disabling 3D acceleration\n");
155 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
161 /* Destroy the device specific context. */
162 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
164 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
168 /* free the option cache */
169 driDestroyOptionCache (&nmesa
->optionCache
);
177 /* Force the context `c' to be the current context and associate with it
180 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
181 __DRIdrawablePrivate
*driDrawPriv
,
182 __DRIdrawablePrivate
*driReadPriv
)
184 if ( driContextPriv
) {
185 GET_CURRENT_CONTEXT(ctx
);
186 nouveauContextPtr oldNOUVEAUCtx
= ctx
? NOUVEAU_CONTEXT(ctx
) : NULL
;
187 nouveauContextPtr newNOUVEAUCtx
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
189 driDrawableInitVBlank( driDrawPriv
, newNOUVEAUCtx
->vblank_flags
);
190 newNOUVEAUCtx
->driDrawable
= driDrawPriv
;
192 _mesa_make_current( newNOUVEAUCtx
->glCtx
,
193 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
194 (GLframebuffer
*) driReadPriv
->driverPrivate
);
197 _mesa_make_current( NULL
, NULL
, NULL
);
204 /* Force the context `c' to be unbound from its buffer.
206 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)