gfx/cairo/quartz-create-for-data.patch

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 diff --git a/gfx/cairo/README b/gfx/cairo/README
     2 --- a/gfx/cairo/README
     3 +++ b/gfx/cairo/README
     4 @@ -71,16 +71,18 @@ quartz-cache-CGImageRef.patch: cache CGI
     5  quartz-remove-snapshot.patch: remove broken implementation of backend snapshot
     7  quartz-cglayers.patch: add support for cairo surfaces backed by CGLayers
     9  quartz-cglayers-fix-fallback.patch: Bug 572912; fix bug in fallback code in previous patch
    11  quartz-get-image.patch: Bug 575521; add a way to get the image surface associated with a surface
    13 +quartz-create-for-data.patch: Bug 575521; add a way to create quartz surfaces backed with application-provided data
    14 +
    15  premultiply-alpha-solid-gradients.patch: bug 539165; multiply the solid color by the alpha component before using it for a solid surface
    17  xlib-initialize-members.path: bug 548793; initialize XRender version if the server doesn't have the extension
    19  remove-comma: remove a comma from enum
    21  d2d.patch: add d2d support
    23 diff --git a/gfx/cairo/cairo/src/cairo-quartz-private.h b/gfx/cairo/cairo/src/cairo-quartz-private.h
    24 --- a/gfx/cairo/cairo/src/cairo-quartz-private.h
    25 +++ b/gfx/cairo/cairo/src/cairo-quartz-private.h
    26 @@ -63,16 +63,18 @@ typedef struct cairo_quartz_surface {
    27      CGImageRef bitmapContextImage;
    29      /**
    30       * If non-null, this is the CGLayer for the surface.
    31       */
    32      CGLayerRef cgLayer;
    34      cairo_rectangle_int_t extents;
    35 +
    36 +    cairo_bool_t ownsData;
    37  } cairo_quartz_surface_t;
    39  typedef struct cairo_quartz_image_surface {
    40      cairo_surface_t base;
    42      cairo_rectangle_int_t extents;
    44      CGImageRef image;
    45 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
    46 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
    47 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
    48 @@ -1880,20 +1880,21 @@ _cairo_quartz_surface_finish (void *abst
    49      surface->cgContext = NULL;
    51      if (surface->bitmapContextImage) {
    52          CGImageRelease (surface->bitmapContextImage);
    53          surface->bitmapContextImage = NULL;
    54      }
    56      if (surface->imageSurfaceEquiv) {
    57 -	_cairo_image_surface_assume_ownership_of_data (surface->imageSurfaceEquiv);
    58 +        if (surface->ownsData)
    59 +            _cairo_image_surface_assume_ownership_of_data (surface->imageSurfaceEquiv);
    60  	cairo_surface_destroy (surface->imageSurfaceEquiv);
    61  	surface->imageSurfaceEquiv = NULL;
    62 -    } else if (surface->imageData) {
    63 +    } else if (surface->imageData && surface->ownsData) {
    64          free (surface->imageData);
    65      }
    67      surface->imageData = NULL;
    69      if (surface->cgLayer) {
    70          CGLayerRelease (surface->cgLayer);
    71      }
    72 @@ -2888,16 +2889,17 @@ _cairo_quartz_surface_create_internal (C
    74      surface->cgContext = cgContext;
    75      surface->cgContextBaseCTM = CGContextGetCTM (cgContext);
    77      surface->imageData = NULL;
    78      surface->imageSurfaceEquiv = NULL;
    79      surface->bitmapContextImage = NULL;
    80      surface->cgLayer = NULL;
    81 +    surface->ownsData = TRUE;
    83      return surface;
    84  }
    86  /**
    87   * cairo_quartz_surface_create_for_cg_context
    88   * @cgContext: the existing CGContext for which to create the surface
    89   * @width: width of the surface, in pixels
    90 @@ -3031,23 +3033,103 @@ cairo_quartz_surface_create_cg_layer (ca
    91   *
    92   * Since: 1.4
    93   **/
    94  cairo_surface_t *
    95  cairo_quartz_surface_create (cairo_format_t format,
    96  			     unsigned int width,
    97  			     unsigned int height)
    98  {
    99 +    int stride;
   100 +    unsigned char *data;
   101 +
   102 +    if (!_cairo_quartz_verify_surface_size(width, height))
   103 +	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
   104 +
   105 +    if (width == 0 || height == 0) {
   106 +	return (cairo_surface_t*) _cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format),
   107 +									 width, height);
   108 +    }
   109 +
   110 +    if (format == CAIRO_FORMAT_ARGB32 ||
   111 +	format == CAIRO_FORMAT_RGB24)
   112 +    {
   113 +	stride = width * 4;
   114 +    } else if (format == CAIRO_FORMAT_A8) {
   115 +	stride = width;
   116 +    } else if (format == CAIRO_FORMAT_A1) {
   117 +	/* I don't think we can usefully support this, as defined by
   118 +	 * cairo_format_t -- these are 1-bit pixels stored in 32-bit
   119 +	 * quantities.
   120 +	 */
   121 +	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
   122 +    } else {
   123 +	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
   124 +    }
   125 +
   126 +    /* The Apple docs say that for best performance, the stride and the data
   127 +     * pointer should be 16-byte aligned.  malloc already aligns to 16-bytes,
   128 +     * so we don't have to anything special on allocation.
   129 +     */
   130 +    stride = (stride + 15) & ~15;
   131 +
   132 +    data = _cairo_malloc_ab (height, stride);
   133 +    if (!data) {
   134 +	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
   135 +    }
   136 +
   137 +    /* zero the memory to match the image surface behaviour */
   138 +    memset (data, 0, height * stride);
   139 +
   140 +    cairo_quartz_surface_t *surf;
   141 +    surf = (cairo_quartz_surface_t *) cairo_quartz_surface_create_for_data
   142 +                                           (data, format, width, height, stride);
   143 +    if (surf->base.status) {
   144 +        free (data);
   145 +        return (cairo_surface_t *) surf;
   146 +    }
   147 +
   148 +    // We created this data, so we can delete it.
   149 +    surf->ownsData = TRUE;
   150 +
   151 +    return (cairo_surface_t *) surf;
   152 +}
   153 +
   154 +/**
   155 + * cairo_quartz_surface_create_for_data
   156 + * @data: a pointer to a buffer supplied by the application in which
   157 + *     to write contents. This pointer must be suitably aligned for any
   158 + *     kind of variable, (for example, a pointer returned by malloc).
   159 + * @format: format of pixels in the surface to create
   160 + * @width: width of the surface, in pixels
   161 + * @height: height of the surface, in pixels
   162 + *
   163 + * Creates a Quartz surface backed by a CGBitmap.  The surface is
   164 + * created using the Device RGB (or Device Gray, for A8) color space.
   165 + * All Cairo operations, including those that require software
   166 + * rendering, will succeed on this surface.
   167 + *
   168 + * Return value: the newly created surface.
   169 + *
   170 + * Since: 1.12
   171 + **/
   172 +cairo_surface_t *
   173 +cairo_quartz_surface_create_for_data (unsigned char *data,
   174 +				      cairo_format_t format,
   175 +				      unsigned int width,
   176 +				      unsigned int height,
   177 +				      unsigned int stride)
   178 +{
   179      cairo_quartz_surface_t *surf;
   180      CGContextRef cgc;
   181      CGColorSpaceRef cgColorspace;
   182      CGBitmapInfo bitinfo;
   183 -    void *imageData;
   184 -    int stride;
   185 +    void *imageData = data;
   186      int bitsPerComponent;
   187 +    unsigned int i;
   189      // verify width and height of surface
   190      if (!_cairo_quartz_verify_surface_size(width, height))
   191  	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));
   193      if (width == 0 || height == 0) {
   194  	return (cairo_surface_t*) _cairo_quartz_surface_create_internal (NULL, _cairo_content_from_format (format),
   195  									 width, height);
   196 @@ -3058,47 +3140,30 @@ cairo_quartz_surface_create (cairo_forma
   197      {
   198  	cgColorspace = CGColorSpaceCreateDeviceRGB();
   199  	bitinfo = kCGBitmapByteOrder32Host;
   200  	if (format == CAIRO_FORMAT_ARGB32)
   201  	    bitinfo |= kCGImageAlphaPremultipliedFirst;
   202  	else
   203  	    bitinfo |= kCGImageAlphaNoneSkipFirst;
   204  	bitsPerComponent = 8;
   205 -	stride = width * 4;
   206      } else if (format == CAIRO_FORMAT_A8) {
   207  	cgColorspace = NULL;
   208 -	stride = width;
   209  	bitinfo = kCGImageAlphaOnly;
   210  	bitsPerComponent = 8;
   211      } else if (format == CAIRO_FORMAT_A1) {
   212  	/* I don't think we can usefully support this, as defined by
   213  	 * cairo_format_t -- these are 1-bit pixels stored in 32-bit
   214  	 * quantities.
   215  	 */
   216  	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
   217      } else {
   218  	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
   219      }
   221 -    /* The Apple docs say that for best performance, the stride and the data
   222 -     * pointer should be 16-byte aligned.  malloc already aligns to 16-bytes,
   223 -     * so we don't have to anything special on allocation.
   224 -     */
   225 -    stride = (stride + 15) & ~15;
   226 -
   227 -    imageData = _cairo_malloc_ab (height, stride);
   228 -    if (!imageData) {
   229 -	CGColorSpaceRelease (cgColorspace);
   230 -	return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
   231 -    }
   232 -
   233 -    /* zero the memory to match the image surface behaviour */
   234 -    memset (imageData, 0, height * stride);
   235 -
   236      cgc = CGBitmapContextCreate (imageData,
   237  				 width,
   238  				 height,
   239  				 bitsPerComponent,
   240  				 stride,
   241  				 cgColorspace,
   242  				 bitinfo);
   243      CGColorSpaceRelease (cgColorspace);
   244 @@ -3118,16 +3183,17 @@ cairo_quartz_surface_create (cairo_forma
   245  	CGContextRelease (cgc);
   246  	free (imageData);
   247  	// create_internal will have set an error
   248  	return (cairo_surface_t*) surf;
   249      }
   251      surf->imageData = imageData;
   252      surf->imageSurfaceEquiv = cairo_image_surface_create_for_data (imageData, format, width, height, stride);
   253 +    surf->ownsData = FALSE;
   255      return (cairo_surface_t *) surf;
   256  }
   258  /**
   259   * cairo_quartz_surface_get_cg_context
   260   * @surface: the Cairo Quartz surface
   261   *
   262 diff --git a/gfx/cairo/cairo/src/cairo-quartz.h b/gfx/cairo/cairo/src/cairo-quartz.h
   263 --- a/gfx/cairo/cairo/src/cairo-quartz.h
   264 +++ b/gfx/cairo/cairo/src/cairo-quartz.h
   265 @@ -45,16 +45,23 @@
   266  CAIRO_BEGIN_DECLS
   268  cairo_public cairo_surface_t *
   269  cairo_quartz_surface_create (cairo_format_t format,
   270                               unsigned int width,
   271                               unsigned int height);
   273  cairo_public cairo_surface_t *
   274 +cairo_quartz_surface_create_for_data (unsigned char *data,
   275 +				      cairo_format_t format,
   276 +				      unsigned int width,
   277 +				      unsigned int height,
   278 +				      unsigned int stride);
   279 +
   280 +cairo_public cairo_surface_t *
   281  cairo_quartz_surface_create_cg_layer (cairo_surface_t *surface,
   282                                        unsigned int width,
   283                                        unsigned int height);
   285  cairo_public cairo_surface_t *
   286  cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
   287                                              unsigned int width,
   288                                              unsigned int height);
   289 diff --git a/gfx/cairo/cairo/src/cairo-rename.h b/gfx/cairo/cairo/src/cairo-rename.h
   290 --- a/gfx/cairo/cairo/src/cairo-rename.h
   291 +++ b/gfx/cairo/cairo/src/cairo-rename.h
   292 @@ -176,16 +176,17 @@
   293  #define cairo_qpainter_surface_get_image _moz_cairo_qpainter_surface_get_image
   294  #define cairo_qpainter_surface_get_qimage _moz_cairo_qpainter_surface_get_qimage
   295  #define cairo_qpainter_surface_get_qpainter _moz_cairo_qpainter_surface_get_qpainter
   296  #define cairo_quartz_font_face_create_for_atsu_font_id _moz_cairo_quartz_font_face_create_for_atsu_font_id
   297  #define cairo_quartz_font_face_create_for_cgfont _moz_cairo_quartz_font_face_create_for_cgfont
   298  #define cairo_quartz_image_surface_create _moz_cairo_quartz_image_surface_create
   299  #define cairo_quartz_image_surface_get_image _moz_cairo_quartz_image_surface_get_image
   300  #define cairo_quartz_surface_create _moz_cairo_quartz_surface_create
   301 +#define cairo_quartz_surface_create_for_data _moz_cairo_quartz_surface_create_for_data
   302  #define cairo_quartz_surface_create_for_cg_context _moz_cairo_quartz_surface_create_for_cg_context
   303  #define cairo_quartz_surface_get_cg_context _moz_cairo_quartz_surface_get_cg_context
   304  #define cairo_quartz_surface_get_image _moz_cairo_quartz_surface_get_image
   305  #define cairo_rectangle _moz_cairo_rectangle
   306  #define cairo_rectangle_list_destroy _moz_cairo_rectangle_list_destroy
   307  #define cairo_reference _moz_cairo_reference
   308  #define cairo_rel_curve_to _moz_cairo_rel_curve_to
   309  #define cairo_rel_line_to _moz_cairo_rel_line_to

mercurial