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