Re: create_surface_for_cg_context behavior in Cairo 1.9 vs. 1.12
Andrea Canciani <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <CAN_5=BCAdmh+-B43Ue2L6+jxOjd-YwXJjjatEHj7K1ad=x50qA@mail.gmail.com> |
On Sat, Jun 2, 2012 at 2:44 PM, cu <[email protected]> wrote: > Andrea, > > Please take a careful look at sample code. Source surface is an *image > surface* created previously (not shown in the sample) with > cairo_surface_create. CGContext surface is the *destination*. > Note that source pattern "qpat" is created from "source_surf". > Note that destination context "qcr" is created from "qsurf" which is the > CGContext surface. > Sorry, you're right, I misread your code snippet. I tried making a program out of it, but I didn't manage to reproduce the issue. See the attachments for the code, the output on 1.9.8 and on master. Can you please check if you can confirm the behavior in your environment? Do you have any idea about what the initialization of the context should be in order to reproduce your issue? Andrea > > Andrea Canciani wrote: >> On Sat, Jun 2, 2012 at 2:01 PM, cu <[email protected]> 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) >> > -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
quartz-context-1.9.8.png
(image/png, 236 B) - not displayed
quartz-context-master.png
(image/png, 236 B) - not displayed
quartz-transform.c
(text/x-csrc, 2.5 KB)
#include <cairo.h>
#include <cairo-quartz.h>
#include <stdio.h>
static cairo_surface_t *
create_source (int width, int height)
{
cairo_surface_t *similar;
cairo_t *cr;
similar = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
width, height);
cr = cairo_create (similar);
cairo_surface_destroy (similar);
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_rectangle (cr,
width - 4, height - 4,
2, 2);
cairo_fill (cr);
cairo_set_source_rgb (cr, 1, 0, 0);
cairo_rectangle (cr,
width - 2, height - 4,
2, 2);
cairo_fill (cr);
cairo_set_source_rgb (cr, 0, 1, 0);
cairo_rectangle (cr,
width - 4, height - 2,
2, 2);
cairo_fill (cr);
cairo_set_source_rgb (cr, 0, 0, 1);
cairo_rectangle (cr,
width - 2, height - 2,
2, 2);
cairo_fill (cr);
similar = cairo_surface_reference (cairo_get_target (cr));
cairo_destroy (cr);
return similar;
}
int
main (int argc, char **argv)
{
cairo_t *cr;
CGContextRef cgref;
CGColorSpaceRef cgcsref;
CGBitmapInfo bitinfo;
int stride, bits_per_component, width, height;
cairo_surface_t *surface, *source;
void *data;
cairo_matrix_t matrix;
cairo_matrix_init_scale (&matrix, 0.25, 0.25);
cairo_matrix_translate (&matrix, -8, -8);
width = 128;
height = 128;
bits_per_component = 8;
stride = width * 4;
bitinfo = kCGBitmapByteOrder32Host | kCGImageAlphaNoneSkipFirst; //PremultipliedFirst;
data = calloc (stride, height);
cgcsref = CGColorSpaceCreateDeviceRGB ();
cgref = CGBitmapContextCreate (data,
width,
height,
bits_per_component,
stride,
cgcsref,
bitinfo);
CGColorSpaceRelease (cgcsref);
CGContextTranslateCTM (cgref, 0.0, height);
CGContextScaleCTM (cgref, 1.0, -1.0);
CGContextScaleCTM (cgref, 2.0, 2.0);
surface = cairo_quartz_surface_create_for_cg_context(cgref, width, height);
CGContextRelease (cgref);
cr = cairo_create (surface);
source = create_source (4, 4);
cairo_set_source_surface (cr, source, 0, 0);
cairo_surface_destroy (source);
cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
cairo_pattern_set_matrix (cairo_get_source (cr), &matrix);
cairo_paint (cr);
printf ("%s: %d\n", cairo_version_string (), cairo_status (cr));
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "quartz-context.png");
cairo_surface_destroy (surface);
free (data);
return 0;
}