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_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"
53 #include "xmlpool.h" /* for symbolic values of enum-type options */
56 int NOUVEAU_DEBUG
= 0;
59 static const struct dri_debug_control debug_control
[] =
64 const struct dri_extension common_extensions
[] =
69 /* Create the device specific context.
71 GLboolean
nouveauCreateContext( const __GLcontextModes
*glVisual
,
72 __DRIcontextPrivate
*driContextPriv
,
73 void *sharedContextPrivate
)
75 GLcontext
*ctx
, *shareCtx
;
76 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
77 struct dd_function_table functions
;
78 nouveauContextPtr nmesa
;
79 nouveauScreenPtr screen
;
81 /* Allocate the context */
82 nmesa
= (nouveauContextPtr
) CALLOC( sizeof(*nmesa
) );
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
;
93 nmesa
->screen
= (nouveauScreenPtr
)(sPriv
->private);
96 /* Create the hardware context */
97 if (!nouveauFifoInit(nmesa
))
99 nouveauObjectInit(nmesa
);
101 /* Init default driver functions then plug in our nouveau-specific functions
102 * (the texture functions are especially important)
104 _mesa_init_driver_functions( &functions
);
105 nouveauDriverInitFunctions( &functions
);
106 nouveauTexInitFunctions( &functions
);
108 /* Allocate the Mesa context */
109 if (sharedContextPrivate
)
110 shareCtx
= ((nouveauContextPtr
) sharedContextPrivate
)->glCtx
;
113 nmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
114 &functions
, (void *) nmesa
);
119 driContextPriv
->driverPrivate
= nmesa
;
122 /* Parse configuration files */
123 driParseConfigFiles (&nmesa
->optionCache
, &screen
->optionCache
,
124 screen
->driScreen
->myNum
, "nouveau");
126 nmesa
->sarea
= (drm_nouveau_sarea_t
*)((char *)sPriv
->pSAREA
+
127 screen
->sarea_priv_offset
);
130 nmesa
->current_primitive
= -1;
132 /* Initialize the swrast */
133 _swrast_CreateContext( ctx
);
134 _ac_CreateContext( ctx
);
135 _tnl_CreateContext( ctx
);
136 _swsetup_CreateContext( ctx
);
138 switch(nmesa
->screen
->card
->type
)
141 //nv03TriInitFunctions( ctx );
145 //nv04TriInitFunctions( ctx );
153 nv10TriInitFunctions( ctx
);
156 nouveauDDInitStateFuncs( ctx
);
157 nouveauSpanInitFunctions( ctx
);
158 nouveauDDInitState( nmesa
);
160 driContextPriv
->driverPrivate
= (void *)nmesa
;
162 NOUVEAU_DEBUG
= driParseDebugString( getenv( "NOUVEAU_DEBUG" ),
165 if (driQueryOptionb(&nmesa
->optionCache
, "no_rast")) {
166 fprintf(stderr
, "disabling 3D acceleration\n");
167 FALLBACK(nmesa
, NOUVEAU_FALLBACK_DISABLE
, 1);
173 /* Destroy the device specific context. */
174 void nouveauDestroyContext( __DRIcontextPrivate
*driContextPriv
)
176 nouveauContextPtr nmesa
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
180 /* free the option cache */
181 driDestroyOptionCache (&nmesa
->optionCache
);
189 /* Force the context `c' to be the current context and associate with it
192 GLboolean
nouveauMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
193 __DRIdrawablePrivate
*driDrawPriv
,
194 __DRIdrawablePrivate
*driReadPriv
)
196 if ( driContextPriv
) {
197 GET_CURRENT_CONTEXT(ctx
);
198 nouveauContextPtr oldNOUVEAUCtx
= ctx
? NOUVEAU_CONTEXT(ctx
) : NULL
;
199 nouveauContextPtr newNOUVEAUCtx
= (nouveauContextPtr
) driContextPriv
->driverPrivate
;
201 driDrawableInitVBlank(driDrawPriv
, newNOUVEAUCtx
->vblank_flags
, &newNOUVEAUCtx
->vblank_seq
);
202 newNOUVEAUCtx
->driDrawable
= driDrawPriv
;
204 _mesa_make_current( newNOUVEAUCtx
->glCtx
,
205 (GLframebuffer
*) driDrawPriv
->driverPrivate
,
206 (GLframebuffer
*) driReadPriv
->driverPrivate
);
209 _mesa_make_current( NULL
, NULL
, NULL
);
216 /* Force the context `c' to be unbound from its buffer.
218 GLboolean
nouveauUnbindContext( __DRIcontextPrivate
*driContextPriv
)
223 void nouveauSwapBuffers(__DRIdrawablePrivate
*dPriv
)
227 void nouveauCopySubBuffer(__DRIdrawablePrivate
*dPriv
,
228 int x
, int y
, int w
, int h
)