<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <small>We can avoid using stencil test for cases where drawing twice
      will produce same result.<br>
      For example, opaque solid source with op OVER.<br>
      <br>
      Clearing entire stencil buffer for every stroke might be quite
      expensive for most of drivers<br>
      and GPUs. It would be good to restrict clearing area within
      bounded rectangle.<br>
      <br>
      And have you measured the effect of glColorMask() in clipping
      code?<br>
      AFAIK, it was extremely expensive. (But I didn't measure it with
      recent GPUs and drivers.)<br>
      <br>
      Here's my suggestion.<br>
      <br>
      if (! used_stencil_buffer_for_clip) {<br>
    </small><small>&nbsp;&nbsp;&nbsp; glStencilFunc (GL_NEVER, ...); // Nothing will be
      drawn to the color buffer<br>
      &nbsp;&nbsp;&nbsp; glStencilOp (GL_ONE, GL_ONE, GL_ONE)</small>;<br>
    <small>&nbsp;&nbsp;&nbsp; drawBoundedRectangle (); // Stroke extent</small><br>
    <small>}<br>
      <br>
      One last thing is that you consumes stencil buffer to prevent
      overlap thus it would be hard<br>
      to cache stencil buffer for a clip.<br>
      <br>
    </small>On 10/17/2011 11:56 PM, Henry (Yu) Song - SISA wrote:
    <blockquote
      cite="mid:3955FA337689574EB32F94B12A7E6E9E0B18C84B@ex10mail"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 12 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.5pt;
        font-family:Consolas;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:Consolas;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">When stroking we do
            not send our polygon to the tessellator, so<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">it may have
            overlapping stroke components. Use the stencil buffer<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">to prevent stroke
            components from overlapping.<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">---<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">src/cairo-gl-msaa-compositor.c
            |&nbsp;&nbsp; 26 ++++++++++++++++++++++++++<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">1 files changed, 26
            insertions(+), 0 deletions(-)<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">diff --git
            a/src/cairo-gl-msaa-compositor.c
            b/src/cairo-gl-msaa-compositor.c<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">index
            7a0e828..01ef40f 100644<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">---
            a/src/cairo-gl-msaa-compositor.c<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+++
            b/src/cairo-gl-msaa-compositor.c<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">@@ -247,6 +247,27 @@
            _stroke_shaper_add_quad (void&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *closure,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;quad);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">}<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+static void<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+_prevent_overlapping_drawing
            (cairo_clip_t&nbsp;&nbsp;&nbsp;&nbsp; *clip,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cairo_bool_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; used_stencil_buffer_for_clip)<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+{<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp; if
            (used_stencil_buffer_for_clip == FALSE) {<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; /* Enable the
            stencil buffer, even if we have no clip so that<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; we can use
            it below to prevent overlapping shapes. We initialize<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; it all to
            one here which represents infinite clip. */<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; glDepthMask
            (GL_TRUE);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; glEnable
            (GL_STENCIL_TEST);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp;
            glClearStencil(1);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; glClear
            (GL_STENCIL_BUFFER_BIT);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp; glStencilFunc
            (GL_EQUAL, 1, 1);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp; /* This means
            that once we draw to a particular pixel nothing else can<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; be drawn
            there until the stencil buffer is reset or the stencil test<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; is disabled.
            */<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp; glStencilOp
            (GL_ZERO, GL_ZERO, GL_ZERO);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+}<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">static
            cairo_int_status_t<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">_cairo_gl_msaa_compositor_stroke
            (const cairo_compositor_t *compositor,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;cairo_composite_rectangles_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *composite,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">@@ -261,6 +282,8 @@
            _cairo_gl_msaa_compositor_stroke (const
            cairo_compositor_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *compositor,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;
            cairo_gl_surface_t *dst = (cairo_gl_surface_t *)
            composite-&gt;surface;<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; struct
            _tristrip_composite_info info;<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp; cairo_bool_t
            used_stencil_buffer_for_clip = FALSE;<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; if (antialias !=
            CAIRO_ANTIALIAS_NONE)<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; return
            CAIRO_INT_STATUS_UNSUPPORTED;<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">@@ -296,11 +319,14 @@
            _cairo_gl_msaa_compositor_stroke (const
            cairo_compositor_t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *compositor,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; if (!
            _cairo_composite_rectangles_can_reduce_clip (composite,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;composite-&gt;clip))<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; {<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;&nbsp;
            used_stencil_buffer_for_clip = TRUE;<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; status =
            _draw_clip_to_stencil_buffer (info.ctx, &amp;info.setup,
            composite-&gt;clip);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; if (unlikely
            (status))<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;goto finish;<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; }<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+&nbsp;&nbsp;&nbsp;
            _prevent_overlapping_drawing (composite-&gt;clip,
            used_stencil_buffer_for_clip);<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">+<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp; status =
            _cairo_path_fixed_stroke_to_shaper ((cairo_path_fixed_t *)
            path,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;style,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;ctm,<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">--
            <o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;">1.7.4.1<o:p></o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoPlainText">--<o:p></o:p></p>
        <p class="MsoPlainText">cairo mailing list<o:p></o:p></p>
        <p class="MsoPlainText"><a moz-do-not-send="true"
            href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><o:p></o:p></p>
        <p class="MsoPlainText"><a moz-do-not-send="true"
            href="http://lists.cairographics.org/mailman/listinfo/cairo">http://lists.cairographics.org/mailman/listinfo/cairo</a><o:p></o:p></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal" style=""><span style="font-size: 10pt;
            font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></p>
        <p class="MsoNormal"><o:p>&nbsp;</o:p></p>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
--
cairo mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cairo@cairographics.org">cairo@cairographics.org</a>
<a class="moz-txt-link-freetext" href="http://lists.cairographics.org/mailman/listinfo/cairo">http://lists.cairographics.org/mailman/listinfo/cairo</a></pre>
    </blockquote>
    <br>
  </body>
</html>