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 **************************************************************************/
30 #include "framebuffer.h"
31 #include "renderbuffer.h"
33 #include "nouveau_context.h"
34 #include "nouveau_screen.h"
35 #include "nouveau_object.h"
36 #include "nouveau_span.h"
41 #include "drirenderbuffer.h"
43 #include "GL/internal/dri_interface.h"
47 PUBLIC
const char __driConfigOptions
[] =
49 DRI_CONF_SECTION_DEBUG
50 DRI_CONF_NO_RAST(false)
53 static const GLuint __driNConfigOptions
= 1;
55 extern const struct dri_extension common_extensions
[];
57 static nouveauScreenPtr
nouveauCreateScreen(__DRIscreenPrivate
*sPriv
)
59 nouveauScreenPtr screen
;
60 NOUVEAUDRIPtr dri_priv
=(NOUVEAUDRIPtr
)sPriv
->pDevPriv
;
63 screen
= (nouveauScreenPtr
) CALLOC( sizeof(*screen
) );
65 __driUtilMessage("%s: Could not allocate memory for screen structure",__FUNCTION__
);
69 /* parse information in __driConfigOptions */
70 driParseOptionInfo (&screen
->optionCache
,__driConfigOptions
, __driNConfigOptions
);
72 screen
->fbFormat
= dri_priv
->bpp
/ 8;
73 screen
->frontOffset
= dri_priv
->front_offset
;
74 screen
->frontPitch
= dri_priv
->front_pitch
;
75 screen
->backOffset
= dri_priv
->back_offset
;
76 screen
->backPitch
= dri_priv
->back_pitch
;
77 screen
->depthOffset
= dri_priv
->depth_offset
;
78 screen
->depthPitch
= dri_priv
->depth_pitch
;
80 screen
->card
=nouveau_card_lookup(dri_priv
->device_id
);
81 screen
->driScreen
= sPriv
;
86 nouveauDestroyScreen(__DRIscreenPrivate
*sPriv
)
88 nouveauScreenPtr screen
= (nouveauScreenPtr
)sPriv
->private;
92 /* free all option information */
93 driDestroyOptionInfo (&screen
->optionCache
);
96 sPriv
->private = NULL
;
99 static GLboolean
nouveauInitDriver(__DRIscreenPrivate
*sPriv
)
101 sPriv
->private = (void *) nouveauCreateScreen( sPriv
);
102 if ( !sPriv
->private ) {
103 nouveauDestroyScreen( sPriv
);
111 * Create the Mesa framebuffer and renderbuffers for a given window/drawable.
113 * \todo This function (and its interface) will need to be updated to support
117 nouveauCreateBuffer(__DRIscreenPrivate
*driScrnPriv
,
118 __DRIdrawablePrivate
*driDrawPriv
,
119 const __GLcontextModes
*mesaVis
,
122 nouveauScreenPtr screen
= (nouveauScreenPtr
) driScrnPriv
->private;
125 return GL_FALSE
; /* not implemented */
128 const GLboolean swDepth
= GL_FALSE
;
129 const GLboolean swAlpha
= GL_FALSE
;
130 const GLboolean swAccum
= mesaVis
->accumRedBits
> 0;
131 const GLboolean swStencil
= mesaVis
->stencilBits
> 0 && mesaVis
->depthBits
!= 24;
132 struct gl_framebuffer
*fb
= _mesa_create_framebuffer(mesaVis
);
134 /* front color renderbuffer */
136 driRenderbuffer
*frontRb
137 = driNewRenderbuffer(GL_RGBA
,
138 driScrnPriv
->pFB
+ screen
->frontOffset
,
140 screen
->frontOffset
, screen
->frontPitch
,
142 nouveauSpanSetFunctions(frontRb
, mesaVis
);
143 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &frontRb
->Base
);
146 /* back color renderbuffer */
147 if (mesaVis
->doubleBufferMode
) {
148 driRenderbuffer
*backRb
149 = driNewRenderbuffer(GL_RGBA
,
150 driScrnPriv
->pFB
+ screen
->backOffset
,
152 screen
->backOffset
, screen
->backPitch
,
154 nouveauSpanSetFunctions(backRb
, mesaVis
);
155 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &backRb
->Base
);
158 /* depth renderbuffer */
159 if (mesaVis
->depthBits
== 16) {
160 driRenderbuffer
*depthRb
161 = driNewRenderbuffer(GL_DEPTH_COMPONENT16
,
162 driScrnPriv
->pFB
+ screen
->depthOffset
,
164 screen
->depthOffset
, screen
->depthPitch
,
166 nouveauSpanSetFunctions(depthRb
, mesaVis
);
167 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
169 else if (mesaVis
->depthBits
== 24) {
170 driRenderbuffer
*depthRb
171 = driNewRenderbuffer(GL_DEPTH_COMPONENT24
,
172 driScrnPriv
->pFB
+ screen
->depthOffset
,
174 screen
->depthOffset
, screen
->depthPitch
,
176 nouveauSpanSetFunctions(depthRb
, mesaVis
);
177 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &depthRb
->Base
);
180 /* stencil renderbuffer */
181 if (mesaVis
->stencilBits
> 0 && !swStencil
) {
182 driRenderbuffer
*stencilRb
183 = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT
,
184 driScrnPriv
->pFB
+ screen
->depthOffset
,
186 screen
->depthOffset
, screen
->depthPitch
,
188 nouveauSpanSetFunctions(stencilRb
, mesaVis
);
189 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &stencilRb
->Base
);
192 _mesa_add_soft_renderbuffers(fb
,
193 GL_FALSE
, /* color */
199 driDrawPriv
->driverPrivate
= (void *) fb
;
201 return (driDrawPriv
->driverPrivate
!= NULL
);
207 nouveauDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
209 _mesa_destroy_framebuffer((GLframebuffer
*) (driDrawPriv
->driverPrivate
));
213 nouveauGetSwapInfo(__DRIdrawablePrivate
*dpriv
, __DRIswapInfo
*sInfo
)
218 static const struct __DriverAPIRec nouveauAPI
= {
219 .InitDriver
= nouveauInitDriver
,
220 .DestroyScreen
= nouveauDestroyScreen
,
221 .CreateContext
= nouveauCreateContext
,
222 .DestroyContext
= nouveauDestroyContext
,
223 .CreateBuffer
= nouveauCreateBuffer
,
224 .DestroyBuffer
= nouveauDestroyBuffer
,
225 .SwapBuffers
= nouveauSwapBuffers
,
226 .MakeCurrent
= nouveauMakeCurrent
,
227 .UnbindContext
= nouveauUnbindContext
,
228 .GetSwapInfo
= nouveauGetSwapInfo
,
229 .GetMSC
= driGetMSC32
,
230 .WaitForMSC
= driWaitForMSC32
,
232 .SwapBuffersMSC
= NULL
,
233 .CopySubBuffer
= nouveauCopySubBuffer
237 static __GLcontextModes
*
238 nouveauFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
239 unsigned stencil_bits
, GLboolean have_back_buffer
)
241 __GLcontextModes
* modes
;
242 __GLcontextModes
* m
;
244 unsigned depth_buffer_factor
;
245 unsigned back_buffer_factor
;
249 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
250 * support pageflipping at all.
252 static const GLenum back_buffer_modes
[] = {
253 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
256 u_int8_t depth_bits_array
[3];
257 u_int8_t stencil_bits_array
[3];
259 depth_bits_array
[0] = 0;
260 depth_bits_array
[1] = depth_bits
;
261 depth_bits_array
[2] = depth_bits
;
263 /* Just like with the accumulation buffer, always provide some modes
264 * with a stencil buffer. It will be a sw fallback, but some apps won't
267 stencil_bits_array
[0] = 0;
268 stencil_bits_array
[1] = 0;
269 stencil_bits_array
[2] = (stencil_bits
== 0) ? 8 : stencil_bits
;
271 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 3 : 1;
272 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
274 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
276 if ( pixel_bits
== 16 ) {
278 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
281 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
284 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
286 if (!driFillInModes(&m
, fb_format
, fb_type
,
287 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
288 back_buffer_modes
, back_buffer_factor
,
290 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
291 __func__
, __LINE__
);
294 if (!driFillInModes(&m
, fb_format
, fb_type
,
295 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
296 back_buffer_modes
, back_buffer_factor
,
298 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
299 __func__
, __LINE__
);
303 /* Mark the visual as slow if there are "fake" stencil bits.
305 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
306 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
307 m
->visualRating
= GLX_SLOW_CONFIG
;
316 * This is the bootstrap function for the driver. libGL supplies all of the
317 * requisite information about the system, and the driver initializes itself.
318 * This routine also fills in the linked list pointed to by \c driver_modes
319 * with the \c __GLcontextModes that the driver can support for windows or
322 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
326 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
327 const __GLcontextModes
* modes
,
328 const __DRIversion
* ddx_version
,
329 const __DRIversion
* dri_version
,
330 const __DRIversion
* drm_version
,
331 const __DRIframebuffer
* frame_buffer
,
332 drmAddress pSAREA
, int fd
,
333 int internal_api_version
,
334 const __DRIinterfaceMethods
* interface
,
335 __GLcontextModes
** driver_modes
)
338 __DRIscreenPrivate
*psp
;
339 static const __DRIversion ddx_expected
= { 1, 2, 0 };
340 static const __DRIversion dri_expected
= { 4, 0, 0 };
341 static const __DRIversion drm_expected
= { 1, 0, 0 };
343 dri_interface
= interface
;
345 if (!driCheckDriDdxDrmVersions2("nouveau",
346 dri_version
, & dri_expected
,
347 ddx_version
, & ddx_expected
,
348 drm_version
, & drm_expected
)) {
352 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
353 ddx_version
, dri_version
, drm_version
,
354 frame_buffer
, pSAREA
, fd
,
355 internal_api_version
, &nouveauAPI
);
357 NOUVEAUDRIPtr dri_priv
= (NOUVEAUDRIPtr
)psp
->pDevPriv
;
359 *driver_modes
= nouveauFillInModes(dri_priv
->bpp
,
360 (dri_priv
->bpp
== 16) ? 16 : 24,
361 (dri_priv
->bpp
== 16) ? 0 : 8,
362 (dri_priv
->back_offset
!= dri_priv
->depth_offset
));
364 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
365 * enable the extensions. It just makes sure that all the dispatch offsets for all
366 * the extensions that *might* be enables are known. This is needed because the
367 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
368 * enable the extensions until we have a context pointer.
370 * Hello chicken. Hello egg. How are you two today?
372 driInitExtensions( NULL
, common_extensions
, GL_FALSE
);