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
[];
56 extern const struct dri_extension nv10_extensions
[];
57 extern const struct dri_extension nv20_extensions
[];
58 extern const struct dri_extension nv30_extensions
[];
59 extern const struct dri_extension nv40_extensions
[];
60 extern const struct dri_extension nv50_extensions
[];
62 static nouveauScreenPtr
nouveauCreateScreen(__DRIscreenPrivate
*sPriv
)
64 nouveauScreenPtr screen
;
65 NOUVEAUDRIPtr dri_priv
=(NOUVEAUDRIPtr
)sPriv
->pDevPriv
;
68 screen
= (nouveauScreenPtr
) CALLOC( sizeof(*screen
) );
70 __driUtilMessage("%s: Could not allocate memory for screen structure",__FUNCTION__
);
74 screen
->card
=nouveau_card_lookup(dri_priv
->device_id
);
76 __driUtilMessage("%s: Unknown card type 0x%04x:0x%04x\n",
77 __func__
, dri_priv
->device_id
>> 16, dri_priv
->device_id
& 0xFFFF);
82 /* parse information in __driConfigOptions */
83 driParseOptionInfo (&screen
->optionCache
,__driConfigOptions
, __driNConfigOptions
);
85 screen
->fbFormat
= dri_priv
->bpp
/ 8;
86 screen
->frontOffset
= dri_priv
->front_offset
;
87 screen
->frontPitch
= dri_priv
->front_pitch
;
88 screen
->backOffset
= dri_priv
->back_offset
;
89 screen
->backPitch
= dri_priv
->back_pitch
;
90 screen
->depthOffset
= dri_priv
->depth_offset
;
91 screen
->depthPitch
= dri_priv
->depth_pitch
;
93 screen
->driScreen
= sPriv
;
98 nouveauDestroyScreen(__DRIscreenPrivate
*sPriv
)
100 nouveauScreenPtr screen
= (nouveauScreenPtr
)sPriv
->private;
104 /* free all option information */
105 driDestroyOptionInfo (&screen
->optionCache
);
108 sPriv
->private = NULL
;
111 static GLboolean
nouveauInitDriver(__DRIscreenPrivate
*sPriv
)
113 sPriv
->private = (void *) nouveauCreateScreen( sPriv
);
114 if ( !sPriv
->private ) {
115 nouveauDestroyScreen( sPriv
);
123 * Create the Mesa framebuffer and renderbuffers for a given window/drawable.
125 * \todo This function (and its interface) will need to be updated to support
129 nouveauCreateBuffer(__DRIscreenPrivate
*driScrnPriv
,
130 __DRIdrawablePrivate
*driDrawPriv
,
131 const __GLcontextModes
*mesaVis
,
134 nouveauScreenPtr screen
= (nouveauScreenPtr
) driScrnPriv
->private;
135 nouveau_renderbuffer_t
*nrb
;
136 struct gl_framebuffer
*fb
;
137 const GLboolean swAccum
= mesaVis
->accumRedBits
> 0;
138 const GLboolean swStencil
= (mesaVis
->stencilBits
> 0 &&
139 mesaVis
->depthBits
!= 24);
140 GLenum color_format
= screen
->fbFormat
== 4 ? GL_RGBA8
: GL_RGB5
;
143 return GL_FALSE
; /* not implemented */
145 fb
= _mesa_create_framebuffer(mesaVis
);
150 nrb
= nouveau_renderbuffer_new(color_format
);
151 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &nrb
->mesa
);
153 if (mesaVis
->doubleBufferMode
) {
154 nrb
= nouveau_renderbuffer_new(color_format
);
155 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &nrb
->mesa
);
158 if (mesaVis
->depthBits
== 24 && mesaVis
->stencilBits
== 8) {
159 nrb
= nouveau_renderbuffer_new(GL_DEPTH24_STENCIL8_EXT
);
160 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &nrb
->mesa
);
161 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &nrb
->mesa
);
163 if (mesaVis
->depthBits
== 24) {
164 nrb
= nouveau_renderbuffer_new(GL_DEPTH_COMPONENT24
);
165 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &nrb
->mesa
);
167 if (mesaVis
->depthBits
== 16) {
168 nrb
= nouveau_renderbuffer_new(GL_DEPTH_COMPONENT16
);
169 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &nrb
->mesa
);
172 _mesa_add_soft_renderbuffers(fb
,
173 GL_FALSE
, /* color */
174 GL_FALSE
, /* depth */
177 GL_FALSE
, /* alpha */
180 driDrawPriv
->driverPrivate
= (void *) fb
;
181 return (driDrawPriv
->driverPrivate
!= NULL
);
186 nouveauDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
188 _mesa_unreference_framebuffer((GLframebuffer
**)(&(driDrawPriv
->driverPrivate
)));
192 nouveauGetSwapInfo(__DRIdrawablePrivate
*dpriv
, __DRIswapInfo
*sInfo
)
197 static const struct __DriverAPIRec nouveauAPI
= {
198 .InitDriver
= nouveauInitDriver
,
199 .DestroyScreen
= nouveauDestroyScreen
,
200 .CreateContext
= nouveauCreateContext
,
201 .DestroyContext
= nouveauDestroyContext
,
202 .CreateBuffer
= nouveauCreateBuffer
,
203 .DestroyBuffer
= nouveauDestroyBuffer
,
204 .SwapBuffers
= nouveauSwapBuffers
,
205 .MakeCurrent
= nouveauMakeCurrent
,
206 .UnbindContext
= nouveauUnbindContext
,
207 .GetSwapInfo
= nouveauGetSwapInfo
,
208 .GetMSC
= driGetMSC32
,
209 .WaitForMSC
= driWaitForMSC32
,
211 .SwapBuffersMSC
= NULL
,
212 .CopySubBuffer
= nouveauCopySubBuffer
216 static __GLcontextModes
*
217 nouveauFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
218 unsigned stencil_bits
, GLboolean have_back_buffer
)
220 __GLcontextModes
* modes
;
221 __GLcontextModes
* m
;
223 unsigned depth_buffer_factor
;
224 unsigned back_buffer_factor
;
227 static const struct {
230 } fb_format_array
[] = {
231 { GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
},
232 { GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
},
233 { GL_BGR
, GL_UNSIGNED_INT_8_8_8_8_REV
},
236 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
237 * support pageflipping at all.
239 static const GLenum back_buffer_modes
[] = {
240 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
, GLX_SWAP_COPY_OML
243 u_int8_t depth_bits_array
[4] = { 0, 16, 24, 24 };
244 u_int8_t stencil_bits_array
[4] = { 0, 0, 0, 8 };
246 depth_buffer_factor
= 4;
247 back_buffer_factor
= (have_back_buffer
) ? 3 : 1;
249 num_modes
= ((pixel_bits
==16) ? 1 : 2) *
250 depth_buffer_factor
* back_buffer_factor
* 4;
251 modes
= (*dri_interface
->createContextModes
)(num_modes
,
252 sizeof(__GLcontextModes
));
255 for (i
=((pixel_bits
==16)?0:1);i
<((pixel_bits
==16)?1:3);i
++) {
256 if (!driFillInModes(&m
, fb_format_array
[i
].format
,
257 fb_format_array
[i
].type
,
264 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
265 __func__
, __LINE__
);
269 if (!driFillInModes(&m
, fb_format_array
[i
].format
,
270 fb_format_array
[i
].type
,
277 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
278 __func__
, __LINE__
);
288 * This is the bootstrap function for the driver. libGL supplies all of the
289 * requisite information about the system, and the driver initializes itself.
290 * This routine also fills in the linked list pointed to by \c driver_modes
291 * with the \c __GLcontextModes that the driver can support for windows or
294 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
298 void * __driCreateNewScreen_20050727( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
299 const __GLcontextModes
* modes
,
300 const __DRIversion
* ddx_version
,
301 const __DRIversion
* dri_version
,
302 const __DRIversion
* drm_version
,
303 const __DRIframebuffer
* frame_buffer
,
304 drmAddress pSAREA
, int fd
,
305 int internal_api_version
,
306 const __DRIinterfaceMethods
* interface
,
307 __GLcontextModes
** driver_modes
)
310 __DRIscreenPrivate
*psp
;
311 static const __DRIversion ddx_expected
= { 1, 2, 0 };
312 static const __DRIversion dri_expected
= { 4, 0, 0 };
313 static const __DRIversion drm_expected
= { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL
};
314 #if NOUVEAU_DRM_HEADER_PATCHLEVEL != 10
315 #error nouveau_drm.h version doesn't match expected version
317 dri_interface = interface;
319 if (!driCheckDriDdxDrmVersions2("nouveau",
320 dri_version, & dri_expected,
321 ddx_version, & ddx_expected,
322 drm_version, & drm_expected)) {
326 // temporary lock step versioning
327 if (drm_expected.patch!=drm_version->patch) {
328 __driUtilMessage("%s: wrong DRM version, expected %d, got %d\n",
330 drm_expected.patch, drm_version->patch);
334 psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
335 ddx_version, dri_version, drm_version,
336 frame_buffer, pSAREA, fd,
337 internal_api_version, &nouveauAPI);
339 NOUVEAUDRIPtr dri_priv = (NOUVEAUDRIPtr)psp->pDevPriv;
341 *driver_modes = nouveauFillInModes(dri_priv->bpp,
342 (dri_priv->bpp == 16) ? 16 : 24,
343 (dri_priv->bpp == 16) ? 0 : 8,
347 /* Calling driInitExtensions here, with a NULL context pointer, does not actually
348 * enable the extensions. It just makes sure that all the dispatch offsets for all
349 * the extensions that *might* be enables are known. This is needed because the
350 * dispatch offsets need to be known when _mesa_context_create is called, but we can't
351 * enable the extensions until we have a context pointer
.
353 * Hello chicken
. Hello egg
. How are you two today
?
355 driInitExtensions( NULL
, common_extensions
, GL_FALSE
);
356 driInitExtensions( NULL
, nv10_extensions
, GL_FALSE
);
357 driInitExtensions( NULL
, nv10_extensions
, GL_FALSE
);
358 driInitExtensions( NULL
, nv30_extensions
, GL_FALSE
);
359 driInitExtensions( NULL
, nv40_extensions
, GL_FALSE
);
360 driInitExtensions( NULL
, nv50_extensions
, GL_FALSE
);