Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common.c
index 097ab7cf6136f358d8d2ae02a5d13167f760c3d1..7361adffcf7f60ad8501955813ed612afe7c83da 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,12 @@ 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);
+
+       if(drawable == NULL && readable == NULL)
+               return;
+
        struct radeon_framebuffer *const draw_rfb = drawable->driverPrivate;
        struct radeon_framebuffer *const read_rfb = readable->driverPrivate;
        int x_off, y_off;
@@ -201,7 +205,7 @@ void radeonSetCliprects(radeonContextPtr radeon)
 
 
 
-void radeonUpdateScissor( GLcontext *ctx )
+void radeonUpdateScissor( struct gl_context *ctx )
 {
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
        GLint x = ctx->Scissor.X, y = ctx->Scissor.Y;
@@ -229,7 +233,7 @@ 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 + 1;
           min_x += dPriv->x;
@@ -252,7 +256,7 @@ void radeonUpdateScissor( GLcontext *ctx )
  * Scissoring
  */
 
-void radeonScissor(GLcontext* ctx, GLint x, GLint y, GLsizei w, GLsizei h)
+void radeonScissor(struct gl_context* ctx, GLint x, GLint y, GLsizei w, GLsizei h)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        if (ctx->Scissor.Enabled) {
@@ -262,29 +266,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
  */
@@ -451,7 +432,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;
@@ -519,7 +500,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;
 
@@ -542,11 +523,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;
 
@@ -594,14 +575,14 @@ 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;
-               GLcontext *ctx;
+               struct gl_context *ctx;
 
                radeon = (radeonContextPtr) dPriv->driContextPriv->driverPrivate;
                ctx = radeon->glCtx;
@@ -638,12 +619,12 @@ 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) {
                radeonContextPtr radeon;
-               GLcontext *ctx;
+               struct gl_context *ctx;
 
                radeon = (radeonContextPtr) dPriv->driContextPriv->driverPrivate;
                ctx = radeon->glCtx;
@@ -664,7 +645,28 @@ void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
        }
 }
 
-void radeon_draw_buffer(GLcontext *ctx, struct gl_framebuffer *fb)
+/**
+ * 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);
        struct radeon_renderbuffer *rrbDepth = NULL, *rrbStencil = NULL,
@@ -710,7 +712,6 @@ void radeon_draw_buffer(GLcontext *ctx, struct gl_framebuffer *fb)
                if (fb->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT) {
                        rrbColor = radeon_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
                        radeon->front_cliprects = GL_TRUE;
-                       radeon->front_buffer_dirty = GL_TRUE;
                } else {
                        rrbColor = radeon_renderbuffer(fb->Attachment[BUFFER_BACK_LEFT].Renderbuffer);
                        radeon->front_cliprects = GL_FALSE;
@@ -820,7 +821,7 @@ void radeon_draw_buffer(GLcontext *ctx, struct gl_framebuffer *fb)
 /**
  * Called via glDrawBuffer.
  */
-void radeonDrawBuffer( GLcontext *ctx, GLenum mode )
+void radeonDrawBuffer( struct gl_context *ctx, GLenum mode )
 {
        if (RADEON_DEBUG & RADEON_DRI)
                fprintf(stderr, "%s %s\n", __FUNCTION__,
@@ -840,14 +841,14 @@ 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);
       }
        }
 
        radeon_draw_buffer(ctx, ctx->DrawBuffer);
 }
 
-void radeonReadBuffer( GLcontext *ctx, GLenum mode )
+void radeonReadBuffer( struct gl_context *ctx, GLenum mode )
 {
        if ((ctx->DrawBuffer != NULL) && (ctx->DrawBuffer->Name == 0)) {
                struct radeon_context *const rmesa = RADEON_CONTEXT(ctx);
@@ -857,7 +858,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 */
@@ -894,11 +895,11 @@ void radeon_window_moved(radeonContextPtr radeon)
        }
 }
 
-void radeon_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height)
+void radeon_viewport(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        __DRIcontext *driContext = radeon->dri.context;
-       void (*old_viewport)(GLcontext *ctx, GLint x, GLint y,
+       void (*old_viewport)(struct gl_context *ctx, GLint x, GLint y,
                             GLsizei w, GLsizei h);
 
        if (!driContext->driScreenPriv->dri2.enabled)
@@ -908,9 +909,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;
@@ -1038,10 +1039,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;
 
 }
 
@@ -1066,7 +1068,7 @@ static INLINE void radeonEmitAtoms(radeonContextPtr radeon, GLboolean emitAll)
        COMMIT_BATCH();
 }
 
-static GLboolean radeon_revalidate_bos(GLcontext *ctx)
+static GLboolean radeon_revalidate_bos(struct gl_context *ctx)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        int ret;
@@ -1106,7 +1108,7 @@ void radeonEmitState(radeonContextPtr radeon)
 }
 
 
-void radeonFlush(GLcontext *ctx)
+void radeonFlush(struct gl_context *ctx)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        if (RADEON_DEBUG & RADEON_IOCTL)
@@ -1118,44 +1120,36 @@ 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);
-                       (*screen->dri2.loader->flushFrontBuffer)(drawable, drawable->loaderPrivate);
+                       __DRIdrawable * drawable = radeon_get_drawable(radeon);
 
-                       /* Only clear the dirty bit if front-buffer rendering is no longer
-                        * enabled.  This is done so that the dirty bit can only be set in
-                        * glDrawBuffer.  Otherwise the dirty bit would have to be set at
-                        * each of N places that do rendering.  This has worse performances,
-                        * but it is much easier to get correct.
+                       /* We set the dirty bit in radeon_prepare_render() if we're
+                        * front buffer rendering once we get there.
                         */
-                       if (!radeon->is_front_buffer_rendering) {
-                               radeon->front_buffer_dirty = GL_FALSE;
-                       }
+                       radeon->front_buffer_dirty = GL_FALSE;
+
+                       (*screen->dri2.loader->flushFrontBuffer)(drawable, drawable->loaderPrivate);
                }
        }
-
-       make_empty_list(&radeon->query.not_flushed_head);
-
 }
 
 /* Make sure all commands have been sent to the hardware and have
  * completed processing.
  */
-void radeonFinish(GLcontext * ctx)
+void radeonFinish(struct gl_context * ctx)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        struct gl_framebuffer *fb = ctx->DrawBuffer;
@@ -1236,7 +1230,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;
@@ -1330,11 +1324,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",
@@ -1342,7 +1331,7 @@ void rcommonBeginBatch(radeonContextPtr rmesa, int n,
 
 }
 
-void radeonUserClear(GLcontext *ctx, GLuint mask)
+void radeonUserClear(struct gl_context *ctx, GLuint mask)
 {
    _mesa_meta_Clear(ctx, mask);
 }