Imported the Savage DRI driver from the savage-2-0-0-branch of DRI CVS
[mesa.git] / src / mesa / drivers / dri / fb / fb_dri.c
index 945a78f2d0f6ab317c76d69d494daa5956f39488..2589c07142dee4495da201a431e4a1e3188b6567 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: fb_dri.c,v 1.1 2003/08/06 18:11:57 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -78,6 +77,7 @@
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
 #include "tnl/t_pipeline.h"
+#include "drivers/common/driverfuncs.h"
 
 
 
@@ -119,6 +119,10 @@ update_state( GLcontext *ctx, GLuint new_state )
 }
 
 
+/**
+ * Called by ctx->Driver.GetBufferSize from in core Mesa to query the
+ * current framebuffer size.
+ */
 static void
 get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
 {
@@ -157,46 +161,14 @@ set_buffer( GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit )
 
 
 static void
-init_core_functions( GLcontext *ctx )
+init_core_functions( struct dd_function_table *functions )
 {
-   ctx->Driver.GetString = get_string;
-   ctx->Driver.UpdateState = update_state;
-   ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
-   ctx->Driver.GetBufferSize = get_buffer_size;
-
-   ctx->Driver.Accum = _swrast_Accum;
-   ctx->Driver.Bitmap = _swrast_Bitmap;
-   ctx->Driver.Clear = _swrast_Clear;  /* could accelerate with blits */
-   ctx->Driver.CopyPixels = _swrast_CopyPixels;
-   ctx->Driver.DrawPixels = _swrast_DrawPixels;
-   ctx->Driver.ReadPixels = _swrast_ReadPixels;
-   ctx->Driver.DrawBuffer = _swrast_DrawBuffer;
-
-   ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
-   ctx->Driver.TexImage1D = _mesa_store_teximage1d;
-   ctx->Driver.TexImage2D = _mesa_store_teximage2d;
-   ctx->Driver.TexImage3D = _mesa_store_teximage3d;
-   ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
-   ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
-   ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
-   ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
-
-   ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
-   ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
-   ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
-   ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
-   ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
-   ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
-
-   ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
-   ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
-   ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
-   ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
-   ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
-   ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
-   ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
-   ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
-   ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
+   functions->GetString = get_string;
+   functions->UpdateState = update_state;
+   functions->ResizeBuffers = _swrast_alloc_buffers;
+   functions->GetBufferSize = get_buffer_size;
+
+   functions->Clear = _swrast_Clear;  /* could accelerate with blits */
 }
 
 
@@ -210,11 +182,11 @@ init_core_functions( GLcontext *ctx )
    const fbContextPtr fbdevctx = FB_CONTEXT(ctx); \
    __DRIdrawablePrivate *dPriv = fbdevctx->dri.drawable; 
 #define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (char *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X) * 3
+   GLubyte *P = (GLubyte *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X) * 3
 #define INC_PIXEL_PTR(P) P += 3
-#define STORE_RGB_PIXEL(P, R, G, B) \
+#define STORE_RGB_PIXEL(P, X, Y, R, G, B) \
    P[0] = B;  P[1] = G;  P[2] = R
-#define STORE_RGBA_PIXEL(P, R, G, B, A) \
+#define STORE_RGBA_PIXEL(P, X, Y, R, G, B, A) \
    P[0] = B;  P[1] = G;  P[2] = R
 #define FETCH_RGBA_PIXEL(R, G, B, A, P) \
    R = P[2];  G = P[1];  B = P[0];  A = CHAN_MAX
@@ -228,11 +200,11 @@ init_core_functions( GLcontext *ctx )
    const fbContextPtr fbdevctx = FB_CONTEXT(ctx); \
    __DRIdrawablePrivate *dPriv = fbdevctx->dri.drawable; 
 #define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (char *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X) * 4;
+   GLubyte *P = (GLubyte *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X) * 4;
 #define INC_PIXEL_PTR(P) P += 4
-#define STORE_RGB_PIXEL(P, R, G, B) \
+#define STORE_RGB_PIXEL(P, X, Y, R, G, B) \
    P[0] = B;  P[1] = G;  P[2] = R;  P[3] = 255
-#define STORE_RGBA_PIXEL(P, R, G, B, A) \
+#define STORE_RGBA_PIXEL(P, X, Y, R, G, B, A) \
    P[0] = B;  P[1] = G;  P[2] = R;  P[3] = A
 #define FETCH_RGBA_PIXEL(R, G, B, A, P) \
    R = P[2];  G = P[1];  B = P[0];  A = P[3]
@@ -248,9 +220,9 @@ init_core_functions( GLcontext *ctx )
 #define INIT_PIXEL_PTR(P, X, Y) \
    GLushort *P = (GLushort *) ((char *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X) * 2)
 #define INC_PIXEL_PTR(P) P += 1
-#define STORE_RGB_PIXEL(P, R, G, B) \
+#define STORE_RGB_PIXEL(P, X, Y, R, G, B) \
    *P = ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) )
-#define STORE_RGBA_PIXEL(P, R, G, B, A) \
+#define STORE_RGBA_PIXEL(P, X, Y, R, G, B, A) \
    *P = ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) )
 #define FETCH_RGBA_PIXEL(R, G, B, A, P) \
    R = ( (((*P) >> 8) & 0xf8) | (((*P) >> 11) & 0x7) ); \
@@ -269,9 +241,9 @@ init_core_functions( GLcontext *ctx )
 #define INIT_PIXEL_PTR(P, X, Y) \
    GLushort *P = (GLushort *) ((char *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X) * 2)
 #define INC_PIXEL_PTR(P) P += 1
-#define STORE_RGB_PIXEL(P, R, G, B) \
+#define STORE_RGB_PIXEL(P, X, Y, R, G, B) \
    *P = ( (((R) & 0xf8) << 7) | (((G) & 0xf8) << 2) | ((B) >> 3) )
-#define STORE_RGBA_PIXEL(P, R, G, B, A) \
+#define STORE_RGBA_PIXEL(P, X, Y, R, G, B, A) \
    *P = ( (((R) & 0xf8) << 7) | (((G) & 0xf8) << 2) | ((B) >> 3) )
 #define FETCH_RGBA_PIXEL(R, G, B, A, P) \
    R = ( (((*P) >> 7) & 0xf8) | (((*P) >> 10) & 0x7) ); \
@@ -288,14 +260,14 @@ init_core_functions( GLcontext *ctx )
    const fbContextPtr fbdevctx = FB_CONTEXT(ctx); \
    __DRIdrawablePrivate *dPriv = fbdevctx->dri.drawable;
 #define INIT_PIXEL_PTR(P, X, Y) \
-   GLubyte *P = (char *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X)
+   GLubyte *P = (GLubyte *)dPriv->currentBuffer + (Y) * dPriv->currentPitch + (X)
 #define INC_PIXEL_PTR(P) P += 1
 #define STORE_CI_PIXEL(P, CI) \
    P[0] = CI
 #define FETCH_CI_PIXEL(CI, P) \
    CI = P[0]
 
-#include "swrast/s_spantemp.h"
+ #include "swrast/s_spantemp.h"
 
 
 
@@ -322,6 +294,7 @@ fbCreateContext( const __GLcontextModes *glVisual,
 {
    fbContextPtr fbmesa;
    GLcontext *ctx, *shareCtx;
+   struct dd_function_table functions;
 
    assert(glVisual);
    assert(driContextPriv);
@@ -331,6 +304,11 @@ fbCreateContext( const __GLcontextModes *glVisual,
    if ( !fbmesa )
       return GL_FALSE;
 
+   /* Init default driver functions then plug in our FBdev-specific functions
+    */
+   _mesa_init_driver_functions(&functions);
+   init_core_functions(&functions);
+
    /* Allocate the Mesa context */
    if (sharedContextPrivate)
       shareCtx = ((fbContextPtr) sharedContextPrivate)->glCtx;
@@ -338,8 +316,7 @@ fbCreateContext( const __GLcontextModes *glVisual,
       shareCtx = NULL;
 
    ctx = fbmesa->glCtx = _mesa_create_context(glVisual, shareCtx, 
-                                             (void *) fbmesa, 
-                                             GL_TRUE);
+                                             &functions, (void *) fbmesa);
    if (!fbmesa->glCtx) {
       FREE(fbmesa);
       return GL_FALSE;
@@ -347,7 +324,6 @@ fbCreateContext( const __GLcontextModes *glVisual,
    driContextPriv->driverPrivate = fbmesa;
 
    /* Create module contexts */
-   init_core_functions( ctx );
    _swrast_CreateContext( ctx );
    _ac_CreateContext( ctx );
    _tnl_CreateContext( ctx );
@@ -355,7 +331,6 @@ fbCreateContext( const __GLcontextModes *glVisual,
    _swsetup_Wakeup( ctx );
 
 
-
    /* swrast init -- need to verify these tests - I just plucked the
     * numbers out of the air.  (KW)
     */
@@ -497,8 +472,6 @@ fbCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 }
 
 
-
-
 static void
 fbDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
@@ -611,15 +584,14 @@ __driRegisterExtensions( void )
 }
 
 
-
-
 /*
  * This is the bootstrap function for the driver.
  * The __driCreateScreen name is the symbol that libGL.so fetches.
  * Return:  pointer to a __DRIscreenPrivate.
  */
-void *__driCreateScreen(struct DRIDriverRec *driver,
-                        struct DRIDriverContextRec *driverContext)
+void *
+__driCreateScreen(struct DRIDriverRec *driver,
+                  struct DRIDriverContextRec *driverContext)
 {
    __DRIscreenPrivate *psp;
    psp = __driUtilCreateScreenNoDRM(driver, driverContext, &fbAPI);
@@ -627,6 +599,7 @@ void *__driCreateScreen(struct DRIDriverRec *driver,
 }
 
 
+
 /**
  * \brief Establish the set of modes available for the display.
  *
@@ -662,8 +635,11 @@ const __GLcontextModes __glModes[] = {
      .depthBits = 16, .stencilBits = 0,
      .numAuxBuffers= 0, .level = 0, .pixmapMode = GL_FALSE, },
 };
-static int __driInitScreenModes( const DRIDriverContext *ctx,
-                                  int *numModes, const __GLcontextModes **modes)
+
+
+static int
+__driInitScreenModes( const DRIDriverContext *ctx,
+                      int *numModes, const __GLcontextModes **modes)
 {
    *numModes = sizeof(__glModes)/sizeof(__GLcontextModes *);
    *modes = &__glModes[0];
@@ -672,7 +648,8 @@ static int __driInitScreenModes( const DRIDriverContext *ctx,
 
 
 
-static int __driValidateMode(const DRIDriverContext *ctx )
+static int
+__driValidateMode(const DRIDriverContext *ctx )
 {
    return 1;
 }
@@ -686,9 +663,10 @@ static int __driValidateMode(const DRIDriverContext *ctx )
 #else
 # define DRM_PAGE_SIZE 4096
 #endif
-                                                                                                                    
 
-static int __driInitFBDev( struct DRIDriverContextRec *ctx )
+
+static int
+__driInitFBDev( struct DRIDriverContextRec *ctx )
 {
    int id;
    ctx->shared.hFrameBuffer = ctx->FBStart;
@@ -713,7 +691,8 @@ static int __driInitFBDev( struct DRIDriverContextRec *ctx )
    return 1;
 }
 
-static void __driHaltFBDev( struct DRIDriverContextRec *ctx )
+static void
+__driHaltFBDev( struct DRIDriverContextRec *ctx )
 {
 }