gfx/cairo/cairo-x-visual.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 -r c1195334f839 gfx/cairo/cairo/src/cairo-xlib-surface.c
     2 --- a/gfx/cairo/cairo/src/cairo-xlib-surface.c	Fri May 21 17:42:55 2010 +0300
     3 +++ b/gfx/cairo/cairo/src/cairo-xlib-surface.c	Fri May 21 19:12:29 2010 +0300
     4 @@ -189,16 +189,57 @@ static const XTransform identity = { {
     6  #define CAIRO_SURFACE_RENDER_HAS_PDF_OPERATORS(surface)	CAIRO_SURFACE_RENDER_AT_LEAST((surface), 0, 11)
     8  #define CAIRO_SURFACE_RENDER_SUPPORTS_OPERATOR(surface, op)	\
     9       ((op) <= CAIRO_OPERATOR_SATURATE ||			\
    10        (CAIRO_SURFACE_RENDER_HAS_PDF_OPERATORS(surface) &&	\
    11         (op) <= CAIRO_OPERATOR_HSL_LUMINOSITY))
    13 +static Visual *
    14 +_visual_for_xrender_format(Screen *screen,
    15 +			    XRenderPictFormat *xrender_format)
    16 +{
    17 +    int d, v;
    18 +    for (d = 0; d < screen->ndepths; d++) {
    19 +	Depth *d_info = &screen->depths[d];
    20 +	if (d_info->depth != xrender_format->depth)
    21 +	    continue;
    22 +
    23 +	for (v = 0; v < d_info->nvisuals; v++) {
    24 +	    Visual *visual = &d_info->visuals[v];
    25 +
    26 +	    switch (visual->class) {
    27 +	    case TrueColor:
    28 +		if (xrender_format->type != PictTypeDirect)
    29 +		    continue;
    30 +		break;
    31 +	    case DirectColor:
    32 +		/* Prefer TrueColor to DirectColor.
    33 +		   (XRenderFindVisualFormat considers both TrueColor and
    34 +		   DirectColor Visuals to match the same PictFormat.) */
    35 +		continue;
    36 +	    case StaticGray:
    37 +	    case GrayScale:
    38 +	    case StaticColor:
    39 +	    case PseudoColor:
    40 +		if (xrender_format->type != PictTypeIndexed)
    41 +		    continue;
    42 +		break;
    43 +	    }
    44 +
    45 +	    if (xrender_format ==
    46 +		XRenderFindVisualFormat (DisplayOfScreen(screen), visual))
    47 +		return visual;
    48 +	}
    49 +    }
    50 +
    51 +    return NULL;
    52 +}
    53 +
    54  static cairo_status_t
    55  _cairo_xlib_surface_set_clip_region (cairo_xlib_surface_t *surface,
    56  				     cairo_region_t *region)
    57  {
    58      cairo_bool_t had_clip_rects = surface->clip_region != NULL;
    60      if (had_clip_rects == FALSE && region == NULL)
    61  	return CAIRO_STATUS_SUCCESS;
    62 @@ -313,16 +354,19 @@ _cairo_xlib_surface_create_similar (void
    63  	 * visual/depth etc. as possible. */
    64  	pix = XCreatePixmap (src->dpy, src->drawable,
    65  			     width <= 0 ? 1 : width, height <= 0 ? 1 : height,
    66  			     xrender_format->depth);
    68  	visual = NULL;
    69  	if (xrender_format == src->xrender_format)
    70  	    visual = src->visual;
    71 +	else
    72 +	    visual = _visual_for_xrender_format(src->screen->screen,
    73 +					        xrender_format);
    75  	surface = (cairo_xlib_surface_t *)
    76  		  _cairo_xlib_surface_create_internal (src->screen, pix,
    77  						       visual,
    78  						       xrender_format,
    79  						       width, height,
    80  						       xrender_format->depth);
    81      }
    82 @@ -3178,28 +3222,32 @@ cairo_xlib_surface_create_with_xrender_f
    83  					       Screen		    *scr,
    84  					       XRenderPictFormat    *format,
    85  					       int		    width,
    86  					       int		    height)
    87  {
    88      cairo_xlib_screen_t *screen;
    89      cairo_surface_t *surface;
    90      cairo_status_t status;
    91 +    Visual *visual;
    93      if (width > XLIB_COORD_MAX || height > XLIB_COORD_MAX)
    94  	return _cairo_surface_create_in_error (CAIRO_STATUS_INVALID_SIZE);
    96      status = _cairo_xlib_screen_get (dpy, scr, &screen);
    97      if (unlikely (status))
    98  	return _cairo_surface_create_in_error (status);
   100      X_DEBUG ((dpy, "create_with_xrender_format (drawable=%x)", (unsigned int) drawable));
   102 +    if (format)
   103 +    visual = _visual_for_xrender_format (scr, format);
   104 +
   105      surface = _cairo_xlib_surface_create_internal (screen, drawable,
   106 -						   NULL, format,
   107 +						   visual, format,
   108  						   width, height, 0);
   109      _cairo_xlib_screen_destroy (screen);
   111      return surface;
   112  }
   113  slim_hidden_def (cairo_xlib_surface_create_with_xrender_format);
   115  /**
   116 @@ -3413,33 +3461,37 @@ cairo_xlib_surface_get_screen (cairo_sur
   118      return surface->screen->screen;
   119  }
   121  /**
   122   * cairo_xlib_surface_get_visual:
   123   * @surface: a #cairo_xlib_surface_t
   124   *
   125 - * Get the X Visual used for underlying X Drawable.
   126 + * Gets the X Visual associated with @surface, suitable for use with the
   127 + * underlying X Drawable.  If @surface was created by
   128 + * cairo_xlib_surface_create(), the return value is the Visual passed to that
   129 + * constructor.
   130   *
   131 - * Return value: the visual.
   132 + * Return value: the Visual or %NULL if there is no appropriate Visual for
   133 + * @surface.
   134   *
   135   * Since: 1.2
   136   **/
   137  Visual *
   138 -cairo_xlib_surface_get_visual (cairo_surface_t *abstract_surface)
   139 +cairo_xlib_surface_get_visual (cairo_surface_t *surface)
   140  {
   141 -    cairo_xlib_surface_t *surface = (cairo_xlib_surface_t *) abstract_surface;
   142 -
   143 -    if (! _cairo_surface_is_xlib (abstract_surface)) {
   144 +    cairo_xlib_surface_t *xlib_surface = (cairo_xlib_surface_t *) surface;
   145 +
   146 +    if (! _cairo_surface_is_xlib (surface)) {
   147  	_cairo_error_throw (CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
   148  	return NULL;
   149      }
   151 -    return surface->visual;
   152 +    return xlib_surface->visual;
   153  }
   155  /**
   156   * cairo_xlib_surface_get_depth:
   157   * @surface: a #cairo_xlib_surface_t
   158   *
   159   * Get the number of bits used to represent each pixel value.
   160   *

mercurial