[cairo-commit] src/cairo-gl-device.c src/cairo-gl-msaa-compositor.c src/cairo-gl-operand.c src/cairo-gl-private.h src/cairo-gl-surface.c

Martin Robinson mrobinson at kemper.freedesktop.org
Thu May 17 13:21:55 PDT 2012


 src/cairo-gl-device.c          |    8 ++++++++
 src/cairo-gl-msaa-compositor.c |   40 ++++++++++++++++++++++++++++++++++++++++
 src/cairo-gl-operand.c         |    3 +++
 src/cairo-gl-private.h         |    2 ++
 src/cairo-gl-surface.c         |    5 +----
 5 files changed, 54 insertions(+), 4 deletions(-)

New commits:
commit 29b243325c0af760249a414bdce2e6afb64186a7
Author: Martin Robinson <mrobinson at igalia.com>
Date:   Mon Jan 23 13:07:59 2012 -0800

    gl/msaa: Support for non-texture surfaces
    
    Add full support for non-texture surfaces, by correctly
    querying primitives for stencil and multisample bits.

diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index 7400107..ffa4b04 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -679,6 +679,14 @@ _cairo_gl_context_set_destination (cairo_gl_context_t *ctx,
 	}
     } else {
         ctx->make_current (ctx, surface);
+
+#if CAIRO_HAS_GL_SURFACE
+	if (multisampling)
+	    glEnable(GL_MULTISAMPLE);
+	else
+	    glDisable(GL_MULTISAMPLE);
+#endif
+
         ctx->dispatch.BindFramebuffer (GL_FRAMEBUFFER, 0);
 
 #if CAIRO_HAS_GL_SURFACE
diff --git a/src/cairo-gl-msaa-compositor.c b/src/cairo-gl-msaa-compositor.c
index 6a12200..59cb1e3 100644
--- a/src/cairo-gl-msaa-compositor.c
+++ b/src/cairo-gl-msaa-compositor.c
@@ -55,6 +55,9 @@ static cairo_bool_t
 should_fall_back (cairo_gl_surface_t *surface,
 		  cairo_antialias_t antialias);
 
+static void
+query_surface_capabilities (cairo_gl_surface_t *surface);
+
 struct _tristrip_composite_info {
     cairo_gl_composite_t	setup;
     cairo_gl_context_t		*ctx;
@@ -343,6 +346,10 @@ static cairo_bool_t
 should_fall_back (cairo_gl_surface_t *surface,
 		  cairo_antialias_t antialias)
 {
+    query_surface_capabilities (surface);
+    if (! surface->supports_stencil)
+	return TRUE;
+
     /* Multisampling OpenGL ES surfaces only maintain one multisampling
        framebuffer and thus must use the spans compositor to do non-antialiased
        rendering. */
@@ -533,6 +540,39 @@ _prevent_overlapping_drawing (cairo_gl_context_t *ctx,
     return CAIRO_INT_STATUS_SUCCESS;
 }
 
+static void
+query_surface_capabilities (cairo_gl_surface_t *surface)
+{
+    GLint samples, stencil_bits;
+    cairo_gl_context_t *ctx;
+    cairo_int_status_t status;
+
+    /* Texture surfaces are create in such a way that they always
+       have stencil and multisample bits if possible, so we don't
+       need to query their capabilities lazily. */
+    if (_cairo_gl_surface_is_texture (surface))
+	return;
+    if (surface->stencil_and_msaa_caps_initialized)
+	return;
+
+    surface->stencil_and_msaa_caps_initialized = TRUE;
+    surface->supports_stencil = FALSE;
+    surface->supports_msaa = FALSE;
+
+    status = _cairo_gl_context_acquire (surface->base.device, &ctx);
+    if (unlikely (status))
+	return;
+
+    _cairo_gl_context_set_destination (ctx, surface, FALSE);
+
+    glGetIntegerv(GL_SAMPLES, &samples);
+    glGetIntegerv(GL_STENCIL_BITS, &stencil_bits);
+    surface->supports_stencil = stencil_bits > 0;
+    surface->supports_msaa = samples > 1;
+
+    status = _cairo_gl_context_release (ctx, status);
+}
+
 static cairo_int_status_t
 _cairo_gl_msaa_compositor_stroke (const cairo_compositor_t	*compositor,
 				  cairo_composite_rectangles_t	*composite,
diff --git a/src/cairo-gl-operand.c b/src/cairo-gl-operand.c
index 000b32b..1c7ad2f 100644
--- a/src/cairo-gl-operand.c
+++ b/src/cairo-gl-operand.c
@@ -85,6 +85,9 @@ _resolve_multisampling (cairo_gl_surface_t *surface)
     if (((cairo_gl_context_t *) surface->base.device)->gl_flavor == CAIRO_GL_FLAVOR_ES)
 	return CAIRO_INT_STATUS_SUCCESS;
 
+    if (! _cairo_gl_surface_is_texture (surface))
+	return CAIRO_INT_STATUS_SUCCESS;
+
     status = _cairo_gl_context_acquire (surface->base.device, &ctx);
     if (unlikely (status))
 	return status;
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 21aad24..16353de 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -170,6 +170,8 @@ struct _cairo_gl_surface {
 #endif
     GLuint msaa_depth_stencil;
 
+    cairo_bool_t stencil_and_msaa_caps_initialized;
+    cairo_bool_t supports_stencil; /* Stencil support for for non-texture surfaces. */
     cairo_bool_t supports_msaa;
     cairo_bool_t msaa_active; /* Whether the multisampling
 			         framebuffer is active or not. */
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 9b8cf27..c2e9687 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -392,10 +392,6 @@ _cairo_gl_surface_init (cairo_device_t *device,
     surface->height = height;
     surface->needs_update = FALSE;
 
-    /* Support for multisampling in non-texture surfaces is still spotty. */
-    surface->supports_msaa = FALSE;
-    surface->msaa_active = FALSE;
-
     _cairo_gl_surface_embedded_operand_init (surface);
 }
 
@@ -417,6 +413,7 @@ _cairo_gl_surface_create_scratch_for_texture (cairo_gl_context_t   *ctx,
     _cairo_gl_surface_init (&ctx->base, surface, content, width, height);
 
     surface->supports_msaa = ctx->supports_msaa;
+    surface->supports_stencil = TRUE;
 
     /* Create the texture used to store the surface's data. */
     _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP);


More information about the cairo-commit mailing list