[cairo-commit] 2 commits - src/cairo-gl-composite.c src/cairo-gl-msaa-compositor.c src/cairo-gl-private.h

Martin Robinson mrobinson at kemper.freedesktop.org
Wed Jan 9 14:57:34 PST 2013


 src/cairo-gl-composite.c       |   58 ++++++++++++++++++++++++++++-------------
 src/cairo-gl-msaa-compositor.c |    5 ++-
 src/cairo-gl-private.h         |    1 
 3 files changed, 46 insertions(+), 18 deletions(-)

New commits:
commit 1bcd59ef4c9dceaefa51ec6db1f5240d75940724
Author: Martin Robinson <mrobinson at igalia.com>
Date:   Wed Jan 9 14:16:59 2013 -0800

    gl/msaa: Rely on the stencil buffer to cache the clip
    
    When using a texture surface the depth/stencil buffer is private to
    cairo so we can rely on the fact that any previously painted clip is
    still valid.
    
    We also only scissor when there's a previously painted clip on the
    stencil buffer, otherwise we disable the scissor test. This fixes a few
    test cases.

diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 486ab60..de45028 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -563,10 +563,22 @@ _cairo_gl_composite_setup_painted_clipping (cairo_gl_composite_t *setup,
     /* The clip is not rectangular, so use the stencil buffer. */
     glDepthMask (GL_TRUE);
     glEnable (GL_STENCIL_TEST);
+    glDisable (GL_SCISSOR_TEST);
+
+    /* Texture surfaces have private depth/stencil buffers, so we can
+     * rely on any previous clip being cached there. */
+    if (_cairo_gl_surface_is_texture (setup->dst)) {
+	cairo_clip_t *old_clip = setup->dst->clip_on_stencil_buffer;
+	if (_cairo_clip_equal (old_clip, setup->clip))
+	    goto activate_stencil_buffer_and_return;
+
+      /* Clear the stencil buffer, but only the areas that we are
+       * going to be drawing to. */
+	if (old_clip)
+	    _cairo_gl_scissor_to_rectangle (dst, _cairo_clip_get_extents (old_clip));
+	setup->dst->clip_on_stencil_buffer = _cairo_clip_copy (setup->clip);
+    }
 
-    /* Clear the stencil buffer, but only the areas that we are
-     * going to be drawing to. */
-    _cairo_gl_scissor_to_rectangle (dst, _cairo_clip_get_extents (clip));
     glClearStencil (0);
     glClear (GL_STENCIL_BUFFER_BIT);
     glDisable (GL_SCISSOR_TEST);
@@ -588,6 +600,7 @@ _cairo_gl_composite_setup_painted_clipping (cairo_gl_composite_t *setup,
     _cairo_gl_composite_flush (ctx);
     _cairo_gl_composite_setup_vbo (ctx, vertex_size);
 
+activate_stencil_buffer_and_return:
     glColorMask (1, 1, 1, 1);
     glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
     glStencilFunc (GL_EQUAL, 1, 0xffffffff);
@@ -603,29 +616,40 @@ _cairo_gl_composite_setup_clipping (cairo_gl_composite_t *setup,
 				    cairo_gl_context_t *ctx,
 				    int vertex_size)
 {
+    cairo_bool_t clip_changing = TRUE;
+    cairo_bool_t clip_region_changing = TRUE;
+
+    if (! ctx->clip && ! setup->clip && ! setup->clip_region && ! ctx->clip_region)
+	goto disable_all_clipping;
 
+    clip_changing = ! _cairo_clip_equal (ctx->clip, setup->clip);
+    clip_region_changing = ! cairo_region_equal (ctx->clip_region, setup->clip_region);
     if (! _cairo_gl_context_is_flushed (ctx) &&
-	(! cairo_region_equal (ctx->clip_region, setup->clip_region) ||
-	 ! _cairo_clip_equal (ctx->clip, setup->clip)))
+	(clip_region_changing || clip_changing))
 	_cairo_gl_composite_flush (ctx);
 
-    cairo_region_destroy (ctx->clip_region);
-    ctx->clip_region = cairo_region_reference (setup->clip_region);
-    _cairo_clip_destroy (ctx->clip);
-    ctx->clip = _cairo_clip_copy (setup->clip);
-
     assert (!setup->clip_region || !setup->clip);
 
-    if (ctx->clip_region) {
-	_disable_stencil_buffer ();
-	glEnable (GL_SCISSOR_TEST);
-	return CAIRO_INT_STATUS_SUCCESS;
+    /* setup->clip is only used by the msaa compositor and setup->clip_region
+     * only by the other compositors, so it's safe to wait to clean up obsolete
+     * clips. */
+    if (clip_region_changing) {
+	cairo_region_destroy (ctx->clip_region);
+	ctx->clip_region = cairo_region_reference (setup->clip_region);
+    }
+    if (clip_changing) {
+	_cairo_clip_destroy (ctx->clip);
+	ctx->clip = _cairo_clip_copy (setup->clip);
     }
 
-    if (ctx->clip)
-	return _cairo_gl_composite_setup_painted_clipping (setup, ctx,
-							   vertex_size);
+    /* For clip regions, we scissor right before drawing. */
+    if (setup->clip_region)
+	goto disable_all_clipping;
 
+    if (setup->clip)
+	return _cairo_gl_composite_setup_painted_clipping (setup, ctx,
+                                                           vertex_size);
+disable_all_clipping:
     _disable_stencil_buffer ();
     glDisable (GL_SCISSOR_TEST);
     return CAIRO_INT_STATUS_SUCCESS;
diff --git a/src/cairo-gl-msaa-compositor.c b/src/cairo-gl-msaa-compositor.c
index ca9fe22..5773733 100644
--- a/src/cairo-gl-msaa-compositor.c
+++ b/src/cairo-gl-msaa-compositor.c
@@ -583,6 +583,10 @@ _prevent_overlapping_strokes (cairo_gl_context_t 		*ctx,
        be drawn there until the stencil buffer is reset or the stencil test
        is disabled. */
     glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO);
+
+    _cairo_clip_destroy (setup->dst->clip_on_stencil_buffer);
+    setup->dst->clip_on_stencil_buffer = NULL;
+
     return CAIRO_INT_STATUS_SUCCESS;
 }
 
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 1da5084..9366309 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -177,6 +177,7 @@ struct _cairo_gl_surface {
     cairo_bool_t supports_msaa;
     cairo_bool_t msaa_active; /* Whether the multisampling
 			         framebuffer is active or not. */
+    cairo_clip_t *clip_on_stencil_buffer;
 
     int owns_tex;
     cairo_bool_t needs_update;
commit d524697ede85d36e4f88fa44d6a8b884685d804b
Author: Martin Robinson <mrobinson at igalia.com>
Date:   Tue Jan 8 17:08:52 2013 -0800

    gl/msaa: No need to set the clip when masking
    
    After 5e9083f882859201c5df18fc870577a224f88cbb there's no need to set a
    clip on the cairo_gl_composite_t when masking. Clips are converted to
    traps and rendered directly when masking now.

diff --git a/src/cairo-gl-msaa-compositor.c b/src/cairo-gl-msaa-compositor.c
index 4d7ab62..ca9fe22 100644
--- a/src/cairo-gl-msaa-compositor.c
+++ b/src/cairo-gl-msaa-compositor.c
@@ -343,7 +343,6 @@ _cairo_gl_msaa_compositor_mask_source_operator (const cairo_compositor_t *compos
 					     &composite->bounded);
     if (unlikely (status))
 	goto finish;
-    _cairo_gl_composite_set_clip (&setup, composite->clip);
     _cairo_gl_composite_set_multisample (&setup);
     status = _cairo_gl_composite_begin (&setup, &ctx);
     if (unlikely (status))


More information about the cairo-commit mailing list