Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa into pipe-video
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common.c
index f8a4cdb4954f1f5a4b9f56370c422597423e8cd2..13f1f0611b85b3059df70001a2d802be956ed58d 100644 (file)
@@ -137,7 +137,7 @@ void radeon_get_cliprects(radeonContextPtr radeon,
                          unsigned int *num_cliprects,
                          int *x_off, int *y_off)
 {
-       __DRIdrawablePrivate *dPriv = radeon_get_drawable(radeon);
+       __DRIdrawable *dPriv = radeon_get_drawable(radeon);
        struct radeon_framebuffer *rfb = dPriv->driverPrivate;
 
        if (radeon->constant_cliprect) {
@@ -169,8 +169,8 @@ void radeon_get_cliprects(radeonContextPtr radeon,
  */
 void radeonSetCliprects(radeonContextPtr radeon)
 {
-       __DRIdrawablePrivate *const drawable = radeon_get_drawable(radeon);
-       __DRIdrawablePrivate *const readable = radeon_get_readable(radeon);
+       __DRIdrawable *const drawable = radeon_get_drawable(radeon);
+       __DRIdrawable *const readable = radeon_get_readable(radeon);
        struct radeon_framebuffer *const draw_rfb = drawable->driverPrivate;
        struct radeon_framebuffer *const read_rfb = readable->driverPrivate;
        int x_off, y_off;
@@ -229,16 +229,15 @@ void radeonUpdateScissor( GLcontext *ctx )
        }
        if (!rmesa->radeonScreen->kernel_mm) {
           /* Fix scissors for dri 1 */
-
-          __DRIdrawablePrivate *dPriv = radeon_get_drawable(rmesa);
+          __DRIdrawable *dPriv = radeon_get_drawable(rmesa);
           x1 += dPriv->x;
-          x2 += dPriv->x;
+          x2 += dPriv->x + 1;
           min_x += dPriv->x;
-          max_x += dPriv->x;
+          max_x += dPriv->x + 1;
           y1 += dPriv->y;
-          y2 += dPriv->y;
+          y2 += dPriv->y + 1;
           min_y += dPriv->y;
-          max_y += dPriv->y;
+          max_y += dPriv->y + 1;
        }
 
        rmesa->state.scissor.rect.x1 = CLAMP(x1,  min_x, max_x);
@@ -263,29 +262,6 @@ void radeonScissor(GLcontext* ctx, GLint x, GLint y, GLsizei w, GLsizei h)
        }
 }
 
-void radeonPolygonStipplePreKMS( GLcontext *ctx, const GLubyte *mask )
-{
-   radeonContextPtr radeon = RADEON_CONTEXT(ctx);
-   GLuint i;
-   drm_radeon_stipple_t stipple;
-
-   /* Must flip pattern upside down.
-   */
-   for ( i = 0 ; i < 32 ; i++ ) {
-      stipple.mask[31 - i] = ((GLuint *) mask)[i];
-   }
-
-   /* TODO: push this into cmd mechanism
-   */
-   radeon_firevertices(radeon);
-   LOCK_HARDWARE( radeon );
-
-   drmCommandWrite( radeon->dri.fd, DRM_RADEON_STIPPLE,
-        &stipple, sizeof(stipple) );
-   UNLOCK_HARDWARE( radeon );
-}
-
-
 /* ================================================================
  * SwapBuffers with client-side throttling
  */
@@ -452,7 +428,7 @@ static void radeon_flip_renderbuffers(struct radeon_framebuffer *rfb)
 
 /* Copy the back color buffer to the front color buffer.
  */
-void radeonCopyBuffer( __DRIdrawablePrivate *dPriv,
+void radeonCopyBuffer( __DRIdrawable *dPriv,
                       const drm_clip_rect_t      *rect)
 {
        radeonContextPtr rmesa;
@@ -520,7 +496,7 @@ void radeonCopyBuffer( __DRIdrawablePrivate *dPriv,
        UNLOCK_HARDWARE( rmesa );
 }
 
-static int radeonScheduleSwap(__DRIdrawablePrivate *dPriv, GLboolean *missed_target)
+static int radeonScheduleSwap(__DRIdrawable *dPriv, GLboolean *missed_target)
 {
        radeonContextPtr rmesa;
 
@@ -543,11 +519,11 @@ static int radeonScheduleSwap(__DRIdrawablePrivate *dPriv, GLboolean *missed_tar
        return 0;
 }
 
-static GLboolean radeonPageFlip( __DRIdrawablePrivate *dPriv )
+static GLboolean radeonPageFlip( __DRIdrawable *dPriv )
 {
        radeonContextPtr radeon;
        GLint ret;
-       __DRIscreenPrivate *psp;
+       __DRIscreen *psp;
        struct radeon_renderbuffer *rrb;
        struct radeon_framebuffer *rfb;
 
@@ -595,10 +571,10 @@ static GLboolean radeonPageFlip( __DRIdrawablePrivate *dPriv )
 /**
  * Swap front and back buffer.
  */
-void radeonSwapBuffers(__DRIdrawablePrivate * dPriv)
+void radeonSwapBuffers(__DRIdrawable * dPriv)
 {
        int64_t ust;
-       __DRIscreenPrivate *psp;
+       __DRIscreen *psp;
 
        if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
                radeonContextPtr radeon;
@@ -639,7 +615,7 @@ void radeonSwapBuffers(__DRIdrawablePrivate * dPriv)
        }
 }
 
-void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
+void radeonCopySubBuffer(__DRIdrawable * dPriv,
                         int x, int y, int w, int h )
 {
        if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
@@ -665,6 +641,27 @@ void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
        }
 }
 
+/**
+ * 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(GLcontext *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(GLcontext *ctx, struct gl_framebuffer *fb)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
@@ -841,7 +838,7 @@ void radeonDrawBuffer( GLcontext *ctx, GLenum mode )
        */
                if (!was_front_buffer_rendering && radeon->is_front_buffer_rendering) {
                        radeon_update_renderbuffers(radeon->dri.context,
-                               radeon->dri.context->driDrawablePriv);
+                               radeon->dri.context->driDrawablePriv, GL_FALSE);
       }
        }
 
@@ -858,7 +855,7 @@ void radeonReadBuffer( GLcontext *ctx, GLenum mode )
 
                if (!was_front_buffer_reading && rmesa->is_front_buffer_reading) {
                        radeon_update_renderbuffers(rmesa->dri.context,
-                                                   rmesa->dri.context->driReadablePriv);
+                                                   rmesa->dri.context->driReadablePriv, GL_FALSE);
                }
        }
        /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
@@ -909,9 +906,9 @@ void radeon_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei he
                if (radeon->is_front_buffer_rendering) {
                        ctx->Driver.Flush(ctx);
                }
-               radeon_update_renderbuffers(driContext, driContext->driDrawablePriv);
+               radeon_update_renderbuffers(driContext, driContext->driDrawablePriv, GL_FALSE);
                if (driContext->driDrawablePriv != driContext->driReadablePriv)
-                       radeon_update_renderbuffers(driContext, driContext->driReadablePriv);
+                       radeon_update_renderbuffers(driContext, driContext->driReadablePriv, GL_FALSE);
        }
 
        old_viewport = ctx->Driver.Viewport;
@@ -1039,10 +1036,11 @@ static INLINE void radeon_emit_atom(radeonContextPtr radeon, struct radeon_state
                        OUT_BATCH_TABLE(atom->cmd, dwords);
                        END_BATCH();
                }
+               atom->dirty = GL_FALSE;
+
        } else {
                radeon_print(RADEON_STATE, RADEON_VERBOSE, "  skip state %s\n", atom->name);
        }
-       atom->dirty = GL_FALSE;
 
 }
 
@@ -1119,22 +1117,21 @@ void radeonFlush(GLcontext *ctx)
           then no point flushing anything at all.
        */
        if (!radeon->dma.flush && !radeon->cmdbuf.cs->cdw && is_empty_list(&radeon->dma.reserved))
-               return;
+               goto flush_front;
 
        if (radeon->dma.flush)
                radeon->dma.flush( ctx );
 
-       radeonEmitState(radeon);
-
        if (radeon->cmdbuf.cs->cdw)
                rcommonFlushCmdBuf(radeon, __FUNCTION__);
 
+flush_front:
        if ((ctx->DrawBuffer->Name == 0) && radeon->front_buffer_dirty) {
                __DRIscreen *const screen = radeon->radeonScreen->driScreen;
 
                if (screen->dri2.loader && (screen->dri2.loader->base.version >= 2)
                        && (screen->dri2.loader->flushFrontBuffer != NULL)) {
-                       __DRIdrawablePrivate * drawable = radeon_get_drawable(radeon);
+                       __DRIdrawable * drawable = radeon_get_drawable(radeon);
                        (*screen->dri2.loader->flushFrontBuffer)(drawable, drawable->loaderPrivate);
 
                        /* Only clear the dirty bit if front-buffer rendering is no longer
@@ -1148,9 +1145,6 @@ void radeonFlush(GLcontext *ctx)
                        }
                }
        }
-
-       make_empty_list(&radeon->query.not_flushed_head);
-
 }
 
 /* Make sure all commands have been sent to the hardware and have
@@ -1237,7 +1231,7 @@ int rcommonFlushCmdBuf(radeonContextPtr rmesa, const char *caller)
                fprintf(stderr, "drmRadeonCmdBuffer: %d. Kernel failed to "
                                "parse or rejected command stream. See dmesg "
                                "for more info.\n", ret);
-               _mesa_exit(ret);
+               exit(ret);
        }
 
        return ret;
@@ -1331,11 +1325,6 @@ void rcommonBeginBatch(radeonContextPtr rmesa, int n,
                       const char *function,
                       int line)
 {
-       if (!rmesa->cmdbuf.cs->cdw && dostate) {
-               radeon_print(RADEON_STATE, RADEON_NORMAL,
-                               "Reemit state after flush (from %s)\n", function);
-               radeonEmitState(rmesa);
-       }
        radeon_cs_begin(rmesa->cmdbuf.cs, n, file, function, line);
 
     radeon_print(RADEON_CS, RADEON_VERBOSE, "BEGIN_BATCH(%d) at %d, from %s:%i\n",