tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

09-quartz-surface-additions.patch (4899B)


      1 # HG changeset patch
      2 # User Jonathan Kew <jkew@mozilla.com>
      3 # Date 1713889662 -3600
      4 #      Tue Apr 23 17:27:42 2024 +0100
      5 # Node ID fd010d43c6a9aabbffd9cba9d0f290996c052c65
      6 # Parent  cf33e155ac6207c3903408de7341e0ac68be7474
      7 Bug 1892913 - patch 12 - Update and apply 09-quartz-surface-additions.patch
      8 
      9 diff --git a/gfx/cairo/cairo/src/cairo-quartz-surface.c b/gfx/cairo/cairo/src/cairo-quartz-surface.c
     10 --- a/gfx/cairo/cairo/src/cairo-quartz-surface.c
     11 +++ b/gfx/cairo/cairo/src/cairo-quartz-surface.c
     12 @@ -409,6 +409,7 @@ static CGBlendMode
     13         default:
     14 	    ASSERT_NOT_REACHED;
     15     }
     16 +    return kCGBlendModeNormal; /* unreached */
     17 }
     18 
     19 static cairo_int_status_t
     20 @@ -998,7 +999,7 @@ static cairo_int_status_t
     21 	_cairo_surface_get_extents (&surface->base, &pattern_extents);
     22     }
     23 
     24 -    if (source->extend == CAIRO_EXTEND_NONE) {
     25 +    if (source->extend == CAIRO_EXTEND_NONE || source->extend == CAIRO_EXTEND_PAD) {
     26 	int x, y;
     27 
     28 	if (op == CAIRO_OPERATOR_SOURCE &&
     29 @@ -1402,6 +1403,97 @@ static cairo_int_status_t
     30 
     31 
     32 /*
     33 + * get source/dest image implementation
     34 + */
     35 +
     36 +/* Read the image from the surface's front buffer */
     37 +static cairo_int_status_t
     38 +_cairo_quartz_get_image (cairo_quartz_surface_t *surface,
     39 +			 cairo_image_surface_t **image_out)
     40 +{
     41 +    unsigned char *imageData;
     42 +    cairo_image_surface_t *isurf;
     43 +
     44 +    if (_cairo_quartz_is_zero_surface (&surface->base)) {
     45 +	*image_out = (cairo_image_surface_t*) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 0, 0);
     46 +	return CAIRO_STATUS_SUCCESS;
     47 +    }
     48 +
     49 +    if (_cairo_quartz_is_cgcontext_bitmap_context(surface->cgContext)) {
     50 +	unsigned int stride;
     51 +	unsigned int bitinfo;
     52 +	unsigned int bpc, bpp;
     53 +	CGColorSpaceRef colorspace;
     54 +	unsigned int color_comps;
     55 +
     56 +	CGContextFlush(surface->cgContext);
     57 +	imageData = (unsigned char *) CGBitmapContextGetData(surface->cgContext);
     58 +
     59 +#ifdef USE_10_3_WORKAROUNDS
     60 +	bitinfo = CGBitmapContextGetAlphaInfo (surface->cgContext);
     61 +#else
     62 +	bitinfo = CGBitmapContextGetBitmapInfo (surface->cgContext);
     63 +#endif
     64 +	stride = CGBitmapContextGetBytesPerRow (surface->cgContext);
     65 +	bpp = CGBitmapContextGetBitsPerPixel (surface->cgContext);
     66 +	bpc = CGBitmapContextGetBitsPerComponent (surface->cgContext);
     67 +
     68 +	// let's hope they don't add YUV under us
     69 +	colorspace = CGBitmapContextGetColorSpace (surface->cgContext);
     70 +	color_comps = CGColorSpaceGetNumberOfComponents(colorspace);
     71 +
     72 +	// XXX TODO: We can handle all of these by converting to
     73 +	// pixman masks, including non-native-endian masks
     74 +	if (bpc != 8)
     75 +	    return CAIRO_INT_STATUS_UNSUPPORTED;
     76 +
     77 +	if (bpp != 32 && bpp != 8)
     78 +	    return CAIRO_INT_STATUS_UNSUPPORTED;
     79 +
     80 +	if (color_comps != 3 && color_comps != 1)
     81 +	    return CAIRO_INT_STATUS_UNSUPPORTED;
     82 +
     83 +	if (bpp == 32 && color_comps == 3 &&
     84 +	    (bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst &&
     85 +	    (bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host)
     86 +	{
     87 +	    isurf = (cairo_image_surface_t *)
     88 +		cairo_image_surface_create_for_data (imageData,
     89 +						     CAIRO_FORMAT_ARGB32,
     90 +						     surface->extents.width,
     91 +						     surface->extents.height,
     92 +						     stride);
     93 +	} else if (bpp == 32 && color_comps == 3 &&
     94 +		   (bitinfo & kCGBitmapAlphaInfoMask) == kCGImageAlphaNoneSkipFirst &&
     95 +		   (bitinfo & kCGBitmapByteOrderMask) == kCGBitmapByteOrder32Host)
     96 +	{
     97 +	    isurf = (cairo_image_surface_t *)
     98 +		cairo_image_surface_create_for_data (imageData,
     99 +						     CAIRO_FORMAT_RGB24,
    100 +						     surface->extents.width,
    101 +						     surface->extents.height,
    102 +						     stride);
    103 +	} else if (bpp == 8 && color_comps == 1)
    104 +	{
    105 +	    isurf = (cairo_image_surface_t *)
    106 +		cairo_image_surface_create_for_data (imageData,
    107 +						     CAIRO_FORMAT_A8,
    108 +						     surface->extents.width,
    109 +						     surface->extents.height,
    110 +						     stride);
    111 +	} else {
    112 +	    return CAIRO_INT_STATUS_UNSUPPORTED;
    113 +	}
    114 +    } else {
    115 +	return CAIRO_INT_STATUS_UNSUPPORTED;
    116 +    }
    117 +
    118 +    *image_out = isurf;
    119 +    return CAIRO_STATUS_SUCCESS;
    120 +}
    121 +
    122 +
    123 +/*
    124  * Cairo surface backend implementations
    125  */
    126 
    127 @@ -2478,3 +2570,15 @@ cairo_status_t
    128     CGImageRelease (image);
    129     return CAIRO_STATUS_SUCCESS;
    130 }
    131 +
    132 +cairo_surface_t *
    133 +cairo_quartz_surface_get_image (cairo_surface_t *surface)
    134 +{
    135 +    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t *)surface;
    136 +    cairo_image_surface_t *image;
    137 +
    138 +    if (_cairo_quartz_get_image(quartz, &image))
    139 +        return NULL;
    140 +
    141 +    return (cairo_surface_t *)image;
    142 +}
    143 diff --git a/gfx/cairo/cairo/src/cairo-quartz.h b/gfx/cairo/cairo/src/cairo-quartz.h
    144 --- a/gfx/cairo/cairo/src/cairo-quartz.h
    145 +++ b/gfx/cairo/cairo/src/cairo-quartz.h
    146 @@ -57,6 +57,9 @@ cairo_quartz_surface_create_for_cg_conte
    147 cairo_public CGContextRef
    148 cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
    149 
    150 +cairo_public cairo_surface_t *
    151 +cairo_quartz_surface_get_image (cairo_surface_t *surface);
    152 +
    153 #if CAIRO_HAS_QUARTZ_FONT
    154 
    155 /*