[cairo] OpenGL backend news and a few words about shading

Thomas Hunger info at teh-web.de
Mon Mar 1 10:26:07 PST 2004


> Maybe it would be enough with an ensure_source backend function which
> would take a cairo_shader_t structure and would return the backends
> accelerated source surface. The cairo_shader_t would contain type and a
That is a good idea. 

> union of all different shader data structures. Type would be solid,
> linear, radial, gouraud or whatever. If the backend cannot create an
> accelerated surface it could just return NULL and an image version would
> be created.
We would need a cairo_shader_t_copy and destroy to save and restore the shader 
state in the gstate-stack.
It might be usefull to have a rx, ry for a radial shader instead of just r to 
allow elliptical shaders.
Before every source_ensure operation we would need to transform the control 
points with the gstate->ctm, and restore the old controls points after the 
ensure_source function has finished. Here we would need a shader_t_copy 
function, too. As I wrote in the last post, if the surface_matrix of the 
pattern is part of the current state (i.e. saved in cairo_shader_t), too, it 
could be saved and restored with the shader_t_copy function, so we could 
remove the 

    if (! gstate->source_is_solid) {
	cairo_surface_get_matrix (gstate->source, &user_to_source);
	cairo_matrix_multiply (&device_to_source, &gstate->ctm_inverse, 
&user_to_source);
	cairo_surface_set_matrix (gstate->source, &device_to_source);
    }

and 

   /* restore the matrix originally in the source surface */
    if (! gstate->source_is_solid)
	cairo_surface_set_matrix (gstate->source, &user_to_source);

part since that is just a case of transforming the control points with the ctm 
(if you think of the surface matrix as some kind of control point).

> The best would probably be to have shader repeat behavior as an argument
> to the shader creation function or set with a cairo_set_shader_repeat
> function.
OK.

I'd like to have the following two functions to the public cairo_api:
(we would need them to determine the size of a shader surface before it is 
created, and  (sorry if I repeat myself) could also be useful to crop an 
image to its exact contents).

/* Rectangular extents */
void
cairo_stroke_extents (cairo_t *cr, pixman_box16_t *extents);

void
cairo_fill_extents (cairo_t *cr, pixman_box16_t *extents);

To Carl:
I think retrieving the region an operation covers should be done with seperate

pixman_region16_t *
cairo_stroke|fill_covers (cairo_t *cr);

since these function would be much more complicated. In the cairo_spline 
example they could create up to three rects for each drawn line just for the 
spline. 

> > cairo_set_shader_custom (cairo_shader_callback_t *shader_callback);

This function can not easily be introduced when the cairo_shader_t is hidden, 
so I think if someone really wants to have a custom shader one would have to 
create the shaded surface by hand and then use cairo_set_pattern (although 
the surface matrix would need to be set to the inverse gstate->ctm to ensure 
the image is not influenced by current transformations).

Tom





More information about the cairo mailing list