diff options
author | John Ralls <jralls@ceridwen.us> | 2023-02-07 09:48:16 -0800 |
---|---|---|
committer | John Ralls <jralls@ceridwen.us> | 2023-02-17 10:25:14 -0800 |
commit | 951a3dd9a78c7882106b5c0d5c0a74454ffcd387 (patch) | |
tree | d6dc8df640d985e93cc053ce6f74d6eea02ca198 /src/cairo-quartz-image-surface.c | |
parent | d7b9695ee431dfe43a2ae48ebfd907623c6cb6e0 (diff) | |
download | cairo-951a3dd9a78c7882106b5c0d5c0a74454ffcd387.tar.gz |
[quartz]Conditionally Use Main Display ColorSpace instead of kCGColorSpaceDefaultRGB.
The default RGB colorspace must be converted to the GPU's colorspace
using CGColorTransformConvertUsingCMSConverter. Profiling has shown this
function to consume as much as 48% of a redraw cycle in gdk-quartz.
There seems to be no named colorspace that matches the one stored on the
display, so we use the one associated with the main display. This has
some risks for users with multiple monitors but in testing with my own
two-monitor setup, one of which is HDR and the other not, the colorspace
was the same for both.
This is applied to quartz surfaces created with
cairo_quartz_surface_create(); surfaces created with
cairo_quartz_surface_create_for_cg_context will inherit the colorspace
from the context.
In order to generate PNGs that look right I've converted the
existing debugging functions for writing a quartz surface to png
into private functions and wired cairo-boilerplate-quartz to use
them. Using the generic cairo routine produced washed-out PNGs.
Fixes https://gitlab.freedesktop.org/cairo/cairo/-/issues/330
Diffstat (limited to 'src/cairo-quartz-image-surface.c')
-rw-r--r-- | src/cairo-quartz-image-surface.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cairo-quartz-image-surface.c b/src/cairo-quartz-image-surface.c index 5d7f96018..d09f5b5bc 100644 --- a/src/cairo-quartz-image-surface.c +++ b/src/cairo-quartz-image-surface.c @@ -292,7 +292,15 @@ cairo_quartz_image_surface_create (cairo_surface_t *surface) NULL, /* device */ _cairo_content_from_format (format), FALSE); /* is_vector */ - colorspace = CGColorSpaceCreateDeviceRGB (); + + if (_cairo_surface_is_quartz (surface) || _cairo_surface_is_quartz_image (surface)) { + CGContextRef context = cairo_quartz_surface_get_cg_context(surface); + colorspace = _cairo_quartz_create_color_space (context); + } + else { + colorspace = CGDisplayCopyColorSpace (CGMainDisplayID ()); + } + bitinfo |= format == CAIRO_FORMAT_ARGB32 ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst; qisurf->width = width; |