Revert "radeon: Fix legacy bo not to reuse dma buffers before refcount is 1."
[mesa.git] / src / mesa / drivers / svga / svgamesa.c
index a808241998e4a838f9bb2f09c681f48b325f1b5f..5afa8e188bb8c8ca72a24034c71c7023b305e717 100644 (file)
@@ -1,9 +1,8 @@
-/* $Id: svgamesa.c,v 1.15 2001/03/19 02:25:36 keithw Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.3
- * Copyright (C) 1995-2000  Brian Paul
+ * Version:  5.0
+ * Copyright (C) 1995-2002  Brian Paul
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 
 #ifdef SVGA
 
-#ifdef PC_HEADER
-#include "all.h"
-#else
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <vga.h>
 #include "GL/svgamesa.h"
-#include "context.h"
-#include "extensions.h"
-#include "matrix.h"
-#include "mtypes.h"
+#include "main/buffers.h"
+#include "main/context.h"
+#include "main/extensions.h"
+#include "main/imports.h"
+#include "main/matrix.h"
+#include "main/mtypes.h"
 #include "swrast/swrast.h"
-#endif
-
 #include "svgapix.h"
 #include "svgamesa8.h"
 #include "svgamesa15.h"
@@ -210,41 +206,28 @@ static void copy_buffer( const GLubyte * buffer) {
  }
 }
 
-static void get_buffer_size( GLcontext *ctx, GLuint *width, GLuint *height )
+static void get_buffer_size( GLframebuffer *buffer, GLuint *width, GLuint *height )
 {
    *width = SVGAMesa->width = vga_getxdim();
    *height = SVGAMesa->height = vga_getydim();
 }
 
-static GLboolean set_draw_buffer( GLcontext *ctx, GLenum buffer )
+/**
+ * We only implement this function as a mechanism to check if the
+ * framebuffer size has changed (and update corresponding state).
+ */
+static void viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
 {
-   if (buffer == GL_FRONT_LEFT) {
-      SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
-#if 0
-      /*    vga_waitretrace(); */
-      void * tmpptr;
-      copy_buffer(SVGABuffer.FrontBuffer);
-      tmpptr=SVGABuffer.BackBuffer;
-      SVGABuffer.BackBuffer=SVGABuffer.FrontBuffer;
-      SVGABuffer.FrontBuffer=tmpptr;
-#endif
-      return GL_TRUE;
-   }
-   else if (buffer == GL_BACK_LEFT) {
-      SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
-#if 0
-      /*    vga_waitretrace(); */
-      copy_buffer(SVGABuffer.BackBuffer);
-#endif
-      return GL_TRUE;
+   GLuint newWidth, newHeight;
+   GLframebuffer *buffer = ctx->WinSysDrawBuffer;
+   get_buffer_size( buffer, &newWidth, &newHeight );
+   if (buffer->Width != newWidth || buffer->Height != newHeight) {
+      _mesa_resize_framebuffer(ctx, buffer, newWidth, newHeight );
    }
-   else
-      return GL_FALSE;
 }
 
-
-static void set_read_buffer( GLcontext *ctx, GLframebuffer *colorBuffer,
-                             GLenum buffer )
+static void set_buffer( GLcontext *ctx, GLframebuffer *colorBuffer,
+                        GLenum buffer )
 {
    /* We can ignore colorBuffer since we don't support a MakeCurrentRead()
     * function.
@@ -253,6 +236,7 @@ static void set_read_buffer( GLcontext *ctx, GLframebuffer *colorBuffer,
 
    if (buffer == GL_FRONT_LEFT) {
       SVGABuffer.ReadBuffer = SVGABuffer.FrontBuffer;
+      SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
 #if 0
       void * tmpptr;
       /*    vga_waitretrace(); */
@@ -264,6 +248,7 @@ static void set_read_buffer( GLcontext *ctx, GLframebuffer *colorBuffer,
    }
    else if (buffer == GL_BACK_LEFT) {
       SVGABuffer.ReadBuffer = SVGABuffer.BackBuffer;
+      SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
 #if 0
       /*    vga_waitretrace(); */
       copy_buffer(SVGABuffer.BackBuffer);
@@ -285,19 +270,11 @@ static void svgamesa_update_state( GLcontext *ctx, GLuint new_state )
    ctx->Driver.UpdateState = svgamesa_update_state;
 
    ctx->Driver.GetBufferSize = get_buffer_size;
-   ctx->Driver.SetDrawBuffer = set_draw_buffer;
-
-   /* Software rasterizer pixel paths:
-    */
-   ctx->Driver.Accum = _swrast_Accum;
-   ctx->Driver.Bitmap = _swrast_Bitmap;
-   ctx->Driver.CopyPixels = _swrast_CopyPixels;
-   ctx->Driver.DrawPixels = _swrast_DrawPixels;
-   ctx->Driver.ReadPixels = _swrast_ReadPixels;
+   ctx->Driver.Viewport = viewport;
 
    /* Fill in the swrast driver interface:
     */
-   swdd->SetReadBuffer = set_read_buffer;
+   swdd->SetBuffer = set_buffer;
 
    switch (SVGABuffer.Depth) {
     case  8: ctx->Driver.ClearIndex = __clear_index8;
@@ -377,6 +354,7 @@ SVGAMesaContext SVGAMesaCreateContext( GLboolean doubleBuffer )
    GLfloat redscale, greenscale, bluescale, alphascale;
    GLint index_bits;
    GLint redbits, greenbits, bluebits, alphabits;
+
    /* determine if we're in RGB or color index mode */
    if ((SVGABuffer.Depth==32) || (SVGABuffer.Depth==24)) {
       rgb_flag = GL_TRUE;
@@ -427,9 +405,12 @@ SVGAMesaContext SVGAMesaCreateContext( GLboolean doubleBuffer )
 
    ctx->gl_ctx = _mesa_create_context( ctx->gl_vis,
                                        NULL,  /* share list context */
-                                       (void *) ctx, GL_TRUE );
+                                       (void *) ctx, GL_FALSE );
 
    _mesa_enable_sw_extensions(ctx->gl_ctx);
+   _mesa_enable_1_3_extensions(ctx->gl_ctx);
+
+   _mesa_init_driver_functions(&ctx->Driver);
 
    ctx->gl_buffer = _mesa_create_framebuffer( ctx->gl_vis,
                                               ctx->gl_vis->depthBits > 0,
@@ -451,7 +432,6 @@ void SVGAMesaDestroyContext( SVGAMesaContext ctx )
    if (ctx) {
       _mesa_destroy_visual( ctx->gl_vis );
       _mesa_destroy_context( ctx->gl_ctx );
-      _mesa_destroy_framebuffer( ctx->gl_buffer );
       free( ctx );
       if (ctx==SVGAMesa) {
          SVGAMesa = NULL;
@@ -471,10 +451,8 @@ void SVGAMesaMakeCurrent( SVGAMesaContext ctx )
    _mesa_make_current( ctx->gl_ctx, ctx->gl_buffer );
 
    if (ctx->width==0 || ctx->height==0) {
-      /* setup initial viewport */
       ctx->width = vga_getxdim();
       ctx->height = vga_getydim();
-      _mesa_set_viewport( ctx->gl_ctx, 0, 0, ctx->width, ctx->height );
    }
 #endif
 }
@@ -500,7 +478,7 @@ void SVGAMesaSwapBuffers( void )
    copy_buffer(SVGABuffer.BackBuffer);
 
 #ifndef DEV
-   _mesa_swapbuffers( SVGAMesa->gl_ctx );
+   _mesa_notifySwapBuffers( SVGAMesa->gl_ctx );
    if (SVGAMesa->gl_vis->doubleBufferMode)
 #endif /* DEV */
    {
@@ -528,7 +506,7 @@ void SVGAMesaSwapBuffers( void )
  * Need this to provide at least one external definition when SVGA is
  * not defined on the compiler command line.
  */
-
+extern int gl_svga_dummy_function(void);
 int gl_svga_dummy_function(void)
 {
    return 0;