[cairo] create_surface_for_cg_context behavior in Cairo 1.9 vs. 1.12

Andrea Canciani ranma42 at gmail.com
Sat Jun 2 05:28:04 PDT 2012

On Sat, Jun 2, 2012 at 2:01 PM, cu <cairouser at yahoo.com> wrote:
> The test case is quite simple:
> // .. set up source_surf as an image surface of the same size as the
> UIView, draw into it...
> CGContextRef cgref = UIGraphicsGetCurrentContext();
> qsurf = cairo_quartz_surface_create_for_cg_context(cgref,
> source_surf_width, source_surf_height);
> qpat = cairo_pattern_create_for_surface(source_surf);
> qcr = cairo_create(qsurf);
> cairo_set_source(qcr, qpat);
> cairo_paint(qcr);

It looks like you're using a surface created with
cairo_quartz_surface_create_for_cg_context() as source.
That is quite a bad idea (see the "bad things" I warned you about).

Would it be possible to draw on a surface created with
cairo_quartz_surface_create(), instead?
(I guess it might involve performing an additional blit)

> Under 1.9.8 the resulting cairo surface backed by CGContext is measured
> in "points", covers the entire view and seems to have native iOS scaling
> applied.
> Under 1.12 it is in pixels with no scaling applied, and covers upper
> left quadrant of the view.
> I tried to manually add scaling to CGContext surface while using cairo
> 1.12 by setting scaling transform and increasing surface dimensions
> times 2. The result was not the same as when using cairo 1.9.8. Image
> appeared poorly scaled (not very sharp, looked like the usual pixman
> upscaling) and rendering was very slow. It would appear that 1.9.8
> somehow is using native up-scaling of iOS which is faster and creates
> better quality images on "retina" display. We are using this
> functionality to move main image  to screen, where both performance and
> quality of upscaling are crucial.
>> Quite a lot of changes happened between 1.12 and 1.9.8.
>> Could you provide a small testcase to help keeping track of this
>> behavior (and to bisect the change).
>> The API reference says:
>> "The CGContext is assumed to be in the standard Cairo coordinate space
>> (that is, with the origin at the upper left and the Y axis increasing
>> downward). If the CGContext is in the Quartz coordinate space (with
>> the origin at the bottom left), then it should be flipped before this
>> function is called."
>> so I would expect cairo-quartz to respect the original transform
>> (although I guess bad things might happen if there are fallbacks
>> and/or the surface is used as a source).

More information about the cairo mailing list