Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common.c
index 2a2b16a54bd2bba0b9f2744f92ff157e3e6fd37f..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) {
@@ -428,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;
@@ -496,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;
 
@@ -519,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;
 
@@ -571,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;
@@ -615,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;
@@ -646,7 +650,7 @@ void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
  * If so, set the intel->front_buffer_dirty field to true.
  */
 void
-radeon_check_front_buffer_rendering(GLcontext *ctx)
+radeon_check_front_buffer_rendering(struct gl_context *ctx)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        const struct gl_framebuffer *fb = ctx->DrawBuffer;
@@ -662,7 +666,7 @@ radeon_check_front_buffer_rendering(GLcontext *ctx)
 }
 
 
-void radeon_draw_buffer(GLcontext *ctx, struct gl_framebuffer *fb)
+void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        struct radeon_renderbuffer *rrbDepth = NULL, *rrbStencil = NULL,
@@ -708,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;
@@ -818,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__,
@@ -845,7 +848,7 @@ void radeonDrawBuffer( GLcontext *ctx, GLenum mode )
        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);
@@ -892,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)
@@ -1036,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;
 
 }
 
@@ -1064,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;
@@ -1104,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)
@@ -1130,18 +1134,14 @@ flush_front:
 
                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);
                }
        }
 }
@@ -1149,7 +1149,7 @@ flush_front:
 /* 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;
@@ -1230,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;
@@ -1324,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",
@@ -1336,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);
 }