[cairo-commit] src/cairo-gl-msaa-compositor.c

Martin Robinson mrobinson at kemper.freedesktop.org
Tue May 8 11:41:23 PDT 2012


 src/cairo-gl-msaa-compositor.c |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

New commits:
commit a60bb83f28a27c065f21f6a8466408df4565a0b1
Author: Henry (Yu) Song <hsong at sisa.samsung.com>
Date:   Tue Oct 11 09:08:38 2011 -0700

    gl/msaa: Prevent stroke overlap
    
    When stroking we do not send our polygon to the tessellator, so
    it may have overlapping stroke components. Use the stencil buffer
    to prevent stroke components from overlapping.

diff --git a/src/cairo-gl-msaa-compositor.c b/src/cairo-gl-msaa-compositor.c
index f88d354..2b9adb4 100644
--- a/src/cairo-gl-msaa-compositor.c
+++ b/src/cairo-gl-msaa-compositor.c
@@ -298,6 +298,37 @@ _stroke_shaper_add_quad (void			*closure,
 }
 
 static cairo_int_status_t
+_prevent_overlapping_drawing (cairo_gl_context_t *ctx,
+			      cairo_gl_composite_t *setup,
+			      cairo_composite_rectangles_t *composite,
+			      cairo_bool_t used_stencil_buffer_for_clip)
+{
+    if (! _cairo_gl_ensure_stencil (ctx, setup->dst))
+	return CAIRO_INT_STATUS_UNSUPPORTED;
+
+    if (_cairo_pattern_is_opaque (&composite->source_pattern.base,
+				  &composite->source_sample_area))
+	return CAIRO_INT_STATUS_SUCCESS;
+
+   if (used_stencil_buffer_for_clip == FALSE) {
+	/* Enable the stencil buffer, even if we have no clip so that
+	   we can use it below to prevent overlapping shapes. We initialize
+	   it all to one here which represents infinite clip. */
+	glDepthMask (GL_TRUE);
+	glEnable (GL_STENCIL_TEST);
+	glClearStencil (1);
+	glClear (GL_STENCIL_BUFFER_BIT);
+	glStencilFunc (GL_EQUAL, 1, 1);
+    }
+
+    /* This means that once we draw to a particular pixel nothing else can
+       be drawn there until the stencil buffer is reset or the stencil test
+       is disabled. */
+    glStencilOp (GL_ZERO, GL_ZERO, GL_ZERO);
+    return CAIRO_INT_STATUS_SUCCESS;
+}
+
+static cairo_int_status_t
 _cairo_gl_msaa_compositor_stroke (const cairo_compositor_t	*compositor,
 				  cairo_composite_rectangles_t	*composite,
 				  const cairo_path_fixed_t	*path,
@@ -340,6 +371,11 @@ _cairo_gl_msaa_compositor_stroke (const cairo_compositor_t	*compositor,
     if (unlikely (status))
 	goto finish;
 
+    status = _prevent_overlapping_drawing (info.ctx, &info.setup, composite,
+					   used_stencil_buffer_for_clip);
+    if (unlikely (status))
+	goto finish;
+
     status = _cairo_path_fixed_stroke_to_shaper ((cairo_path_fixed_t *) path,
 						 style,
 						 ctm,


More information about the cairo-commit mailing list