mesa: add bool param to _mesa_free_context_data
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common.c
index d834d9bde3f05f1bf1f0b6bc39b050a70bd25cf3..1b734d26a57d072a4cf9d8798a616cf7906540d4 100644 (file)
@@ -43,7 +43,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <errno.h>
 #include "main/glheader.h"
-#include "main/imports.h"
 #include "main/context.h"
 #include "main/enums.h"
 #include "main/fbobject.h"
@@ -175,27 +174,6 @@ uint32_t radeonGetAge(radeonContextPtr radeon)
        return age;
 }
 
-/**
- * Check if we're about to draw into the front color buffer.
- * If so, set the intel->front_buffer_dirty field to true.
- */
-void
-radeon_check_front_buffer_rendering(struct gl_context *ctx)
-{
-       radeonContextPtr radeon = RADEON_CONTEXT(ctx);
-       const struct gl_framebuffer *fb = ctx->DrawBuffer;
-
-       if (fb->Name == 0) {
-               /* drawing to window system buffer */
-               if (fb->_NumColorDrawBuffers > 0) {
-                       if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
-                               radeon->front_buffer_dirty = GL_TRUE;
-                       }
-               }
-       }
-}
-
-
 void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
@@ -306,7 +284,6 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
        if (ctx->Driver.Enable) {
                ctx->Driver.Enable(ctx, GL_DEPTH_TEST,
                                   (ctx->Depth.Test && fb->Visual.depthBits > 0));
-               /* Need to update the derived ctx->Stencil._Enabled first */
                ctx->Driver.Enable(ctx, GL_STENCIL_TEST,
                                   (ctx->Stencil.Enabled && fb->Visual.stencilBits > 0));
        } else {
@@ -339,28 +316,22 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 /**
  * Called via glDrawBuffer.
  */
-void radeonDrawBuffer( struct gl_context *ctx, GLenum mode )
+void radeonDrawBuffer(struct gl_context *ctx)
 {
        if (RADEON_DEBUG & RADEON_DRI)
-               fprintf(stderr, "%s %s\n", __func__,
-                       _mesa_lookup_enum_by_nr( mode ));
+               fprintf(stderr, "%s\n", __func__);
 
-       if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
+       if (_mesa_is_front_buffer_drawing(ctx->DrawBuffer)) {
                radeonContextPtr radeon = RADEON_CONTEXT(ctx);
 
-               const GLboolean was_front_buffer_rendering =
-                       radeon->is_front_buffer_rendering;
-
-               radeon->is_front_buffer_rendering = (mode == GL_FRONT_LEFT) ||
-                                            (mode == GL_FRONT);
-
-      /* If we weren't front-buffer rendering before but we are now, make sure
-       * that the front-buffer has actually been allocated.
-       */
-               if (!was_front_buffer_rendering && radeon->is_front_buffer_rendering) {
-                       radeon_update_renderbuffers(radeon->driContext,
-                               radeon->driContext->driDrawablePriv, GL_FALSE);
-      }
+               /* If we might be front-buffer rendering on this buffer for
+                * the first time, invalidate our DRI drawable so we'll ask
+                * for new buffers (including the fake front) before we start
+                * rendering again.
+                */
+               radeon_update_renderbuffers(radeon->driContext,
+                                           radeon->driContext->driDrawablePriv,
+                                           GL_FALSE);
        }
 
        radeon_draw_buffer(ctx, ctx->DrawBuffer);
@@ -368,16 +339,10 @@ void radeonDrawBuffer( struct gl_context *ctx, GLenum mode )
 
 void radeonReadBuffer( struct gl_context *ctx, GLenum mode )
 {
-       if (ctx->DrawBuffer && _mesa_is_winsys_fbo(ctx->DrawBuffer)) {
+       if (_mesa_is_front_buffer_reading(ctx->ReadBuffer)) {
                struct radeon_context *const rmesa = RADEON_CONTEXT(ctx);
-               const GLboolean was_front_buffer_reading = rmesa->is_front_buffer_reading;
-               rmesa->is_front_buffer_reading = (mode == GL_FRONT_LEFT)
-                                       || (mode == GL_FRONT);
-
-               if (!was_front_buffer_reading && rmesa->is_front_buffer_reading) {
-                       radeon_update_renderbuffers(rmesa->driContext,
-                                                   rmesa->driContext->driReadablePriv, GL_FALSE);
-               }
+               radeon_update_renderbuffers(rmesa->driContext,
+                                           rmesa->driContext->driReadablePriv, GL_FALSE);
        }
        /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
        if (ctx->ReadBuffer == ctx->DrawBuffer) {
@@ -403,7 +368,7 @@ void radeon_viewport(struct gl_context *ctx)
        void (*old_viewport)(struct gl_context *ctx);
 
        if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
-               if (radeon->is_front_buffer_rendering) {
+               if (_mesa_is_front_buffer_drawing(ctx->DrawBuffer)) {
                        ctx->Driver.Flush(ctx);
                }
                radeon_update_renderbuffers(driContext, driContext->driDrawablePriv, GL_FALSE);
@@ -426,7 +391,7 @@ static void radeon_print_state_atom(radeonContextPtr radeon, struct radeon_state
        if (!radeon_is_debug_enabled(RADEON_STATE, RADEON_VERBOSE) )
                return;
 
-       dwords = (*state->check) (&radeon->glCtx, state);
+       dwords = state->check(&radeon->glCtx, state);
 
        fprintf(stderr, "  emit %s %d/%d\n", state->name, dwords, state->cmd_size);
 
@@ -491,13 +456,13 @@ static inline void radeon_emit_atom(radeonContextPtr radeon, struct radeon_state
        BATCH_LOCALS(radeon);
        int dwords;
 
-       dwords = (*atom->check) (&radeon->glCtx, atom);
+       dwords = atom->check(&radeon->glCtx, atom);
        if (dwords) {
 
                radeon_print_state_atom(radeon, atom);
 
                if (atom->emit) {
-                       (*atom->emit)(&radeon->glCtx, atom);
+                       atom->emit(&radeon->glCtx, atom);
                } else {
                        BEGIN_BATCH(dwords);
                        OUT_BATCH_TABLE(atom->cmd, dwords);
@@ -591,7 +556,7 @@ flush_front:
                         */
                        radeon->front_buffer_dirty = GL_FALSE;
 
-                       (*screen->dri2.loader->flushFrontBuffer)(drawable, drawable->loaderPrivate);
+                       screen->dri2.loader->flushFrontBuffer(drawable, drawable->loaderPrivate);
                }
        }
 }