util: rename xmlpool.h to driconf.h
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common_context.c
index ceaefdad91c3cffc9846793dd5bf7ed969541750..416d2d988fec06c882b354d3aa6ce94495d23949 100644 (file)
@@ -33,7 +33,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 **************************************************************************/
 
 #include "radeon_common.h"
-#include "xmlpool.h"           /* for symbolic values of enum-type options */
+#include "util/driconf.h"              /* for symbolic values of enum-type options */
 #include "utils.h"
 #include "drivers/common/meta.h"
 #include "main/context.h"
@@ -41,7 +41,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "main/fbobject.h"
 #include "main/renderbuffer.h"
 #include "main/state.h"
-#include "main/simple_list.h"
+#include "util/simple_list.h"
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "tnl/tnl.h"
@@ -70,44 +70,47 @@ static const char* get_chip_family_name(int chip_family)
        }
 }
 
+const char *const radeonVendorString = "Mesa Project";
 
-/* Return various strings for glGetString().
+/* Return complete renderer string.
  */
-static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name)
+const char *radeonGetRendererString(radeonScreenPtr radeonScreen)
 {
-       radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        static char buffer[128];
+       char hardwarename[32];
 
-       switch (name) {
-       case GL_VENDOR:
-               return (GLubyte *) "Tungsten Graphics, Inc.";
-
-       case GL_RENDERER:
-       {
-               unsigned offset;
-               GLuint agp_mode = (radeon->radeonScreen->card_type==RADEON_CARD_PCI) ? 0 :
-                       radeon->radeonScreen->AGPMode;
-               char hardwarename[32];
+       GLuint agp_mode = (radeonScreen->card_type==RADEON_CARD_PCI) ? 0 :
+               radeonScreen->AGPMode;
 
-               sprintf(hardwarename, "%s (%s %04X)",
+       snprintf(hardwarename, sizeof(hardwarename), "%s (%s %04X)",
 #if defined(RADEON_R100)
-                       "R100",
+               "R100",
 #elif defined(RADEON_R200)
-                       "R200",
+               "R200",
 #endif
-                       get_chip_family_name(radeon->radeonScreen->chip_family),
-                       radeon->radeonScreen->device_id);
+               get_chip_family_name(radeonScreen->chip_family),
+               radeonScreen->device_id);
 
-               offset = driGetRendererString(buffer, hardwarename, agp_mode);
+       driGetRendererString(buffer, hardwarename, agp_mode);
 
-               sprintf(&buffer[offset], " %sTCL",
-                       !(radeon->TclFallback & RADEON_TCL_FALLBACK_TCL_DISABLE)
-                       ? "" : "NO-");
+       strcat(buffer, " DRI2");
 
-               strcat(buffer, " DRI2");
+       return buffer;
+}
 
-               return (GLubyte *) buffer;
-       }
+
+/* Return various strings for glGetString().
+ */
+static const GLubyte *radeonGetString(struct gl_context * ctx, GLenum name)
+{
+       radeonContextPtr radeon = RADEON_CONTEXT(ctx);
+
+       switch (name) {
+       case GL_VENDOR:
+               return (GLubyte *) radeonVendorString;
+
+       case GL_RENDERER:
+               return (GLubyte *) radeonGetRendererString(radeon->radeonScreen);
 
        default:
                return NULL;
@@ -126,6 +129,7 @@ static void radeonInitDriverFuncs(struct dd_function_table *functions)
  * including the Mesa context itself.
  */
 GLboolean radeonInitContext(radeonContextPtr radeon,
+                            gl_api api,
                            struct dd_function_table* functions,
                            const struct gl_config * glVisual,
                            __DRIcontext * driContextPriv,
@@ -143,24 +147,22 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
        radeon->radeonScreen = screen;
        /* Allocate and initialize the Mesa context */
        if (sharedContextPrivate)
-               shareCtx = ((radeonContextPtr)sharedContextPrivate)->glCtx;
+               shareCtx = &((radeonContextPtr)sharedContextPrivate)->glCtx;
        else
                shareCtx = NULL;
-       radeon->glCtx = _mesa_create_context(API_OPENGL, glVisual, shareCtx,
-                                           functions, (void *)radeon);
-       if (!radeon->glCtx)
+
+       if (!_mesa_initialize_context(&radeon->glCtx, api,
+                                     glVisual, shareCtx,
+                                     functions))
                return GL_FALSE;
 
-       ctx = radeon->glCtx;
+       ctx = &radeon->glCtx;
        driContextPriv->driverPrivate = radeon;
 
        _mesa_meta_init(ctx);
 
        /* DRI fields */
-       radeon->dri.context = driContextPriv;
-       radeon->dri.screen = sPriv;
-       radeon->dri.fd = sPriv->fd;
-       radeon->dri.drmMinor = sPriv->drm_version.minor;
+       radeon->driContext = driContextPriv;
 
        /* Setup IRQs */
        fthrottle_mode = driQueryOptioni(&radeon->optionCache, "fthrottle_mode");
@@ -180,7 +182,7 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
         radeon->texture_depth = driQueryOptioni (&radeon->optionCache,
                                                "texture_depth");
         if (radeon->texture_depth == DRI_CONF_TEXTURE_DEPTH_FB)
-                radeon->texture_depth = ( glVisual->rgbBits > 16 ) ?
+                radeon->texture_depth = (glVisual == NULL || glVisual->rgbBits > 16) ?
                DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
 
        radeon->texture_row_align = 32;
@@ -189,6 +191,29 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
 
        radeon_init_dma(radeon);
 
+        /* _mesa_initialize_context calls _mesa_init_queryobj which
+         * initializes all of the counter sizes to 64.  The counters on r100
+         * and r200 are only 32-bits for occlusion queries.  Those are the
+         * only counters, so set the other sizes to zero.
+         */
+        radeon->glCtx.Const.QueryCounterBits.SamplesPassed = 32;
+
+        radeon->glCtx.Const.QueryCounterBits.TimeElapsed = 0;
+        radeon->glCtx.Const.QueryCounterBits.Timestamp = 0;
+        radeon->glCtx.Const.QueryCounterBits.PrimitivesGenerated = 0;
+        radeon->glCtx.Const.QueryCounterBits.PrimitivesWritten = 0;
+        radeon->glCtx.Const.QueryCounterBits.VerticesSubmitted = 0;
+        radeon->glCtx.Const.QueryCounterBits.PrimitivesSubmitted = 0;
+        radeon->glCtx.Const.QueryCounterBits.VsInvocations = 0;
+        radeon->glCtx.Const.QueryCounterBits.TessPatches = 0;
+        radeon->glCtx.Const.QueryCounterBits.TessInvocations = 0;
+        radeon->glCtx.Const.QueryCounterBits.GsInvocations = 0;
+        radeon->glCtx.Const.QueryCounterBits.GsPrimitives = 0;
+        radeon->glCtx.Const.QueryCounterBits.FsInvocations = 0;
+        radeon->glCtx.Const.QueryCounterBits.ComputeInvocations = 0;
+        radeon->glCtx.Const.QueryCounterBits.ClInPrimitives = 0;
+        radeon->glCtx.Const.QueryCounterBits.ClOutPrimitives = 0;
+
        return GL_TRUE;
 }
 
@@ -202,9 +227,8 @@ static void radeon_destroy_atom_list(radeonContextPtr radeon)
        struct radeon_state_atom *atom;
 
        foreach(atom, &radeon->hw.atomlist) {
-               FREE(atom->cmd);
-               if (atom->lastcmd)
-                       FREE(atom->lastcmd);
+               free(atom->cmd);
+               free(atom->lastcmd);
        }
 
 }
@@ -224,7 +248,7 @@ void radeonDestroyContext(__DRIcontext *driContextPriv )
 
        assert(radeon);
 
-       _mesa_meta_free(radeon->glCtx);
+       _mesa_meta_free(&radeon->glCtx);
 
        if (radeon == current) {
                _mesa_make_current(NULL, NULL, NULL);
@@ -232,27 +256,22 @@ void radeonDestroyContext(__DRIcontext *driContextPriv )
 
        radeon_firevertices(radeon);
        if (!is_empty_list(&radeon->dma.reserved)) {
-               rcommonFlushCmdBuf( radeon, __FUNCTION__ );
+               rcommonFlushCmdBuf( radeon, __func__ );
        }
 
        radeonFreeDmaRegions(radeon);
-       radeonReleaseArrays(radeon->glCtx, ~0);
+       radeonReleaseArrays(&radeon->glCtx, ~0);
        if (radeon->vtbl.free_context)
-               radeon->vtbl.free_context(radeon->glCtx);
-       _swsetup_DestroyContext( radeon->glCtx );
-       _tnl_DestroyContext( radeon->glCtx );
-       _vbo_DestroyContext( radeon->glCtx );
-       _swrast_DestroyContext( radeon->glCtx );
+               radeon->vtbl.free_context(&radeon->glCtx);
+       _swsetup_DestroyContext( &radeon->glCtx );
+       _tnl_DestroyContext( &radeon->glCtx );
+       _vbo_DestroyContext( &radeon->glCtx );
+       _swrast_DestroyContext( &radeon->glCtx );
 
        /* free atom list */
-       /* free the Mesa context */
-       _mesa_destroy_context(radeon->glCtx);
+       /* free the Mesa context data */
+       _mesa_free_context_data(&radeon->glCtx);
 
-       /* _mesa_destroy_context() might result in calls to functions that
-        * depend on the DriverCtx, so don't set it to NULL before.
-        *
-        * radeon->glCtx->DriverCtx = NULL;
-        */
        /* free the option cache */
        driDestroyOptionCache(&radeon->optionCache);
 
@@ -260,10 +279,6 @@ void radeonDestroyContext(__DRIcontext *driContextPriv )
 
        radeon_destroy_atom_list(radeon);
 
-       if (radeon->state.scissor.pClipRects) {
-               FREE(radeon->state.scissor.pClipRects);
-               radeon->state.scissor.pClipRects = 0;
-       }
 #ifdef RADEON_BO_TRACK
        track = fopen("/tmp/tracklog", "w");
        if (track) {
@@ -271,7 +286,7 @@ void radeonDestroyContext(__DRIcontext *driContextPriv )
                fclose(track);
        }
 #endif
-       FREE(radeon);
+       free(radeon);
 }
 
 /* Force the context `c' to be unbound from its buffer.
@@ -281,8 +296,8 @@ GLboolean radeonUnbindContext(__DRIcontext * driContextPriv)
        radeonContextPtr radeon = (radeonContextPtr) driContextPriv->driverPrivate;
 
        if (RADEON_DEBUG & RADEON_DRI)
-               fprintf(stderr, "%s ctx %p\n", __FUNCTION__,
-                       radeon->glCtx);
+               fprintf(stderr, "%s ctx %p\n", __func__,
+                       &radeon->glCtx);
 
        /* Unset current context and dispath table */
        _mesa_make_current(NULL, NULL, NULL);
@@ -294,7 +309,7 @@ GLboolean radeonUnbindContext(__DRIcontext * driContextPriv)
 static unsigned
 radeon_bits_per_pixel(const struct radeon_renderbuffer *rb)
 {
-   return _mesa_get_format_bytes(rb->base.Format) * 8; 
+   return _mesa_get_format_bytes(rb->base.Base.Format) * 8; 
 }
 
 /*
@@ -307,7 +322,7 @@ radeon_bits_per_pixel(const struct radeon_renderbuffer *rb)
  */
 void radeon_prepare_render(radeonContextPtr radeon)
 {
-    __DRIcontext *driContext = radeon->dri.context;
+    __DRIcontext *driContext = radeon->driContext;
     __DRIdrawable *drawable;
     __DRIscreen *screen;
 
@@ -321,7 +336,7 @@ void radeon_prepare_render(radeonContextPtr radeon)
            radeon_update_renderbuffers(driContext, drawable, GL_FALSE);
 
        /* Intel driver does the equivalent of this, no clue if it is needed:*/
-       radeon_draw_buffer(radeon->glCtx, radeon->glCtx->DrawBuffer);
+       radeon_draw_buffer(&radeon->glCtx, radeon->glCtx.DrawBuffer);
 
        driContext->dri2.draw_stamp = drawable->dri2.stamp;
     }
@@ -337,7 +352,7 @@ void radeon_prepare_render(radeonContextPtr radeon)
      * that will happen next will probably dirty the front buffer.  So
      * mark it as dirty here.
      */
-    if (radeon->is_front_buffer_rendering)
+    if (_mesa_is_front_buffer_drawing(radeon->glCtx.DrawBuffer))
        radeon->front_buffer_dirty = GL_TRUE;
 }
 
@@ -374,10 +389,10 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
                struct radeon_renderbuffer *stencil_rb;
 
                i = 0;
-               if ((front_only || radeon->is_front_buffer_rendering ||
-                    radeon->is_front_buffer_reading ||
-                    !draw->color_rb[1])
-                   && draw->color_rb[0]) {
+                if ((front_only || _mesa_is_front_buffer_drawing(&draw->base) ||
+                     _mesa_is_front_buffer_reading(&draw->base) ||
+                     !draw->color_rb[1])
+                    && draw->color_rb[0]) {
                        attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
                        attachments[i++] = radeon_bits_per_pixel(draw->color_rb[0]);
                }
@@ -403,12 +418,12 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
                        }
                }
 
-               buffers = (*screen->dri2.loader->getBuffersWithFormat)(drawable,
-                                                               &drawable->w,
-                                                               &drawable->h,
-                                                               attachments, i / 2,
-                                                               &count,
-                                                               drawable->loaderPrivate);
+               buffers = screen->dri2.loader->getBuffersWithFormat(drawable,
+                                                                   &drawable->w,
+                                                                   &drawable->h,
+                                                                   attachments, i / 2,
+                                                                   &count,
+                                                                   drawable->loaderPrivate);
        } else if (screen->dri2.loader) {
                i = 0;
                if (draw->color_rb[0])
@@ -422,12 +437,12 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
                                attachments[i++] = __DRI_BUFFER_STENCIL;
                }
 
-               buffers = (*screen->dri2.loader->getBuffers)(drawable,
-                                                                &drawable->w,
-                                                                &drawable->h,
-                                                                attachments, i,
-                                                                &count,
-                                                                drawable->loaderPrivate);
+               buffers = screen->dri2.loader->getBuffers(drawable,
+                                                         &drawable->w,
+                                                         &drawable->h,
+                                                         attachments, i,
+                                                         &count,
+                                                         drawable->loaderPrivate);
        }
 
        if (buffers == NULL)
@@ -484,8 +499,8 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
 
                rb->cpp = buffers[i].cpp;
                rb->pitch = buffers[i].pitch;
-               rb->base.Width = drawable->w;
-               rb->base.Height = drawable->h;
+               rb->base.Base.Width = drawable->w;
+               rb->base.Base.Height = drawable->h;
                rb->has_surface = 0;
 
                if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_bo) {
@@ -554,7 +569,7 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable,
                }
        }
 
-       driUpdateFramebufferSize(radeon->glCtx, drawable);
+       driUpdateFramebufferSize(&radeon->glCtx, drawable);
 }
 
 /* Force the context `c' to be the current context and associate with it
@@ -583,13 +598,13 @@ GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
 
        if (!driContextPriv) {
                if (RADEON_DEBUG & RADEON_DRI)
-                       fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
+                       fprintf(stderr, "%s ctx is null\n", __func__);
                _mesa_make_current(NULL, NULL, NULL);
                return GL_TRUE;
        }
 
        if(driDrawPriv == NULL && driReadPriv == NULL) {
-               drfb = _mesa_create_framebuffer(&radeon->glCtx->Visual);
+               drfb = _mesa_create_framebuffer(&radeon->glCtx.Visual);
                readfb = drfb;
        }
        else {
@@ -602,35 +617,35 @@ GLboolean radeonMakeCurrent(__DRIcontext * driContextPriv,
        if (driDrawPriv != driReadPriv)
           radeon_update_renderbuffers(driContextPriv, driReadPriv, GL_FALSE);
        _mesa_reference_renderbuffer(&radeon->state.color.rb,
-               &(radeon_get_renderbuffer(drfb, BUFFER_BACK_LEFT)->base));
+               &(radeon_get_renderbuffer(drfb, BUFFER_BACK_LEFT)->base.Base));
        _mesa_reference_renderbuffer(&radeon->state.depth.rb,
-               &(radeon_get_renderbuffer(drfb, BUFFER_DEPTH)->base));
+               &(radeon_get_renderbuffer(drfb, BUFFER_DEPTH)->base.Base));
 
        if (RADEON_DEBUG & RADEON_DRI)
-            fprintf(stderr, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__, radeon->glCtx, drfb, readfb);
+            fprintf(stderr, "%s ctx %p dfb %p rfb %p\n", __func__, &radeon->glCtx, drfb, readfb);
 
        if(driDrawPriv)
-               driUpdateFramebufferSize(radeon->glCtx, driDrawPriv);
+               driUpdateFramebufferSize(&radeon->glCtx, driDrawPriv);
        if (driReadPriv != driDrawPriv)
-               driUpdateFramebufferSize(radeon->glCtx, driReadPriv);
+               driUpdateFramebufferSize(&radeon->glCtx, driReadPriv);
 
-       _mesa_make_current(radeon->glCtx, drfb, readfb);
+       _mesa_make_current(&radeon->glCtx, drfb, readfb);
        if (driDrawPriv == NULL && driReadPriv == NULL)
                _mesa_reference_framebuffer(&drfb, NULL);
 
-       _mesa_update_state(radeon->glCtx);
+       _mesa_update_state(&radeon->glCtx);
 
-       if (radeon->glCtx->DrawBuffer == drfb) {
+       if (radeon->glCtx.DrawBuffer == drfb) {
                if(driDrawPriv != NULL) {
                        radeon_window_moved(radeon);
                }
 
-               radeon_draw_buffer(radeon->glCtx, drfb);
+               radeon_draw_buffer(&radeon->glCtx, drfb);
        }
 
 
        if (RADEON_DEBUG & RADEON_DRI)
-               fprintf(stderr, "End %s\n", __FUNCTION__);
+               fprintf(stderr, "End %s\n", __func__);
 
        return GL_TRUE;
 }