1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/cairo/quartz-create-for-data.patch Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,309 @@ 1.4 +diff --git a/gfx/cairo/README b/gfx/cairo/README 1.5 +--- a/gfx/cairo/README 1.6 ++++ b/gfx/cairo/README 1.7 +@@ -71,16 +71,18 @@ quartz-cache-CGImageRef.patch: cache CGI 1.8 + quartz-remove-snapshot.patch: remove broken implementation of backend snapshot 1.9 + 1.10 + quartz-cglayers.patch: add support for cairo surfaces backed by CGLayers 1.11 + 1.12 + quartz-cglayers-fix-fallback.patch: Bug 572912; fix bug in fallback code in previous patch 1.13 + 1.14 + quartz-get-image.patch: Bug 575521; add a way to get the image surface associated with a surface 1.15 + 1.16 ++quartz-create-for-data.patch: Bug 575521; add a way to create quartz surfaces backed with application-provided data 1.17 ++ 1.18 + premultiply-alpha-solid-gradients.patch: bug 539165; multiply the solid color by the alpha component before using it for a solid surface 1.19 + 1.20 + xlib-initialize-members.path: bug 548793; initialize XRender version if the server doesn't have the extension 1.21 + 1.22 + remove-comma: remove a comma from enum 1.23 + 1.24 + d2d.patch: add d2d support 1.25 + 1.26 +diff --git a/gfx/cairo/cairo/src/cairo-quartz-private.h b/gfx/cairo/cairo/src/cairo-quartz-private.h 1.27 +--- a/gfx/cairo/cairo/src/cairo-quartz-private.h 1.28 ++++ b/gfx/cairo/cairo/src/cairo-quartz-private.h 1.29 +@@ -63,16 +63,18 @@ typedef struct cairo_quartz_surface { 1.30 + CGImageRef bitmapContextImage; 1.31 + 1.32 + /** 1.33 + * If non-null, this is the CGLayer for the surface. 1.34 + */ 1.35 + CGLayerRef cgLayer; 1.36 + 1.37 + cairo_rectangle_int_t extents; 1.38 ++ 1.39 ++ cairo_bool_t ownsData; 1.40 + } cairo_quartz_surface_t; 1.41 + 1.42 + typedef struct cairo_quartz_image_surface { 1.43 + cairo_surface_t base; 1.44 + 1.45 + cairo_rectangle_int_t extents; 1.46 + 1.47 + CGImageRef image; 1.48 +diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c 1.49 +--- a/gfx/cairo/cairo/src/cairo-quartz-surface.c 1.50 ++++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c 1.51 +@@ -1880,20 +1880,21 @@ _cairo_quartz_surface_finish (void *abst 1.52 + surface->cgContext = NULL; 1.53 + 1.54 + if (surface->bitmapContextImage) { 1.55 + CGImageRelease (surface->bitmapContextImage); 1.56 + surface->bitmapContextImage = NULL; 1.57 + } 1.58 + 1.59 + if (surface->imageSurfaceEquiv) { 1.60 +- _cairo_image_surface_assume_ownership_of_data (surface->imageSurfaceEquiv); 1.61 ++ if (surface->ownsData) 1.62 ++ _cairo_image_surface_assume_ownership_of_data (surface->imageSurfaceEquiv); 1.63 + cairo_surface_destroy (surface->imageSurfaceEquiv); 1.64 + surface->imageSurfaceEquiv = NULL; 1.65 +- } else if (surface->imageData) { 1.66 ++ } else if (surface->imageData && surface->ownsData) { 1.67 + free (surface->imageData); 1.68 + } 1.69 + 1.70 + surface->imageData = NULL; 1.71 + 1.72 + if (surface->cgLayer) { 1.73 + CGLayerRelease (surface->cgLayer); 1.74 + } 1.75 +@@ -2888,16 +2889,17 @@ _cairo_quartz_surface_create_internal (C 1.76 + 1.77 + surface->cgContext = cgContext; 1.78 + surface->cgContextBaseCTM = CGContextGetCTM (cgContext); 1.79 + 1.80 + surface->imageData = NULL; 1.81 + surface->imageSurfaceEquiv = NULL; 1.82 + surface->bitmapContextImage = NULL; 1.83 + surface->cgLayer = NULL; 1.84 ++ surface->ownsData = TRUE; 1.85 + 1.86 + return surface; 1.87 + } 1.88 + 1.89 + /** 1.90 + * cairo_quartz_surface_create_for_cg_context 1.91 + * @cgContext: the existing CGContext for which to create the surface 1.92 + * @width: width of the surface, in pixels 1.93 +@@ -3031,23 +3033,103 @@ cairo_quartz_surface_create_cg_layer (ca 1.94 + * 1.95 + * Since: 1.4 1.96 + **/ 1.97 + cairo_surface_t * 1.98 + cairo_quartz_surface_create (cairo_format_t format, 1.99 + unsigned int width, 1.100 + unsigned int height) 1.101 + { 1.102 ++ int stride; 1.103 ++ unsigned char *data; 1.104 ++ 1.105 ++ if (!_cairo_quartz_verify_surface_size(width, height)) 1.106 ++ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); 1.107 ++ 1.108 ++ if (width == 0 || height == 0) { 1.109 ++ return (cairo_surface_t*) _cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format), 1.110 ++ width, height); 1.111 ++ } 1.112 ++ 1.113 ++ if (format == CAIRO_FORMAT_ARGB32 || 1.114 ++ format == CAIRO_FORMAT_RGB24) 1.115 ++ { 1.116 ++ stride = width * 4; 1.117 ++ } else if (format == CAIRO_FORMAT_A8) { 1.118 ++ stride = width; 1.119 ++ } else if (format == CAIRO_FORMAT_A1) { 1.120 ++ /* I don't think we can usefully support this, as defined by 1.121 ++ * cairo_format_t -- these are 1-bit pixels stored in 32-bit 1.122 ++ * quantities. 1.123 ++ */ 1.124 ++ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); 1.125 ++ } else { 1.126 ++ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); 1.127 ++ } 1.128 ++ 1.129 ++ /* The Apple docs say that for best performance, the stride and the data 1.130 ++ * pointer should be 16-byte aligned. malloc already aligns to 16-bytes, 1.131 ++ * so we don't have to anything special on allocation. 1.132 ++ */ 1.133 ++ stride = (stride + 15) & ~15; 1.134 ++ 1.135 ++ data = _cairo_malloc_ab (height, stride); 1.136 ++ if (!data) { 1.137 ++ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); 1.138 ++ } 1.139 ++ 1.140 ++ /* zero the memory to match the image surface behaviour */ 1.141 ++ memset (data, 0, height * stride); 1.142 ++ 1.143 ++ cairo_quartz_surface_t *surf; 1.144 ++ surf = (cairo_quartz_surface_t *) cairo_quartz_surface_create_for_data 1.145 ++ (data, format, width, height, stride); 1.146 ++ if (surf->base.status) { 1.147 ++ free (data); 1.148 ++ return (cairo_surface_t *) surf; 1.149 ++ } 1.150 ++ 1.151 ++ // We created this data, so we can delete it. 1.152 ++ surf->ownsData = TRUE; 1.153 ++ 1.154 ++ return (cairo_surface_t *) surf; 1.155 ++} 1.156 ++ 1.157 ++/** 1.158 ++ * cairo_quartz_surface_create_for_data 1.159 ++ * @data: a pointer to a buffer supplied by the application in which 1.160 ++ * to write contents. This pointer must be suitably aligned for any 1.161 ++ * kind of variable, (for example, a pointer returned by malloc). 1.162 ++ * @format: format of pixels in the surface to create 1.163 ++ * @width: width of the surface, in pixels 1.164 ++ * @height: height of the surface, in pixels 1.165 ++ * 1.166 ++ * Creates a Quartz surface backed by a CGBitmap. The surface is 1.167 ++ * created using the Device RGB (or Device Gray, for A8) color space. 1.168 ++ * All Cairo operations, including those that require software 1.169 ++ * rendering, will succeed on this surface. 1.170 ++ * 1.171 ++ * Return value: the newly created surface. 1.172 ++ * 1.173 ++ * Since: 1.12 1.174 ++ **/ 1.175 ++cairo_surface_t * 1.176 ++cairo_quartz_surface_create_for_data (unsigned char *data, 1.177 ++ cairo_format_t format, 1.178 ++ unsigned int width, 1.179 ++ unsigned int height, 1.180 ++ unsigned int stride) 1.181 ++{ 1.182 + cairo_quartz_surface_t *surf; 1.183 + CGContextRef cgc; 1.184 + CGColorSpaceRef cgColorspace; 1.185 + CGBitmapInfo bitinfo; 1.186 +- void *imageData; 1.187 +- int stride; 1.188 ++ void *imageData = data; 1.189 + int bitsPerComponent; 1.190 ++ unsigned int i; 1.191 + 1.192 + // verify width and height of surface 1.193 + if (!_cairo_quartz_verify_surface_size(width, height)) 1.194 + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE)); 1.195 + 1.196 + if (width == 0 || height == 0) { 1.197 + return (cairo_surface_t*) _cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format), 1.198 + width, height); 1.199 +@@ -3058,47 +3140,30 @@ cairo_quartz_surface_create (cairo_forma 1.200 + { 1.201 + cgColorspace = CGColorSpaceCreateDeviceRGB(); 1.202 + bitinfo = kCGBitmapByteOrder32Host; 1.203 + if (format == CAIRO_FORMAT_ARGB32) 1.204 + bitinfo |= kCGImageAlphaPremultipliedFirst; 1.205 + else 1.206 + bitinfo |= kCGImageAlphaNoneSkipFirst; 1.207 + bitsPerComponent = 8; 1.208 +- stride = width * 4; 1.209 + } else if (format == CAIRO_FORMAT_A8) { 1.210 + cgColorspace = NULL; 1.211 +- stride = width; 1.212 + bitinfo = kCGImageAlphaOnly; 1.213 + bitsPerComponent = 8; 1.214 + } else if (format == CAIRO_FORMAT_A1) { 1.215 + /* I don't think we can usefully support this, as defined by 1.216 + * cairo_format_t -- these are 1-bit pixels stored in 32-bit 1.217 + * quantities. 1.218 + */ 1.219 + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); 1.220 + } else { 1.221 + return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT)); 1.222 + } 1.223 + 1.224 +- /* The Apple docs say that for best performance, the stride and the data 1.225 +- * pointer should be 16-byte aligned. malloc already aligns to 16-bytes, 1.226 +- * so we don't have to anything special on allocation. 1.227 +- */ 1.228 +- stride = (stride + 15) & ~15; 1.229 +- 1.230 +- imageData = _cairo_malloc_ab (height, stride); 1.231 +- if (!imageData) { 1.232 +- CGColorSpaceRelease (cgColorspace); 1.233 +- return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY)); 1.234 +- } 1.235 +- 1.236 +- /* zero the memory to match the image surface behaviour */ 1.237 +- memset (imageData, 0, height * stride); 1.238 +- 1.239 + cgc = CGBitmapContextCreate (imageData, 1.240 + width, 1.241 + height, 1.242 + bitsPerComponent, 1.243 + stride, 1.244 + cgColorspace, 1.245 + bitinfo); 1.246 + CGColorSpaceRelease (cgColorspace); 1.247 +@@ -3118,16 +3183,17 @@ cairo_quartz_surface_create (cairo_forma 1.248 + CGContextRelease (cgc); 1.249 + free (imageData); 1.250 + // create_internal will have set an error 1.251 + return (cairo_surface_t*) surf; 1.252 + } 1.253 + 1.254 + surf->imageData = imageData; 1.255 + surf->imageSurfaceEquiv = cairo_image_surface_create_for_data (imageData, format, width, height, stride); 1.256 ++ surf->ownsData = FALSE; 1.257 + 1.258 + return (cairo_surface_t *) surf; 1.259 + } 1.260 + 1.261 + /** 1.262 + * cairo_quartz_surface_get_cg_context 1.263 + * @surface: the Cairo Quartz surface 1.264 + * 1.265 +diff --git a/gfx/cairo/cairo/src/cairo-quartz.h b/gfx/cairo/cairo/src/cairo-quartz.h 1.266 +--- a/gfx/cairo/cairo/src/cairo-quartz.h 1.267 ++++ b/gfx/cairo/cairo/src/cairo-quartz.h 1.268 +@@ -45,16 +45,23 @@ 1.269 + CAIRO_BEGIN_DECLS 1.270 + 1.271 + cairo_public cairo_surface_t * 1.272 + cairo_quartz_surface_create (cairo_format_t format, 1.273 + unsigned int width, 1.274 + unsigned int height); 1.275 + 1.276 + cairo_public cairo_surface_t * 1.277 ++cairo_quartz_surface_create_for_data (unsigned char *data, 1.278 ++ cairo_format_t format, 1.279 ++ unsigned int width, 1.280 ++ unsigned int height, 1.281 ++ unsigned int stride); 1.282 ++ 1.283 ++cairo_public cairo_surface_t * 1.284 + cairo_quartz_surface_create_cg_layer (cairo_surface_t *surface, 1.285 + unsigned int width, 1.286 + unsigned int height); 1.287 + 1.288 + cairo_public cairo_surface_t * 1.289 + cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext, 1.290 + unsigned int width, 1.291 + unsigned int height); 1.292 +diff --git a/gfx/cairo/cairo/src/cairo-rename.h b/gfx/cairo/cairo/src/cairo-rename.h 1.293 +--- a/gfx/cairo/cairo/src/cairo-rename.h 1.294 ++++ b/gfx/cairo/cairo/src/cairo-rename.h 1.295 +@@ -176,16 +176,17 @@ 1.296 + #define cairo_qpainter_surface_get_image _moz_cairo_qpainter_surface_get_image 1.297 + #define cairo_qpainter_surface_get_qimage _moz_cairo_qpainter_surface_get_qimage 1.298 + #define cairo_qpainter_surface_get_qpainter _moz_cairo_qpainter_surface_get_qpainter 1.299 + #define cairo_quartz_font_face_create_for_atsu_font_id _moz_cairo_quartz_font_face_create_for_atsu_font_id 1.300 + #define cairo_quartz_font_face_create_for_cgfont _moz_cairo_quartz_font_face_create_for_cgfont 1.301 + #define cairo_quartz_image_surface_create _moz_cairo_quartz_image_surface_create 1.302 + #define cairo_quartz_image_surface_get_image _moz_cairo_quartz_image_surface_get_image 1.303 + #define cairo_quartz_surface_create _moz_cairo_quartz_surface_create 1.304 ++#define cairo_quartz_surface_create_for_data _moz_cairo_quartz_surface_create_for_data 1.305 + #define cairo_quartz_surface_create_for_cg_context _moz_cairo_quartz_surface_create_for_cg_context 1.306 + #define cairo_quartz_surface_get_cg_context _moz_cairo_quartz_surface_get_cg_context 1.307 + #define cairo_quartz_surface_get_image _moz_cairo_quartz_surface_get_image 1.308 + #define cairo_rectangle _moz_cairo_rectangle 1.309 + #define cairo_rectangle_list_destroy _moz_cairo_rectangle_list_destroy 1.310 + #define cairo_reference _moz_cairo_reference 1.311 + #define cairo_rel_curve_to _moz_cairo_rel_curve_to 1.312 + #define cairo_rel_line_to _moz_cairo_rel_line_to