[cairo] [PATCH 1/3] gl/msaa: Prevent stroke overlap

Henry (Yu) Song - SISA hsong at sisa.samsung.com
Mon Oct 17 07:56:10 PDT 2011


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.
---
src/cairo-gl-msaa-compositor.c |   26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/cairo-gl-msaa-compositor.c b/src/cairo-gl-msaa-compositor.c
index 7a0e828..01ef40f 100644
--- a/src/cairo-gl-msaa-compositor.c
+++ b/src/cairo-gl-msaa-compositor.c
@@ -247,6 +247,27 @@ _stroke_shaper_add_quad (void                *closure,
                                         quad);
}
+static void
+_prevent_overlapping_drawing (cairo_clip_t     *clip,
+                       cairo_bool_t      used_stencil_buffer_for_clip)
+{
+   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);
+}
+
static cairo_int_status_t
_cairo_gl_msaa_compositor_stroke (const cairo_compositor_t *compositor,
                         cairo_composite_rectangles_t      *composite,
@@ -261,6 +282,8 @@ _cairo_gl_msaa_compositor_stroke (const cairo_compositor_t      *compositor,
     cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface;
     struct _tristrip_composite_info info;
+    cairo_bool_t used_stencil_buffer_for_clip = FALSE;
+
     if (antialias != CAIRO_ANTIALIAS_NONE)
     return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -296,11 +319,14 @@ _cairo_gl_msaa_compositor_stroke (const cairo_compositor_t      *compositor,
     if (! _cairo_composite_rectangles_can_reduce_clip (composite,
                                          composite->clip))
     {
+     used_stencil_buffer_for_clip = TRUE;
     status = _draw_clip_to_stencil_buffer (info.ctx, &info.setup, composite->clip);
     if (unlikely (status))
         goto finish;
     }
+    _prevent_overlapping_drawing (composite->clip, used_stencil_buffer_for_clip);
+
     status = _cairo_path_fixed_stroke_to_shaper ((cairo_path_fixed_t *) path,
                                    style,
                                    ctm,
--
1.7.4.1


--

cairo mailing list

cairo at cairographics.org<mailto:cairo at cairographics.org>

http://lists.cairographics.org/mailman/listinfo/cairo



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20111017/8bc09189/attachment.htm>


More information about the cairo mailing list