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

"Henry (Yu) Song - SISA" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <3955FA337689574EB32F94B12A7E6E9E0B18C84B@ex10mail>
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

[email protected]<mailto:[email protected]>

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

--
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.