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 updateFramebufferSize(GLcontext
*ctx
)
119 fbContextPtr fbmesa
= FB_CONTEXT(ctx
);
120 struct gl_framebuffer
*fb
= ctx
->WinSysDrawBuffer
;
121 if (fbmesa
->dri
.drawable
->w
!= fb
->Width
||
122 fbmesa
->dri
.drawable
->h
!= fb
->Height
) {
123 driUpdateFramebufferSize(ctx
, fbmesa
->dri
.drawable
);
128 viewport(GLcontext
*ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
130 /* XXX this should be called after we acquire the DRI lock, not here */
131 updateFramebufferSize(ctx
);
136 init_core_functions( struct dd_function_table
*functions
)
138 functions
->GetString
= get_string
;
139 functions
->UpdateState
= update_state
;
140 functions
->ResizeBuffers
= _mesa_resize_framebuffer
;
141 functions
->GetBufferSize
= get_buffer_size
;
142 functions
->Viewport
= viewport
;
144 functions
->Clear
= _swrast_Clear
; /* could accelerate with blits */
149 * Generate code for span functions.
153 #define NAME(PREFIX) PREFIX##_B8G8R8
154 #define FORMAT GL_RGBA8
156 driRenderbuffer *drb = (driRenderbuffer *) rb;
157 #define INIT_PIXEL_PTR(P, X, Y) \
158 GLubyte *P = (GLubyte *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 3;
159 #define INC_PIXEL_PTR(P) P += 3
160 #define STORE_PIXEL(DST, X, Y, VALUE) \
161 DST[0] = VALUE[BCOMP]; \
162 DST[1] = VALUE[GCOMP]; \
163 DST[2] = VALUE[RCOMP]
164 #define FETCH_PIXEL(DST, SRC) \
165 DST[RCOMP] = SRC[2]; \
166 DST[GCOMP] = SRC[1]; \
167 DST[BCOMP] = SRC[0]; \
170 #include "swrast/s_spantemp.h"
174 #define NAME(PREFIX) PREFIX##_B8G8R8A8
175 #define FORMAT GL_RGBA8
177 driRenderbuffer *drb = (driRenderbuffer *) rb;
178 #define INIT_PIXEL_PTR(P, X, Y) \
179 GLubyte *P = (GLubyte *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 4;
180 #define INC_PIXEL_PTR(P) P += 4
181 #define STORE_PIXEL(DST, X, Y, VALUE) \
182 DST[0] = VALUE[BCOMP]; \
183 DST[1] = VALUE[GCOMP]; \
184 DST[2] = VALUE[RCOMP]; \
185 DST[3] = VALUE[ACOMP]
186 #define STORE_PIXEL_RGB(DST, X, Y, VALUE) \
187 DST[0] = VALUE[BCOMP]; \
188 DST[1] = VALUE[GCOMP]; \
189 DST[2] = VALUE[RCOMP]; \
191 #define FETCH_PIXEL(DST, SRC) \
192 DST[RCOMP] = SRC[2]; \
193 DST[GCOMP] = SRC[1]; \
194 DST[BCOMP] = SRC[0]; \
197 #include "swrast/s_spantemp.h"
200 /* 16-bit BGR (XXX implement dithering someday) */
201 #define NAME(PREFIX) PREFIX##_B5G6R5
202 #define FORMAT GL_RGBA8
204 driRenderbuffer *drb = (driRenderbuffer *) rb;
205 #define INIT_PIXEL_PTR(P, X, Y) \
206 GLushort *P = (GLushort *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 2;
207 #define INC_PIXEL_PTR(P) P += 1
208 #define STORE_PIXEL(DST, X, Y, VALUE) \
209 DST[0] = ( (((VALUE[RCOMP]) & 0xf8) << 8) | (((VALUE[GCOMP]) & 0xfc) << 3) | ((VALUE[BCOMP]) >> 3) )
210 #define FETCH_PIXEL(DST, SRC) \
211 DST[RCOMP] = ( (((SRC[0]) >> 8) & 0xf8) | (((SRC[0]) >> 11) & 0x7) ); \
212 DST[GCOMP] = ( (((SRC[0]) >> 3) & 0xfc) | (((SRC[0]) >> 5) & 0x3) ); \
213 DST[BCOMP] = ( (((SRC[0]) << 3) & 0xf8) | (((SRC[0]) ) & 0x7) ); \
216 #include "swrast/s_spantemp.h"
219 /* 15-bit BGR (XXX implement dithering someday) */
220 #define NAME(PREFIX) PREFIX##_B5G5R5
221 #define FORMAT GL_RGBA8
223 driRenderbuffer *drb = (driRenderbuffer *) rb;
224 #define INIT_PIXEL_PTR(P, X, Y) \
225 GLushort *P = (GLushort *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X) * 2;
226 #define INC_PIXEL_PTR(P) P += 1
227 #define STORE_PIXEL(DST, X, Y, VALUE) \
228 DST[0] = ( (((VALUE[RCOMP]) & 0xf8) << 7) | (((VALUE[GCOMP]) & 0xf8) << 2) | ((VALUE[BCOMP]) >> 3) )
229 #define FETCH_PIXEL(DST, SRC) \
230 DST[RCOMP] = ( (((SRC[0]) >> 7) & 0xf8) | (((SRC[0]) >> 10) & 0x7) ); \
231 DST[GCOMP] = ( (((SRC[0]) >> 2) & 0xf8) | (((SRC[0]) >> 5) & 0x7) ); \
232 DST[BCOMP] = ( (((SRC[0]) << 3) & 0xf8) | (((SRC[0]) ) & 0x7) ); \
235 #include "swrast/s_spantemp.h"
238 /* 8-bit color index */
239 #define NAME(PREFIX) PREFIX##_CI8
240 #define FORMAT GL_COLOR_INDEX8_EXT
242 driRenderbuffer *drb = (driRenderbuffer *) rb;
243 #define INIT_PIXEL_PTR(P, X, Y) \
244 GLubyte *P = (GLubyte *)drb->Base.Data + (drb->Base.Height - (Y)) * drb->pitch + (X);
245 #define INC_PIXEL_PTR(P) P += 1
246 #define STORE_PIXEL(DST, X, Y, VALUE) \
248 #define FETCH_PIXEL(DST, SRC) \
251 #include "swrast/s_spantemp.h"
256 fbSetSpanFunctions(driRenderbuffer
*drb
, const GLvisual
*vis
)
258 ASSERT(drb
->Base
.InternalFormat
== GL_RGBA
);
259 if (drb
->Base
.InternalFormat
== GL_RGBA
) {
260 if (vis
->redBits
== 5 && vis
->greenBits
== 6 && vis
->blueBits
== 5) {
261 drb
->Base
.GetRow
= get_row_B5G6R5
;
262 drb
->Base
.GetValues
= get_values_B5G6R5
;
263 drb
->Base
.PutRow
= put_row_B5G6R5
;
264 drb
->Base
.PutMonoRow
= put_mono_row_B5G6R5
;
265 drb
->Base
.PutRowRGB
= put_row_rgb_B5G6R5
;
266 drb
->Base
.PutValues
= put_values_B5G6R5
;
267 drb
->Base
.PutMonoValues
= put_mono_values_B5G6R5
;
269 else if (vis
->redBits
== 5 && vis
->greenBits
== 5 && vis
->blueBits
== 5) {
270 drb
->Base
.GetRow
= get_row_B5G5R5
;
271 drb
->Base
.GetValues
= get_values_B5G5R5
;
272 drb
->Base
.PutRow
= put_row_B5G5R5
;
273 drb
->Base
.PutMonoRow
= put_mono_row_B5G5R5
;
274 drb
->Base
.PutRowRGB
= put_row_rgb_B5G5R5
;
275 drb
->Base
.PutValues
= put_values_B5G5R5
;
276 drb
->Base
.PutMonoValues
= put_mono_values_B5G5R5
;
278 else if (vis
->redBits
== 8 && vis
->greenBits
== 8 && vis
->blueBits
== 8
279 && vis
->alphaBits
== 8) {
280 drb
->Base
.GetRow
= get_row_B8G8R8A8
;
281 drb
->Base
.GetValues
= get_values_B8G8R8A8
;
282 drb
->Base
.PutRow
= put_row_B8G8R8A8
;
283 drb
->Base
.PutMonoRow
= put_mono_row_B8G8R8A8
;
284 drb
->Base
.PutRowRGB
= put_row_rgb_B8G8R8A8
;
285 drb
->Base
.PutValues
= put_values_B8G8R8A8
;
286 drb
->Base
.PutMonoValues
= put_mono_values_B8G8R8A8
;
288 else if (vis
->redBits
== 8 && vis
->greenBits
== 8 && vis
->blueBits
== 8
289 && vis
->alphaBits
== 0) {
290 drb
->Base
.GetRow
= get_row_B8G8R8
;
291 drb
->Base
.GetValues
= get_values_B8G8R8
;
292 drb
->Base
.PutRow
= put_row_B8G8R8
;
293 drb
->Base
.PutMonoRow
= put_mono_row_B8G8R8
;
294 drb
->Base
.PutRowRGB
= put_row_rgb_B8G8R8
;
295 drb
->Base
.PutValues
= put_values_B8G8R8
;
296 drb
->Base
.PutMonoValues
= put_mono_values_B8G8R8
;
298 else if (vis
->indexBits
== 8) {
299 drb
->Base
.GetRow
= get_row_CI8
;
300 drb
->Base
.GetValues
= get_values_CI8
;
301 drb
->Base
.PutRow
= put_row_CI8
;
302 drb
->Base
.PutMonoRow
= put_mono_row_CI8
;
303 drb
->Base
.PutValues
= put_values_CI8
;
304 drb
->Base
.PutMonoValues
= put_mono_values_CI8
;
308 /* hardware z/stencil/etc someday */
314 /* Initialize the driver specific screen private data.
317 fbInitDriver( __DRIscreenPrivate
*sPriv
)
319 sPriv
->private = NULL
;
324 fbDestroyScreen( __DRIscreenPrivate
*sPriv
)
329 /* Create the device specific context.
332 fbCreateContext( const __GLcontextModes
*glVisual
,
333 __DRIcontextPrivate
*driContextPriv
,
334 void *sharedContextPrivate
)
337 GLcontext
*ctx
, *shareCtx
;
338 struct dd_function_table functions
;
341 assert(driContextPriv
);
343 /* Allocate the Fb context */
344 fbmesa
= (fbContextPtr
) _mesa_calloc( sizeof(*fbmesa
) );
348 /* Init default driver functions then plug in our FBdev-specific functions
350 _mesa_init_driver_functions(&functions
);
351 init_core_functions(&functions
);
353 /* Allocate the Mesa context */
354 if (sharedContextPrivate
)
355 shareCtx
= ((fbContextPtr
) sharedContextPrivate
)->glCtx
;
359 ctx
= fbmesa
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
360 &functions
, (void *) fbmesa
);
361 if (!fbmesa
->glCtx
) {
365 driContextPriv
->driverPrivate
= fbmesa
;
367 /* Create module contexts */
368 _swrast_CreateContext( ctx
);
369 _ac_CreateContext( ctx
);
370 _tnl_CreateContext( ctx
);
371 _swsetup_CreateContext( ctx
);
372 _swsetup_Wakeup( ctx
);
375 /* use default TCL pipeline */
377 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
378 tnl
->Driver
.RunPipeline
= _tnl_run_pipeline
;
381 _mesa_enable_sw_extensions(ctx
);
388 fbDestroyContext( __DRIcontextPrivate
*driContextPriv
)
390 GET_CURRENT_CONTEXT(ctx
);
391 fbContextPtr fbmesa
= (fbContextPtr
) driContextPriv
->driverPrivate
;
392 fbContextPtr current
= ctx
? FB_CONTEXT(ctx
) : NULL
;
394 /* check if we're deleting the currently bound context */
395 if (fbmesa
== current
) {
396 _mesa_make_current(NULL
, NULL
, NULL
);
399 /* Free fb context resources */
401 _swsetup_DestroyContext( fbmesa
->glCtx
);
402 _tnl_DestroyContext( fbmesa
->glCtx
);
403 _ac_DestroyContext( fbmesa
->glCtx
);
404 _swrast_DestroyContext( fbmesa
->glCtx
);
406 /* free the Mesa context */
407 fbmesa
->glCtx
->DriverCtx
= NULL
;
408 _mesa_destroy_context( fbmesa
->glCtx
);
410 _mesa_free( fbmesa
);
415 /* Create and initialize the Mesa and driver specific pixmap buffer
419 fbCreateBuffer( __DRIscreenPrivate
*driScrnPriv
,
420 __DRIdrawablePrivate
*driDrawPriv
,
421 const __GLcontextModes
*mesaVis
,
424 struct gl_framebuffer
*mesa_framebuffer
;
427 return GL_FALSE
; /* not implemented */
430 const GLboolean swDepth
= mesaVis
->depthBits
> 0;
431 const GLboolean swAlpha
= mesaVis
->alphaBits
> 0;
432 const GLboolean swAccum
= mesaVis
->accumRedBits
> 0;
433 const GLboolean swStencil
= mesaVis
->stencilBits
> 0;
435 mesa_framebuffer
= _mesa_create_framebuffer(mesaVis
);
436 if (!mesa_framebuffer
)
439 /* XXX double-check these parameters (bpp vs cpp, etc) */
441 driRenderbuffer
*drb
= driNewRenderbuffer(GL_RGBA
,
443 driScrnPriv
->fbBPP
/ 8,
444 driScrnPriv
->fbOrigin
,
445 driScrnPriv
->fbStride
,
447 fbSetSpanFunctions(drb
, mesaVis
);
448 _mesa_add_renderbuffer(mesa_framebuffer
,
449 BUFFER_FRONT_LEFT
, &drb
->Base
);
451 if (mesaVis
->doubleBufferMode
) {
452 /* XXX what are the correct origin/stride values? */
453 GLvoid
*backBuf
= _mesa_malloc(driScrnPriv
->fbStride
454 * driScrnPriv
->fbHeight
);
455 driRenderbuffer
*drb
= driNewRenderbuffer(GL_RGBA
,
457 driScrnPriv
->fbBPP
/8,
458 driScrnPriv
->fbOrigin
,
459 driScrnPriv
->fbStride
,
461 fbSetSpanFunctions(drb
, mesaVis
);
462 _mesa_add_renderbuffer(mesa_framebuffer
,
463 BUFFER_BACK_LEFT
, &drb
->Base
);
466 _mesa_add_soft_renderbuffers(mesa_framebuffer
,
467 GL_FALSE
, /* color */
471 swAlpha
, /* or always zero? */
474 driDrawPriv
->driverPrivate
= mesa_framebuffer
;
482 fbDestroyBuffer(__DRIdrawablePrivate
*driDrawPriv
)
484 struct gl_framebuffer
*mesa_framebuffer
= (struct gl_framebuffer
*)driDrawPriv
->driverPrivate
;
486 _mesa_free(mesa_framebuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
->Data
);
487 _mesa_destroy_framebuffer(mesa_framebuffer
);
488 driDrawPriv
->driverPrivate
= NULL
;
493 /* If the backbuffer is on a videocard, this is extraordinarily slow!
496 fbSwapBuffers( __DRIdrawablePrivate
*dPriv
)
498 struct gl_framebuffer
*mesa_framebuffer
= (struct gl_framebuffer
*)dPriv
->driverPrivate
;
499 struct gl_renderbuffer
* front_renderbuffer
= mesa_framebuffer
->Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
;
500 void *frontBuffer
= front_renderbuffer
->Data
;
501 int currentPitch
= ((driRenderbuffer
*)front_renderbuffer
)->pitch
;
502 void *backBuffer
= mesa_framebuffer
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
->Data
;
504 if (dPriv
->driContextPriv
&& dPriv
->driContextPriv
->driverPrivate
) {
505 fbContextPtr fbmesa
= (fbContextPtr
) dPriv
->driContextPriv
->driverPrivate
;
506 GLcontext
*ctx
= fbmesa
->glCtx
;
508 if (ctx
->Visual
.doubleBufferMode
) {
511 char *tmp
= _mesa_malloc(currentPitch
);
513 _mesa_notifySwapBuffers( ctx
); /* flush pending rendering comands */
518 for (i
= 0; i
< dPriv
->h
; i
++) {
519 _mesa_memcpy(tmp
, (char *) backBuffer
+ offset
,
521 _mesa_memcpy((char *) frontBuffer
+ offset
, tmp
,
523 offset
+= currentPitch
;
530 /* XXX this shouldn't be an error but we can't handle it for now */
531 _mesa_problem(NULL
, "fbSwapBuffers: drawable has no context!\n");
536 /* Force the context `c' to be the current context and associate with it
540 fbMakeCurrent( __DRIcontextPrivate
*driContextPriv
,
541 __DRIdrawablePrivate
*driDrawPriv
,
542 __DRIdrawablePrivate
*driReadPriv
)
544 if ( driContextPriv
) {
545 fbContextPtr newFbCtx
=
546 (fbContextPtr
) driContextPriv
->driverPrivate
;
548 newFbCtx
->dri
.drawable
= driDrawPriv
;
550 _mesa_make_current( newFbCtx
->glCtx
,
551 driDrawPriv
->driverPrivate
,
552 driReadPriv
->driverPrivate
);
554 _mesa_make_current( NULL
, NULL
, NULL
);
561 /* Force the context `c' to be unbound from its buffer.
564 fbUnbindContext( __DRIcontextPrivate
*driContextPriv
)
569 static struct __DriverAPIRec fbAPI
= {
570 .InitDriver
= fbInitDriver
,
571 .DestroyScreen
= fbDestroyScreen
,
572 .CreateContext
= fbCreateContext
,
573 .DestroyContext
= fbDestroyContext
,
574 .CreateBuffer
= fbCreateBuffer
,
575 .DestroyBuffer
= fbDestroyBuffer
,
576 .SwapBuffers
= fbSwapBuffers
,
577 .MakeCurrent
= fbMakeCurrent
,
578 .UnbindContext
= fbUnbindContext
,
584 __driValidateMode(const DRIDriverContext
*ctx
)
590 __driInitFBDev( struct DRIDriverContextRec
*ctx
)
592 /* Note that drmOpen will try to load the kernel module, if needed. */
593 /* we need a fbdev drm driver - it will only track maps */
594 ctx
->drmFD
= drmOpen("radeon", NULL
);
595 if (ctx
->drmFD
< 0) {
596 fprintf(stderr
, "[drm] drmOpen failed\n");
600 ctx
->shared
.SAREASize
= SAREA_MAX
;
602 if (drmAddMap( ctx
->drmFD
,
604 ctx
->shared
.SAREASize
,
607 &ctx
->shared
.hSAREA
) < 0)
609 fprintf(stderr
, "[drm] drmAddMap failed\n");
612 fprintf(stderr
, "[drm] added %d byte SAREA at 0x%08lx\n",
613 ctx
->shared
.SAREASize
,
614 (unsigned long) ctx
->shared
.hSAREA
);
616 if (drmMap( ctx
->drmFD
,
618 ctx
->shared
.SAREASize
,
619 (drmAddressPtr
)(&ctx
->pSAREA
)) < 0)
621 fprintf(stderr
, "[drm] drmMap failed\n");
624 memset(ctx
->pSAREA
, 0, ctx
->shared
.SAREASize
);
625 fprintf(stderr
, "[drm] mapped SAREA 0x%08lx to %p, size %d\n",
626 (unsigned long) ctx
->shared
.hSAREA
, ctx
->pSAREA
,
627 ctx
->shared
.SAREASize
);
629 /* Need to AddMap the framebuffer and mmio regions here:
631 if (drmAddMap( ctx
->drmFD
,
632 (drm_handle_t
)ctx
->FBStart
,
640 &ctx
->shared
.hFrameBuffer
) < 0)
642 fprintf(stderr
, "[drm] drmAddMap framebuffer failed\n");
646 fprintf(stderr
, "[drm] framebuffer handle = 0x%08lx\n",
647 (unsigned long) ctx
->shared
.hFrameBuffer
);
653 __driHaltFBDev( struct DRIDriverContextRec
*ctx
)
657 struct DRIDriverRec __driDriver
= {
664 static __GLcontextModes
*
665 fbFillInModes( unsigned pixel_bits
, unsigned depth_bits
,
666 unsigned stencil_bits
, GLboolean have_back_buffer
)
668 __GLcontextModes
* modes
;
669 __GLcontextModes
* m
;
671 unsigned depth_buffer_factor
;
672 unsigned back_buffer_factor
;
676 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
677 * enough to add support. Basically, if a context is created with an
678 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
679 * will never be used.
681 static const GLenum back_buffer_modes
[] = {
682 GLX_NONE
, GLX_SWAP_UNDEFINED_OML
/*, GLX_SWAP_COPY_OML */
685 u_int8_t depth_bits_array
[2];
686 u_int8_t stencil_bits_array
[2];
689 depth_bits_array
[0] = depth_bits
;
690 depth_bits_array
[1] = depth_bits
;
692 /* Just like with the accumulation buffer, always provide some modes
693 * with a stencil buffer. It will be a sw fallback, but some apps won't
696 stencil_bits_array
[0] = 0;
697 stencil_bits_array
[1] = (stencil_bits
== 0) ? 8 : stencil_bits
;
699 depth_buffer_factor
= ((depth_bits
!= 0) || (stencil_bits
!= 0)) ? 2 : 1;
700 back_buffer_factor
= (have_back_buffer
) ? 2 : 1;
702 num_modes
= depth_buffer_factor
* back_buffer_factor
* 4;
704 if ( pixel_bits
== 16 ) {
706 fb_type
= GL_UNSIGNED_SHORT_5_6_5
;
710 fb_type
= GL_UNSIGNED_INT_8_8_8_8_REV
;
713 modes
= (*dri_interface
->createContextModes
)( num_modes
, sizeof( __GLcontextModes
) );
715 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
716 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
717 back_buffer_modes
, back_buffer_factor
,
719 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
720 __func__
, __LINE__
);
724 if ( ! driFillInModes( & m
, fb_format
, fb_type
,
725 depth_bits_array
, stencil_bits_array
, depth_buffer_factor
,
726 back_buffer_modes
, back_buffer_factor
,
727 GLX_DIRECT_COLOR
) ) {
728 fprintf( stderr
, "[%s:%u] Error creating FBConfig!\n",
729 __func__
, __LINE__
);
733 /* Mark the visual as slow if there are "fake" stencil bits.
735 for ( m
= modes
; m
!= NULL
; m
= m
->next
) {
736 if ( (m
->stencilBits
!= 0) && (m
->stencilBits
!= stencil_bits
) ) {
737 m
->visualRating
= GLX_SLOW_CONFIG
;
746 * This is the bootstrap function for the driver. libGL supplies all of the
747 * requisite information about the system, and the driver initializes itself.
748 * This routine also fills in the linked list pointed to by \c driver_modes
749 * with the \c __GLcontextModes that the driver can support for windows or
752 * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
756 void * __driCreateNewScreen( __DRInativeDisplay
*dpy
, int scrn
, __DRIscreen
*psc
,
757 const __GLcontextModes
* modes
,
758 const __DRIversion
* ddx_version
,
759 const __DRIversion
* dri_version
,
760 const __DRIversion
* drm_version
,
761 const __DRIframebuffer
* frame_buffer
,
762 drmAddress pSAREA
, int fd
,
763 int internal_api_version
,
764 __GLcontextModes
** driver_modes
)
766 __DRIscreenPrivate
*psp
;
767 static const __DRIversion ddx_expected
= { 4, 0, 0 };
768 static const __DRIversion dri_expected
= { 4, 0, 0 };
769 static const __DRIversion drm_expected
= { 1, 5, 0 };
772 if ( ! driCheckDriDdxDrmVersions2( "fb",
773 dri_version
, & dri_expected
,
774 ddx_version
, & ddx_expected
,
775 drm_version
, & drm_expected
) ) {
779 psp
= __driUtilCreateNewScreen(dpy
, scrn
, psc
, NULL
,
780 ddx_version
, dri_version
, drm_version
,
781 frame_buffer
, pSAREA
, fd
,
782 internal_api_version
, &fbAPI
);
784 *driver_modes
= fbFillInModes( psp
->fbBPP
,
785 (psp
->fbBPP
== 16) ? 16 : 24,
786 (psp
->fbBPP
== 16) ? 0 : 8,