[cairo] [PATCH 3/3] gl/msaa: Scissor simple rectangular clips
Martin Robinson
mrobinson at igalia.com
Thu Dec 15 11:54:59 PST 2011
Instead of using the stencil buffer to perform simple
rectangular clips, just scissor the clip rectangle.
---
src/cairo-gl-msaa-compositor.c | 68
++++++++++++++++++++++++++++++---------
1 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/src/cairo-gl-msaa-compositor.c b/src/cairo-gl-msaa-compositor.c
index 1f3c006..ceceb15 100644
--- a/src/cairo-gl-msaa-compositor.c
+++ b/src/cairo-gl-msaa-compositor.c
@@ -199,6 +199,49 @@ _draw_clip_to_stencil_buffer (cairo_gl_context_t *ctx,
return status;;
}
+static void
+_scissor_to_box (cairo_gl_surface_t *surface,
+ const cairo_box_t *box)
+{
+ double x = _cairo_fixed_to_double (box->p1.x);
+ double y = _cairo_fixed_to_double (box->p1.y);
+ double width = _cairo_fixed_to_double (box->p2.x) - x;
+ double height = _cairo_fixed_to_double (box->p2.y) - y;
+
+ if (_cairo_gl_surface_is_texture (surface) == FALSE)
+ y = surface->height - (y + height);
+ glScissor (x, y, width, height);
+ glEnable (GL_SCISSOR_TEST);
+}
+
+static cairo_int_status_t
+_scissor_and_clip (cairo_gl_context_t *ctx,
+ cairo_gl_composite_t *setup,
+ cairo_composite_rectangles_t *composite,
+ cairo_bool_t *used_stencil_buffer)
+{
+ cairo_rectangle_int_t *bounds = &composite->unbounded;
+ cairo_clip_t *clip = composite->clip;
+
+ cairo_gl_surface_t *dst = (cairo_gl_surface_t *) composite->surface;
+ *used_stencil_buffer = FALSE;
+
+ if (_cairo_composite_rectangles_can_reduce_clip (composite, clip)) {
+ _scissor_to_rectangle (dst, bounds);
+ return CAIRO_INT_STATUS_SUCCESS;
+ }
+
+ /* If we cannot reduce the clip to a rectangular region,
+ we scissor and clip using the stencil buffer */
+ if (clip->num_boxes > 1 || clip->path != NULL || clip->region !=
NULL) {
+ *used_stencil_buffer = TRUE;
+ _scissor_to_rectangle (dst, bounds);
+ return _draw_clip_to_stencil_buffer (ctx, setup, clip);
+ }
+
+ _scissor_to_box (dst, clip->boxes);
+ return CAIRO_INT_STATUS_SUCCESS;
+}
static cairo_int_status_t
_cairo_gl_msaa_compositor_paint (const cairo_compositor_t *compositor,
cairo_composite_rectangles_t *composite)
@@ -292,14 +335,10 @@ _cairo_gl_msaa_compositor_stroke (const
cairo_compositor_t *compositor,
if (unlikely (status))
goto finish;
- _scissor_to_rectangle (dst, &composite->unbounded);
- if (! _cairo_composite_rectangles_can_reduce_clip (composite,
- composite->clip))
- {
- status = _draw_clip_to_stencil_buffer (info.ctx, &info.setup,
composite->clip);
- if (unlikely (status))
- goto finish;
- }
+ status = _scissor_and_clip (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,
@@ -340,6 +379,7 @@ _cairo_gl_msaa_compositor_fill (const
cairo_compositor_t *compositor,
cairo_gl_context_t *ctx = NULL;
cairo_int_status_t status;
cairo_traps_t traps;
+ cairo_bool_t used_stencil_buffer;
if (antialias != CAIRO_ANTIALIAS_NONE)
return CAIRO_INT_STATUS_UNSUPPORTED;
@@ -368,14 +408,10 @@ _cairo_gl_msaa_compositor_fill (const
cairo_compositor_t *compositor,
if (unlikely (status))
goto cleanup_setup;
- _scissor_to_rectangle (dst, &composite->unbounded);
- if (! _cairo_composite_rectangles_can_reduce_clip (composite,
- composite->clip))
- {
- status = _draw_clip_to_stencil_buffer (ctx, &setup, composite->clip);
- if (unlikely (status))
- goto cleanup_setup;
- }
+ status = _scissor_and_clip (ctx, &setup, composite,
+ &used_stencil_buffer);
+ if (unlikely (status))
+ goto cleanup_setup;
status = _draw_traps (ctx, &setup, &traps);
if (unlikely (status))
--
1.7.5.4
More information about the cairo
mailing list