[cairo] [PATCH 1/3] gl/msaa: Prevent stroke overlap
Henry Song
henry.song at samsung.com
Tue Oct 18 14:51:17 PDT 2011
Thanks for suggestions. We have plan to optimize this and also use stencil buffer as cache in the upcoming patches. Using Stencil buffer is expensive.
1. When stroke is of constant color and alpha == 1.0, we don't need this overlapping on stencil buffer.
2. We keep a tessellated clip path in cache. If current clip and cached clip is same, we reuse stencil buffer image.
Thanks
Henry
From: Taekyun Kim <podain77 at gmail.com>
Date: Mon, Oct 17, 2011 at 11:12 PM
Subject: Re: [cairo] [PATCH 1/3] gl/msaa: Prevent stroke overlap
To: "Henry (Yu) Song - SISA" <hsong at sisa.samsung.com>
Cc: cairo at cairographics.org
We can avoid using stencil test for cases where drawing twice will
produce same result.
For example, opaque solid source with op OVER.
Clearing entire stencil buffer for every stroke might be quite
expensive for most of drivers
and GPUs. It would be good to restrict clearing area within bounded rectangle.
And have you measured the effect of glColorMask() in clipping code?
AFAIK, it was extremely expensive. (But I didn't measure it with
recent GPUs and drivers.)
Here's my suggestion.
if (! used_stencil_buffer_for_clip) {
glStencilFunc (GL_NEVER, ...); // Nothing will be drawn to the color buffer
glStencilOp (GL_ONE, GL_ONE, GL_ONE);
drawBoundedRectangle (); // Stroke extent
}
One last thing is that you consumes stencil buffer to prevent overlap
thus it would be hard
to cache stencil buffer for a clip.
On 10/17/2011 11:56 PM, Henry (Yu) Song - SISA wrote:
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
http://lists.cairographics.org/mailman/listinfo/cairo
--
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
--
cairo mailing list
cairo at cairographics.org
http://lists.cairographics.org/mailman/listinfo/cairo
More information about the cairo
mailing list