2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 /* Minimal swrast-based dri loadable driver.
28 * -- Use malloced (rather than framebuffer) memory for backbuffer
29 * -- 32bpp is hardwared -- fix
32 * -- No mechanism for cliprects or resize notification --
33 * assumes this is a fullscreen device.
34 * -- No locking -- assumes this is the only driver accessing this
36 * -- Doesn't (yet) make use of any acceleration or other interfaces
37 * provided by fb. Would be entirely happy working against any
38 * fullscreen interface.
39 * -- HOWEVER: only a small number of pixelformats are supported, and
40 * the mechanism for choosing between them makes some assumptions
41 * that may not be valid everywhere.
47 #include "drirenderbuffer.h"
50 #include "extensions.h"
51 #include "framebuffer.h"
52 #include "renderbuffer.h"
53 #include "array_cache/acache.h"
54 #include "swrast/swrast.h"
55 #include "swrast_setup/swrast_setup.h"
57 #include "tnl/t_context.h"
58 #include "tnl/t_pipeline.h"
59 #include "drivers/common/driverfuncs.h"
61 void fbSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
);
64 GLcontext
*glCtx
; /* Mesa context */
67 __DRIcontextPrivate
*context
;
68 __DRIscreenPrivate
*screen
;
69 __DRIdrawablePrivate
*drawable
; /* drawable bound to this ctx */
72 } fbContext
, *fbContextPtr
;
74 #define FB_CONTEXT(ctx) ((fbContextPtr)(ctx->DriverCtx))
77 static const GLubyte
*
78 get_string(GLcontext
*ctx
, GLenum pname
)
83 return (const GLubyte
*) "Mesa dumb framebuffer";
91 update_state( GLcontext
*ctx
, GLuint new_state
)
93 /* not much to do here - pass it on */
94 _swrast_InvalidateState( ctx
, new_state
);
95 _swsetup_InvalidateState( ctx
, new_state
);
96 _ac_InvalidateState( ctx
, new_state
);
97 _tnl_InvalidateState( ctx
, new_state
);
102 * Called by ctx->Driver.GetBufferSize from in core Mesa to query the
103 * current framebuffer size.
106 get_buffer_size( GLframebuffer
*buffer
, GLuint
*width
, GLuint
*height
)
108 GET_CURRENT_CONTEXT(ctx
);
109 fbContextPtr fbmesa
= FB_CONTEXT(ctx
);
111 *width
= fbmesa
->dri
.drawable
->w
;
112 *height
= fbmesa
->dri
.drawable
->h
;
117 viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
119 _mesa_ResizeBuffersMESA();
124 init_core_functions( struct dd_function_table
*functions
)
126 functions
->GetString
= get_string
;
127 functions
->UpdateState
= update_state
;
128 functions
->ResizeBuffers
= _mesa_resize_framebuffer
;
129 functions
->GetBufferSize
= get_buffer_size
;
130 functions
->Viewport
= viewport
;
132 functions
->Clear
= _swrast_Clear
; /* could accelerate with blits */
137 * Generate code for span functions.
141 #define NAME(PREFIX) PREFIX##_B8G8R8
142 #define FORMAT GL_RGBA8
144 driRenderbuffer *drb = (driRenderbuffer *) rb;
145 #define INIT_PIXEL_PTR(P, X, Y) \
146 GLubyte *P = (GLubyte *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 3;
147 #define INC_PIXEL_PTR(P) P += 3
148 #define STORE_PIXEL(DST, X, Y, VALUE) \
149 DST[0] = VALUE[BCOMP]; \
150 DST[1] = VALUE[GCOMP]; \
151 DST[2] = VALUE[RCOMP]
152 #define FETCH_PIXEL(DST, SRC) \
153 DST[RCOMP] = SRC[2]; \
154 DST[GCOMP] = SRC[1]; \
155 DST[BCOMP] = SRC[0]; \
158 #include "swrast/s_spantemp.h"
162 #define NAME(PREFIX) PREFIX##_B8G8R8A8
163 #define FORMAT GL_RGBA8
165 driRenderbuffer *drb = (driRenderbuffer *) rb;
166 #define INIT_PIXEL_PTR(P, X, Y) \
167 GLubyte *P = (GLubyte *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 4;
168 #define INC_PIXEL_PTR(P) P += 4
169 #define STORE_PIXEL(DST, X, Y, VALUE) \
170 DST[0] = VALUE[BCOMP]; \
171 DST[1] = VALUE[GCOMP]; \
172 DST[2] = VALUE[RCOMP]; \
173 DST[3] = VALUE[ACOMP]
174 #define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
175 DST[0] = VALUE[BCOMP]; \
176 DST[1] = VALUE[GCOMP]; \
177 DST[2] = VALUE[RCOMP]; \
179 #define FETCH_PIXEL(DST, SRC) \
180 DST[RCOMP] = SRC[2]; \
181 DST[GCOMP] = SRC[1]; \
182 DST[BCOMP] = SRC[0]; \
185 #include "swrast/s_spantemp.h"
188 /* 16-bit BGR (XXX implement dithering someday) */
189 #define NAME(PREFIX) PREFIX##_B5G6R5
190 #define FORMAT GL_RGBA8
192 driRenderbuffer *drb = (driRenderbuffer *) rb;
193 #define INIT_PIXEL_PTR(P, X, Y) \
194 GLushort *P = (GLushort *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 2;
195 #define INC_PIXEL_PTR(P) P += 1
196 #define STORE_PIXEL(DST, X, Y, VALUE) \
197 DST[0] = ( (((VALUE[RCOMP]) & 0xf8) << 8) | (((VALUE[GCOMP]) & 0xfc) << 3) | ((VALUE[BCOMP]) >> 3) )
198 #define FETCH_PIXEL(DST, SRC) \
199 DST[RCOMP] = ( (((SRC[0]) >> 8) & 0xf8) | (((SRC[0]) >> 11) & 0x7) ); \
200 DST[GCOMP] = ( (((SRC[0]) >> 3) & 0xfc) | (((SRC[0]) >> 5) & 0x3) ); \
201 DST[BCOMP] = ( (((SRC[0]) << 3) & 0xf8) | (((SRC[0]) ) & 0x7) ); \
204 #include "swrast/s_spantemp.h"
207 /* 15-bit BGR (XXX implement dithering someday) */
208 #define NAME(PREFIX) PREFIX##_B5G5R5
209 #define FORMAT GL_RGBA8
211 driRenderbuffer *drb = (driRenderbuffer *) rb;
212 #define INIT_PIXEL_PTR(P, X, Y) \
213 GLushort *P = (GLushort *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 2;
214 #define INC_PIXEL_PTR(P) P += 1
215 #define STORE_PIXEL(DST, X, Y, VALUE) \
216 DST[0] = ( (((VALUE[RCOMP]) & 0xf8) << 7) | (((VALUE[GCOMP]) & 0xf8) << 2) | ((VALUE[BCOMP]) >> 3) )
217 #define FETCH_PIXEL(DST, SRC) \
218 DST[RCOMP] = ( (((SRC[0]) >> 7) & 0xf8) | (((SRC[0]) >> 10) & 0x7) ); \
219 DST[GCOMP] = ( (((SRC[0]) >> 2) & 0xf8) | (((SRC[0]) >> 5) & 0x7) ); \
220 DST[BCOMP] = ( (((SRC[0]) << 3) & 0xf8) | (((SRC[0]) ) & 0x7) ); \
223 #include "swrast/s_spantemp.h"
226 /* 8-bit color index */
227 #define NAME(PREFIX) PREFIX##_CI8
228 #define FORMAT GL_COLOR_INDEX8_EXT
230 driRenderbuffer *drb = (driRenderbuffer *) rb;
231 #define INIT_PIXEL_PTR(P, X, Y) \
232 GLubyte *P = (GLubyte *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X);
233 #define INC_PIXEL_PTR(P) P += 1
234 #define STORE_PIXEL(DST, X, Y, VALUE) \
236 #define FETCH_PIXEL(DST, SRC) \
239 #include "swrast/s_spantemp.h"
244 fbSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
246 ASSERT(drb
->Base
.InternalFormat
== GL_RGBA
);
247 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
248 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
249 drb
->Base
.GetRow
= get_row_B5G6R5
;
250 drb
->Base
.GetValues
= get_values_B5G6R5
;
251 drb
->Base
.PutRow
= put_row_B5G6R5
;
252 drb
->Base
.PutMonoRow
= put_mono_row_B5G6R5
;
253 drb
->Base
.PutRowRGB
= put_row_rgb_B5G6R5
;
254 drb
->Base
.PutValues
= put_values_B5G6R5
;
255 drb
->Base
.PutMonoValues
= put_mono_values_B5G6R5
;
257 else if (vis
->redBits
== 5 && vis
->greenBits
== 5 && vis
->blueBits
== 5) {
258 drb
->Base
.GetRow
= get_row_B5G5R5
;
259 drb
->Base
.GetValues
= get_values_B5G5R5
;
260 drb
->Base
.PutRow
= put_row_B5G5R5
;
261 drb
->Base
.PutMonoRow
= put_mono_row_B5G5R5
;
262 drb
->Base
.PutRowRGB
= put_row_rgb_B5G5R5
;
263 drb
->Base
.PutValues
= put_values_B5G5R5
;
264 drb
->Base
.PutMonoValues
= put_mono_values_B5G5R5
;
266 else if (vis
->redBits
== 8 && vis
->greenBits
== 8 && vis
->blueBits
== 8
267 && vis
->alphaBits
== 8) {
268 drb
->Base
.GetRow
= get_row_B8G8R8A8
;
269 drb
->Base
.GetValues
= get_values_B8G8R8A8
;
270 drb
->Base
.PutRow
= put_row_B8G8R8A8
;
271 drb
->Base
.PutMonoRow
= put_mono_row_B8G8R8A8
;
272 drb
->Base
.PutRowRGB
= put_row_rgb_B8G8R8A8
;
273 drb
->Base
.PutValues
= put_values_B8G8R8A8
;
274 drb
->Base
.PutMonoValues
= put_mono_values_B8G8R8A8
;
276 else if (vis
->redBits
== 8 && vis
->greenBits
== 8 && vis
->blueBits
== 8
277 && vis
->alphaBits
== 0) {
278 drb
->Base
.GetRow
= get_row_B8G8R8
;
279 drb
->Base
.GetValues
= get_values_B8G8R8
;
280 drb
->Base
.PutRow
= put_row_B8G8R8
;
281 drb
->Base
.PutMonoRow
= put_mono_row_B8G8R8
;
282 drb
->Base
.PutRowRGB
= put_row_rgb_B8G8R8
;
283 drb
->Base
.PutValues
= put_values_B8G8R8
;
284 drb
->Base
.PutMonoValues
= put_mono_values_B8G8R8
;
286 else if (vis
->indexBits
== 8) {
287 drb
->Base
.GetRow
= get_row_CI8
;
288 drb
->Base
.GetValues
= get_values_CI8
;
289 drb
->Base
.PutRow
= put_row_CI8
;
290 drb
->Base
.PutMonoRow
= put_mono_row_CI8
;
291 drb
->Base
.PutValues
= put_values_CI8
;
292 drb
->Base
.PutMonoValues
= put_mono_values_CI8
;
296 /* hardware z/stencil/etc someday */
302 /* Initialize the driver specific screen private data.
305 fbInitDriver( __DRIscreenPrivate
*sPriv
)
307 sPriv
->private = NULL
;
312 fbDestroyScreen( __DRIscreenPrivate
*sPriv
)
317 /* Create the device specific context.
320 fbCreateContext( const __GLcontextModes
*glVisual
,
321 __DRIcontextPrivate
*driContextPriv
,
322 void *sharedContextPrivate
)
325 GLcontext
*ctx
, *shareCtx
;
326 struct dd_function_table functions
;
329 assert(driContextPriv
);
331 /* Allocate the Fb context */
332 fbmesa
= (fbContextPtr
) _mesa_calloc( sizeof(*fbmesa
) );
336 /* Init default driver functions then plug in our FBdev-specific functions
338 _mesa_init_driver_functions(&functions
);
339 init_core_functions(&functions
);
341 /* Allocate the Mesa context */
342 if (sharedContextPrivate
)
343 shareCtx
= ((fbContextPtr
) sharedContextPrivate
)->glCtx
;
347 ctx
= fbmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
348 &functions
, (void *) fbmesa
);
349 if (!fbmesa
->glCtx
) {
353 driContextPriv
->driverPrivate
= fbmesa
;
355 /* Create module contexts */
356 _swrast_CreateContext( ctx
);
357 _ac_CreateContext( ctx
);
358 _tnl_CreateContext( ctx
);
359 _swsetup_CreateContext( ctx
);
360 _swsetup_Wakeup( ctx
);
363 /* use default TCL pipeline */
365 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
366 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
369 _mesa_enable_sw_extensions(ctx
);
376 fbDestroyContext( __DRIcontextPrivate
*driContextPriv
)
378 GET_CURRENT_CONTEXT(ctx
);
379 fbContextPtr fbmesa
= (fbContextPtr
) driContextPriv
->driverPrivate
;
380 fbContextPtr current
= ctx
? FB_CONTEXT(ctx
) : NULL
;
382 /* check if we're deleting the currently bound context */
383 if (fbmesa
== current
) {
384 _mesa_make_current(NULL
, NULL
, NULL
);
387 /* Free fb context resources */
389 _swsetup_DestroyContext( fbmesa
->glCtx
);
390 _tnl_DestroyContext( fbmesa
->glCtx
);
391 _ac_DestroyContext( fbmesa
->glCtx
);
392 _swrast_DestroyContext( fbmesa
->glCtx
);
394 /* free the Mesa context */
395 fbmesa
->glCtx
->DriverCtx
= NULL
;
396 _mesa_destroy_context( fbmesa
->glCtx
);
398 _mesa_free( fbmesa
);
403 /* Create and initialize the Mesa and driver specific pixmap buffer
407 fbCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
408 __DRIdrawablePrivate
*driDrawPriv
,
409 const __GLcontextModes
*mesaVis
,
412 struct gl_framebuffer
*mesa_framebuffer
;
415 return GL_FALSE
; /* not implemented */
418 const GLboolean swDepth
= mesaVis
->depthBits
> 0;
419 const GLboolean swAlpha
= mesaVis
->alphaBits
> 0;
420 const GLboolean swAccum
= mesaVis
->accumRedBits
> 0;
421 const GLboolean swStencil
= mesaVis
->stencilBits
> 0;
423 mesa_framebuffer
= _mesa_create_framebuffer(mesaVis
);
424 if (!mesa_framebuffer
)
427 /* XXX double-check these parameters (bpp vs cpp, etc) */
429 driRenderbuffer
*drb
= driNewRenderbuffer(GL_RGBA
,
431 driScrnPriv
->fbBPP
/ 8,
432 driScrnPriv
->fbOrigin
,
433 driScrnPriv
->fbStride
,
435 fbSetSpanFunctions(drb
, mesaVis
);
436 _mesa_add_renderbuffer(mesa_framebuffer
,
437 BUFFER_FRONT_LEFT
, &drb
->Base
);
439 if (mesaVis
->doubleBufferMode
) {
440 /* XXX what are the correct origin/stride values? */
441 GLvoid
*backBuf
= _mesa_malloc(driScrnPriv
->fbStride
442 * driScrnPriv
->fbHeight
);
443 driRenderbuffer
*drb
= driNewRenderbuffer(GL_RGBA
,
445 driScrnPriv
->fbBPP
/8,
446 driScrnPriv
->fbOrigin
,
447 driScrnPriv
->fbStride
,
449 fbSetSpanFunctions(drb
, mesaVis
);
450 _mesa_add_renderbuffer(mesa_framebuffer
,
451 BUFFER_BACK_LEFT
, &drb
->Base
);
454 _mesa_add_soft_renderbuffers(mesa_framebuffer
,
455 GL_FALSE
, /* color */
462 driDrawPriv
->driverPrivate
= mesa_framebuffer
;
470 fbDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
472 struct gl_framebuffer
*mesa_framebuffer
= (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
474 _mesa_free(mesa_framebuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
->Data
);
475 _mesa_destroy_framebuffer(mesa_framebuffer
);
476 driDrawPriv
->driverPrivate
= NULL
;
481 /* If the backbuffer is on a videocard, this is extraordinarily slow!
484 fbSwapBuffers( __DRIdrawablePrivate
*dPriv
)
486 struct gl_framebuffer
*mesa_framebuffer
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
487 struct gl_renderbuffer
* front_renderbuffer
= mesa_framebuffer
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
488 void *frontBuffer
= front_renderbuffer
->Data
;
489 int currentPitch
= ((driRenderbuffer
*)front_renderbuffer
)->pitch
;
490 void *backBuffer
= mesa_framebuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
->Data
;
492 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
493 fbContextPtr fbmesa
= (fbContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
494 GLcontext
*ctx
= fbmesa
->glCtx
;
496 if (ctx
->Visual
.doubleBufferMode
) {
499 char *tmp
= _mesa_malloc(currentPitch
);
501 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
506 for (i
= 0; i
< dPriv
->h
; i
++) {
507 _mesa_memcpy(tmp
, (char *) backBuffer
+ offset
,
509 _mesa_memcpy((char *) frontBuffer
+ offset
, tmp
,
511 offset
+= currentPitch
;
518 /* XXX this shouldn't be an error but we can't handle it for now */
519 _mesa_problem(NULL
, "fbSwapBuffers: drawable has no context!\n");
524 /* Force the context `c' to be the current context and associate with it
528 fbMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
529 __DRIdrawablePrivate
*driDrawPriv
,
530 __DRIdrawablePrivate
*driReadPriv
)
532 if ( driContextPriv
) {
533 fbContextPtr newFbCtx
=
534 (fbContextPtr
) driContextPriv
->driverPrivate
;
536 newFbCtx
->dri
.drawable
= driDrawPriv
;
538 _mesa_make_current( newFbCtx
->glCtx
,
539 driDrawPriv
->driverPrivate
,
540 driReadPriv
->driverPrivate
);
542 _mesa_make_current( NULL
, NULL
, NULL
);
549 /* Force the context `c' to be unbound from its buffer.
552 fbUnbindContext( __DRIcontextPrivate
*driContextPriv
)
557 static struct __DriverAPIRec fbAPI
= {
558 .InitDriver
= fbInitDriver
,
559 .DestroyScreen
= fbDestroyScreen
,
560 .CreateContext
= fbCreateContext
,
561 .DestroyContext
= fbDestroyContext
,
562 .CreateBuffer
= fbCreateBuffer
,
563 .DestroyBuffer
= fbDestroyBuffer
,
564 .SwapBuffers
= fbSwapBuffers
,
565 .MakeCurrent
= fbMakeCurrent
,
566 .UnbindContext
= fbUnbindContext
,
572 __driValidateMode(const DRIDriverContext
*ctx
)
578 __driInitFBDev( struct DRIDriverContextRec
*ctx
)
580 /* Note that drmOpen will try to load the kernel module, if needed. */
581 /* we need a fbdev drm driver - it will only track maps */
582 ctx
->drmFD
= drmOpen("radeon", NULL
);
583 if (ctx
->drmFD
< 0) {
584 fprintf(stderr
, "[drm] drmOpen failed\n");
588 ctx
->shared
.SAREASize
= SAREA_MAX
;
590 if (drmAddMap( ctx
->drmFD
,
592 ctx
->shared
.SAREASize
,
595 &ctx
->shared
.hSAREA
) < 0)
597 fprintf(stderr
, "[drm] drmAddMap failed\n");
600 fprintf(stderr
, "[drm] added %d byte SAREA at 0x%08lx\n",
601 ctx
->shared
.SAREASize
, ctx
->shared
.hSAREA
);
603 if (drmMap( ctx
->drmFD
,
605 ctx
->shared
.SAREASize
,
606 (drmAddressPtr
)(&ctx
->pSAREA
)) < 0)
608 fprintf(stderr
, "[drm] drmMap failed\n");
611 memset(ctx
->pSAREA
, 0, ctx
->shared
.SAREASize
);
612 fprintf(stderr
, "[drm] mapped SAREA 0x%08lx to %p, size %d\n",
613 ctx
->shared
.hSAREA
, ctx
->pSAREA
, ctx
->shared
.SAREASize
);
615 /* Need to AddMap the framebuffer and mmio regions here:
617 if (drmAddMap( ctx
->drmFD
,
618 (drm_handle_t
)ctx
->FBStart
,
626 &ctx
->shared
.hFrameBuffer
) < 0)
628 fprintf(stderr
, "[drm] drmAddMap framebuffer failed\n");
632 fprintf(stderr
, "[drm] framebuffer handle = 0x%08lx\n",
633 ctx
->shared
.hFrameBuffer
);
639 __driHaltFBDev( struct DRIDriverContextRec
*ctx
)
643 struct DRIDriverRec __driDriver
= {
650 static __GLcontextModes
*
651 fbFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
652 unsigned stencil_bits
, GLboolean have_back_buffer
)
654 __GLcontextModes
* modes
;
655 __GLcontextModes
* m
;
657 unsigned depth_buffer_factor
;
658 unsigned back_buffer_factor
;
662 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
663 * enough to add support. Basically, if a context is created with an
664 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
665 * will never be used.
667 static const GLenum back_buffer_modes
[] = {
668 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
671 u_int8_t depth_bits_array
[2];
672 u_int8_t stencil_bits_array
[2];
675 depth_bits_array
[0] = depth_bits
;
676 depth_bits_array
[1] = depth_bits
;
678 /* Just like with the accumulation buffer, always provide some modes
679 * with a stencil buffer. It will be a sw fallback, but some apps won't
682 stencil_bits_array
[0] = 0;
683 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
685 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
686 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
688 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
690 if ( pixel_bits
== 16 ) {
692 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
696 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
699 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
701 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
702 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
703 back_buffer_modes
, back_buffer_factor
,
705 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
706 __func__
, __LINE__
);
710 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
711 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
712 back_buffer_modes
, back_buffer_factor
,
713 GLX_DIRECT_COLOR
) ) {
714 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
715 __func__
, __LINE__
);
719 /* Mark the visual as slow if there are "fake" stencil bits.
721 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
722 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
723 m
->visualRating
= GLX_SLOW_CONFIG
;
732 * This is the bootstrap function for the driver. libGL supplies all of the
733 * requisite information about the system, and the driver initializes itself.
734 * This routine also fills in the linked list pointed to by \c driver_modes
735 * with the \c __GLcontextModes that the driver can support for windows or
738 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
742 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
743 const __GLcontextModes
* modes
,
744 const __DRIversion
* ddx_version
,
745 const __DRIversion
* dri_version
,
746 const __DRIversion
* drm_version
,
747 const __DRIframebuffer
* frame_buffer
,
748 drmAddress pSAREA
, int fd
,
749 int internal_api_version
,
750 __GLcontextModes
** driver_modes
)
752 __DRIscreenPrivate
*psp
;
753 static const __DRIversion ddx_expected
= { 4, 0, 0 };
754 static const __DRIversion dri_expected
= { 4, 0, 0 };
755 static const __DRIversion drm_expected
= { 1, 5, 0 };
758 if ( ! driCheckDriDdxDrmVersions2( "fb",
759 dri_version
, & dri_expected
,
760 ddx_version
, & ddx_expected
,
761 drm_version
, & drm_expected
) ) {
765 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
766 ddx_version
, dri_version
, drm_version
,
767 frame_buffer
, pSAREA
, fd
,
768 internal_api_version
, &fbAPI
);
770 *driver_modes
= fbFillInModes( psp
->fbBPP
,
771 (psp
->fbBPP
== 16) ? 16 : 24,
772 (psp
->fbBPP
== 16) ? 0 : 8,