radeon/r200/r300: merge span code into single shared file
[mesa.git] / src / mesa / drivers / dri / r200 / r200_context.c
index 9f882fe6155af022c475dcdc4791e950d69d2f12..1d86a48a5d921357435ef4064fade099924eb927 100644 (file)
@@ -54,7 +54,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "r200_context.h"
 #include "r200_ioctl.h"
 #include "r200_state.h"
-#include "r200_span.h"
 #include "r200_pixel.h"
 #include "r200_tex.h"
 #include "r200_swtcl.h"
@@ -82,9 +81,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "vblank.h"
 #include "utils.h"
 #include "xmlpool.h" /* for symbolic values of enum-type options */
-#ifndef R200_DEBUG
-int R200_DEBUG = (0);
-#endif
 
 /* Return various strings for glGetString().
  */
@@ -262,13 +258,48 @@ static void r200_get_lock(radeonContextPtr radeon)
       DRI_AGE_TEXTURES( rmesa->radeon.texture_heaps[ i ] );
    }
 }
-   
+
+
+static void r200_vtbl_flush(GLcontext *ctx)
+{
+   R200_FIREVERTICES(R200_CONTEXT(ctx));
+}
+
+static void r200_vtbl_flush_vertices(radeonContextPtr rmesa)
+{
+  R200_FIREVERTICES(((r200ContextPtr)rmesa));
+}
+
+static void r200_vtbl_set_all_dirty(GLcontext *ctx)
+{
+   r200ContextPtr rmesa = R200_CONTEXT(ctx);
+   rmesa->hw.all_dirty = GL_TRUE;
+}
+
+static void r200_vtbl_emit_cs_header(struct radeon_cs *cs, radeonContextPtr rmesa)
+{
+}
+
+static void r200_vtbl_emit_state(radeonContextPtr rmesa)
+{
+       r200EmitState((r200ContextPtr)rmesa);
+}
+
+
 static void r200_init_vtbl(radeonContextPtr radeon)
 {
    radeon->vtbl.get_lock = r200_get_lock;
    radeon->vtbl.update_viewport_offset = r200UpdateViewportOffset;
+   radeon->vtbl.flush = r200_vtbl_flush;
+   radeon->vtbl.flush_vertices = r200_vtbl_flush_vertices;
+   radeon->vtbl.set_all_dirty = r200_vtbl_set_all_dirty;
+   radeon->vtbl.update_draw_buffer = r200UpdateDrawBuffer;
+   radeon->vtbl.emit_cs_header = r200_vtbl_emit_cs_header;
+   radeon->vtbl.emit_state = r200_vtbl_emit_state;
+   radeon->vtbl.swtcl_flush = r200_swtcl_flush;
 }
 
+
 /* Create the device specific rendering context.
  */
 GLboolean r200CreateContext( const __GLcontextModes *glVisual,
@@ -279,9 +310,9 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual,
    radeonScreenPtr screen = (radeonScreenPtr)(sPriv->private);
    struct dd_function_table functions;
    r200ContextPtr rmesa;
-   GLcontext *ctx, *shareCtx;
+   GLcontext *ctx;
    int i;
-   int tcl_mode, fthrottle_mode;
+   int tcl_mode;
 
    assert(glVisual);
    assert(driContextPriv);
@@ -326,40 +357,20 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual,
    r200InitTextureFuncs(&functions);
    r200InitShaderFuncs(&functions); 
 
-   /* Allocate and initialize the Mesa context */
-   if (sharedContextPrivate)
-      shareCtx = ((r200ContextPtr) sharedContextPrivate)->radeon.glCtx;
-   else
-      shareCtx = NULL;
-   rmesa->radeon.glCtx = _mesa_create_context(glVisual, shareCtx,
-                                       &functions, (void *) rmesa);
-   if (!rmesa->radeon.glCtx) {
-      FREE(rmesa);
-      return GL_FALSE;
+   if (!radeonInitContext(&rmesa->radeon, &functions,
+                         glVisual, driContextPriv,
+                         sharedContextPrivate)) {
+     FREE(rmesa);
+     return GL_FALSE;
    }
-   driContextPriv->driverPrivate = rmesa;
 
-   /* Init r200 context data */
-   rmesa->radeon.dri.context = driContextPriv;
-   rmesa->radeon.dri.screen = sPriv;
-   rmesa->radeon.dri.drawable = NULL; /* Set by XMesaMakeCurrent */
-   rmesa->radeon.dri.hwContext = driContextPriv->hHWContext;
-   rmesa->radeon.dri.hwLock = &sPriv->pSAREA->lock;
-   rmesa->radeon.dri.fd = sPriv->fd;
-   rmesa->radeon.dri.drmMinor = sPriv->drm_version.minor;
-
-   rmesa->radeon.radeonScreen = screen;
-   rmesa->radeon.sarea = (drm_radeon_sarea_t *)((GLubyte *)sPriv->pSAREA +
-                                      screen->sarea_priv_offset);
-
-
-   rmesa->dma.buf0_address = rmesa->radeon.radeonScreen->buffers->list[0].address;
 
    (void) memset( rmesa->radeon.texture_heaps, 0, sizeof( rmesa->radeon.texture_heaps ) );
    make_empty_list( & rmesa->radeon.swapped );
 
    rmesa->radeon.nr_heaps = 1 /* screen->numTexHeaps */ ;
    assert(rmesa->radeon.nr_heaps < RADEON_NR_TEX_HEAPS);
+#if 0
    for ( i = 0 ; i < rmesa->radeon.nr_heaps ; i++ ) {
       rmesa->radeon.texture_heaps[i] = driCreateTextureHeap( i, rmesa,
            screen->texSize[i],
@@ -371,13 +382,14 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual,
            sizeof( radeonTexObj ),
            (destroy_texture_object_t *) r200DestroyTexObj );
    }
+#endif
    rmesa->radeon.texture_depth = driQueryOptioni (&rmesa->radeon.optionCache,
                                           "texture_depth");
    if (rmesa->radeon.texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
       rmesa->radeon.texture_depth = ( screen->cpp == 4 ) ?
         DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
 
-   rmesa->swtcl.RenderIndex = ~0;
+   rmesa->radeon.swtcl.RenderIndex = ~0;
    rmesa->hw.all_dirty = 1;
 
    /* Set the maximum texture size small enough that we can guarentee that
@@ -508,32 +520,13 @@ GLboolean r200CreateContext( const __GLcontextModes *glVisual,
    /* plug in a few more device driver functions */
    /* XXX these should really go right after _mesa_init_driver_functions() */
    r200InitPixelFuncs( ctx );
-   r200InitSpanFuncs( ctx );
    r200InitTnlFuncs( ctx );
    r200InitState( rmesa );
    r200InitSwtcl( ctx );
 
-   fthrottle_mode = driQueryOptioni(&rmesa->radeon.optionCache, "fthrottle_mode");
-   rmesa->radeon.iw.irq_seq = -1;
-   rmesa->radeon.irqsEmitted = 0;
-   rmesa->radeon.do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
-                    rmesa->radeon.radeonScreen->irq);
-
-   rmesa->radeon.do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
-
-   if (!rmesa->radeon.do_irqs)
-      fprintf(stderr,
-             "IRQ's not enabled, falling back to %s: %d %d\n",
-             rmesa->radeon.do_usleeps ? "usleeps" : "busy waits",
-             fthrottle_mode,
-             rmesa->radeon.radeonScreen->irq);
-
    rmesa->prefer_gart_client_texturing = 
       (getenv("R200_GART_CLIENT_TEXTURES") != 0);
 
-   (*sPriv->systemTime->getUST)( & rmesa->radeon.swap_ust );
-
-
 #if DO_DEBUG
    R200_DEBUG  = driParseDebugString( getenv( "R200_DEBUG" ),
                                      debug_control );
@@ -590,9 +583,8 @@ void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
       r200DestroySwtcl( rmesa->radeon.glCtx );
       r200ReleaseArrays( rmesa->radeon.glCtx, ~0 );
 
-      if (rmesa->dma.current.buf) {
-        r200ReleaseDmaRegion( rmesa, &rmesa->dma.current, __FUNCTION__ );
-        r200FlushCmdBuf( rmesa, __FUNCTION__ );
+      if (rmesa->radeon.dma.current) {
+        rcommonFlushCmdBuf( &rmesa->radeon, __FUNCTION__ );
       }
 
       if (rmesa->radeon.state.scissor.pClipRects) {
@@ -600,6 +592,7 @@ void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
         rmesa->radeon.state.scissor.pClipRects = NULL;
       }
 
+
       if ( release_texture_heaps ) {
          /* This share group is about to go away, free our private
           * texture object data.
@@ -614,12 +607,7 @@ void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
         assert( is_empty_list( & rmesa->radeon.swapped ) );
       }
 
-      /* free the Mesa context */
-      rmesa->radeon.glCtx->DriverCtx = NULL;
-      _mesa_destroy_context( rmesa->radeon.glCtx );
-
-      /* free the option cache */
-      driDestroyOptionCache (&rmesa->radeon.optionCache);
+      radeonCleanupContext(&rmesa->radeon);
 
       FREE( rmesa );
    }
@@ -627,107 +615,6 @@ void r200DestroyContext( __DRIcontextPrivate *driContextPriv )
 
 
 
-
-void
-r200SwapBuffers( __DRIdrawablePrivate *dPriv )
-{
-   if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
-      r200ContextPtr rmesa;
-      GLcontext *ctx;
-      rmesa = (r200ContextPtr) dPriv->driContextPriv->driverPrivate;
-      ctx = rmesa->radeon.glCtx;
-      if (ctx->Visual.doubleBufferMode) {
-         _mesa_notifySwapBuffers( ctx );  /* flush pending rendering comands */
-         if ( rmesa->radeon.doPageFlip ) {
-            r200PageFlip( dPriv );
-         }
-         else {
-            r200CopyBuffer( dPriv, NULL );
-         }
-      }
-   }
-   else {
-      /* XXX this shouldn't be an error but we can't handle it for now */
-      _mesa_problem(NULL, "%s: drawable has no context!", __FUNCTION__);
-   }
-}
-
-void
-r200CopySubBuffer( __DRIdrawablePrivate *dPriv,
-                  int x, int y, int w, int h )
-{
-   if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
-      r200ContextPtr rmesa;
-      GLcontext *ctx;
-      rmesa = (r200ContextPtr) dPriv->driContextPriv->driverPrivate;
-      ctx = rmesa->radeon.glCtx;
-      if (ctx->Visual.doubleBufferMode) {
-        drm_clip_rect_t rect;
-        rect.x1 = x + dPriv->x;
-        rect.y1 = (dPriv->h - y - h) + dPriv->y;
-        rect.x2 = rect.x1 + w;
-        rect.y2 = rect.y1 + h;
-         _mesa_notifySwapBuffers( ctx );  /* flush pending rendering comands */
-        r200CopyBuffer( dPriv, &rect );
-      }
-   }
-   else {
-      /* XXX this shouldn't be an error but we can't handle it for now */
-      _mesa_problem(NULL, "%s: drawable has no context!", __FUNCTION__);
-   }
-}
-
-/* Force the context `c' to be the current context and associate with it
- * buffer `b'.
- */
-GLboolean
-r200MakeCurrent( __DRIcontextPrivate *driContextPriv,
-                   __DRIdrawablePrivate *driDrawPriv,
-                   __DRIdrawablePrivate *driReadPriv )
-{
-   if ( driContextPriv ) {
-      r200ContextPtr newCtx = 
-        (r200ContextPtr) driContextPriv->driverPrivate;
-
-      if (R200_DEBUG & DEBUG_DRI)
-        fprintf(stderr, "%s ctx %p\n", __FUNCTION__, (void *)newCtx->radeon.glCtx);
-
-      newCtx->radeon.dri.readable = driReadPriv;
-
-      if ( newCtx->radeon.dri.drawable != driDrawPriv ||
-           newCtx->radeon.lastStamp != driDrawPriv->lastStamp ) {
-        if (driDrawPriv->swap_interval == (unsigned)-1) {
-           driDrawPriv->vblFlags = (newCtx->radeon.radeonScreen->irq != 0)
-              ? driGetDefaultVBlankFlags(&newCtx->radeon.optionCache)
-              : VBLANK_FLAG_NO_IRQ;
-
-           driDrawableInitVBlank( driDrawPriv );
-        }
-
-        newCtx->radeon.dri.drawable = driDrawPriv;
-
-        r200SetCliprects(newCtx);
-        r200UpdateViewportOffset( newCtx->radeon.glCtx );
-      }
-
-      _mesa_make_current( newCtx->radeon.glCtx,
-                         (GLframebuffer *) driDrawPriv->driverPrivate,
-                         (GLframebuffer *) driReadPriv->driverPrivate );
-
-      _mesa_update_state( newCtx->radeon.glCtx );
-      r200ValidateState( newCtx->radeon.glCtx );
-
-   } else {
-      if (R200_DEBUG & DEBUG_DRI)
-        fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
-      _mesa_make_current( NULL, NULL, NULL );
-   }
-
-   if (R200_DEBUG & DEBUG_DRI)
-      fprintf(stderr, "End %s\n", __FUNCTION__);
-   return GL_TRUE;
-}
-
 /* Force the context `c' to be unbound from its buffer.
  */
 GLboolean