summaryrefslogtreecommitdiff
path: root/src/cairo-default-context.c
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2011-07-21 12:15:05 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2011-10-11 09:05:45 +0100
commit571a27b4fcfe11fec2b33c31525c353eb30c0ad7 (patch)
tree9b338440d2f1366e585a10e6da1b869ce7469772 /src/cairo-default-context.c
parent5783bbfc750c73a4b36ad30a054de59a7ee99f34 (diff)
downloadcairo-571a27b4fcfe11fec2b33c31525c353eb30c0ad7.tar.gz
backends: Adds a new Cogl based backend
This adds a new GPU accelerated backend for Cairo based on the Cogl 3D graphics API. This backend aims to support Cairo in a way that translates as naturally as possible to using a GPU, it does not strive to compete with the anti-aliasing quality of the image backend if it can't be done efficiently using the GPU - raw performance isn't the only metric of concern, so is power usage. As an overview of how the backend works: - fills are handled by tessellating paths into triangles - the backend has an extra fill_rectangle drawing operation so we have a fast-path for drawing rectangles which are so common. - strokes are also tessellated into triangles. - stroke and fill tessellations are cached to avoid the cpu overhead of tessellation and cost of upload given that its common for apps to re-draw the same path multiple times. The tessellations can survive translations and rotations increasing the probability that they can be re-used. - sources and masks are handled using multi-texturing. - clipping is handled with a scissor and the stencil buffer which we're careful to only update when they really change. - linear gradients are rendered to a 1d texture using a triangle strip + interpolating color attributes. All cairo extend modes are handled by corresponding texture sampler wrap modes without needing programmable fragment processing. - antialiasing should be handled using Cogl's multisampling API XXX: This is a work in progress!! TODO: - handle at least basic radial gradients (No need to handle full pdf semantics, since css, svg and canvas only allow radial gradients defined as one circle + a point that must lie within the first circle.) - currently we fall back to pixman for radial gradients. - support glyph rendering with a decent glyph cache design. The current plan is a per scaled-font growable cache texture + a scratch cache for one-shot/short-lived glyphs. - decide how to handle npot textures when lacking hardware support. Current plan is to add a transparent border to npot textures and use CLAMP_TO_EDGE for the default EXTEND_NONE semantics. For anything else we can allocate a shadow npot texture and scale the original to fit that so we can map extend modes to texture sampler modes.
Diffstat (limited to 'src/cairo-default-context.c')
-rw-r--r--src/cairo-default-context.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/cairo-default-context.c b/src/cairo-default-context.c
index 98cc6684d..b58a76614 100644
--- a/src/cairo-default-context.c
+++ b/src/cairo-default-context.c
@@ -63,11 +63,9 @@ _cairo_default_context_reset_static_data (void)
_freed_pool_reset (&context_pool);
}
-static void
-_cairo_default_context_destroy (void *abstract_cr)
+void
+_cairo_default_context_fini (cairo_default_context_t *cr)
{
- cairo_default_context_t *cr = abstract_cr;
-
while (cr->gstate != &cr->gstate_tail[0]) {
if (_cairo_gstate_restore (&cr->gstate, &cr->gstate_freelist))
break;
@@ -84,6 +82,14 @@ _cairo_default_context_destroy (void *abstract_cr)
_cairo_path_fixed_fini (cr->path);
_cairo_fini (&cr->base);
+}
+
+static void
+_cairo_default_context_destroy (void *abstract_cr)
+{
+ cairo_default_context_t *cr = abstract_cr;
+
+ _cairo_default_context_fini (cr);
/* mark the context as invalid to protect against misuse */
cr->base.status = CAIRO_STATUS_NULL_POINTER;
@@ -1381,6 +1387,19 @@ static const cairo_backend_t _cairo_default_context_backend = {
_cairo_default_context_show_page,
};
+cairo_status_t
+_cairo_default_context_init (cairo_default_context_t *cr, void *target)
+{
+ _cairo_init (&cr->base, &_cairo_default_context_backend);
+ _cairo_path_fixed_init (cr->path);
+
+ cr->gstate = &cr->gstate_tail[0];
+ cr->gstate_freelist = &cr->gstate_tail[1];
+ cr->gstate_tail[1].next = NULL;
+
+ return _cairo_gstate_init (cr->gstate, target);
+}
+
cairo_t *
_cairo_default_context_create (void *target)
{
@@ -1394,14 +1413,7 @@ _cairo_default_context_create (void *target)
return _cairo_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
}
- _cairo_init (&cr->base, &_cairo_default_context_backend);
- _cairo_path_fixed_init (cr->path);
-
- cr->gstate = &cr->gstate_tail[0];
- cr->gstate_freelist = &cr->gstate_tail[1];
- cr->gstate_tail[1].next = NULL;
-
- status = _cairo_gstate_init (cr->gstate, target);
+ status = _cairo_default_context_init (cr, target);
if (unlikely (status)) {
_freed_pool_put (&context_pool, cr);
return _cairo_create_in_error (status);