gfx/cairo/native-clipping.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 commit 857df0583365228150b3319475efc43b22077d06
     2 Author: Jeff Muizelaar <jmuizelaar@mozilla.com>
     3 Date:   Tue Apr 20 15:43:54 2010 -0400
     5     native clipping
     7 diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
     8 index df063bf..819e53e 100644
     9 --- a/src/cairo-quartz-surface.c
    10 +++ b/src/cairo-quartz-surface.c
    11 @@ -39,6 +39,8 @@
    13  #include "cairo-quartz-private.h"
    14  #include "cairo-surface-clipper-private.h"
    15 +#include "cairo-gstate-private.h"
    16 +#include "cairo-private.h"
    18  #include <dlfcn.h>
    20 @@ -3095,6 +3097,61 @@ cairo_quartz_surface_get_cg_context (cairo_surface_t *surface)
    21      return quartz->cgContext;
    22  }
    24 +CGContextRef
    25 +cairo_quartz_get_cg_context_with_clip (cairo_t *cr)
    26 +{
    27 +
    28 +    cairo_surface_t *surface = cr->gstate->target;
    29 +    cairo_clip_t *clip = &cr->gstate->clip;
    30 +    cairo_status_t status;
    31 +
    32 +    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
    33 +
    34 +    if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
    35 +	return NULL;
    36 +
    37 +    if (!clip->path) {
    38 +	if (clip->all_clipped) {
    39 +	    /* Save the state before we set an empty clip rect so that
    40 +	     * our previous clip will be restored */
    41 +	    CGContextSaveGState (quartz->cgContext);
    42 +
    43 +	    /* _cairo_surface_clipper_set_clip doesn't deal with
    44 +	     * clip->all_clipped because drawing is normally discarded earlier */
    45 +	    CGRect empty = {{0,0}, {0,0}};
    46 +	    CGContextClipToRect (quartz->cgContext, empty);
    47 +
    48 +	    return quartz->cgContext;
    49 +	}
    50 +
    51 +	/* an empty clip is represented by NULL */
    52 +	clip = NULL;
    53 +    }
    54 +
    55 +    status = _cairo_surface_clipper_set_clip (&quartz->clipper, clip);
    56 +
    57 +    /* Save the state after we set the clip so that it persists
    58 +     * after we restore */
    59 +    CGContextSaveGState (quartz->cgContext);
    60 +
    61 +    if (unlikely (status))
    62 +	return NULL;
    63 +
    64 +    return quartz->cgContext;
    65 +}
    66 +
    67 +void
    68 +cairo_quartz_finish_cg_context_with_clip (cairo_t *cr)
    69 +{
    70 +    cairo_surface_t *surface = cr->gstate->target;
    71 +
    72 +    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
    73 +
    74 +    if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
    75 +	return;
    76 +
    77 +    CGContextRestoreGState (quartz->cgContext);
    78 +}
    80  /* Debug stuff */
    82 diff --git a/src/cairo-quartz.h b/src/cairo-quartz.h
    83 index e8b71ba..aa1cdd2 100644
    84 --- a/src/cairo-quartz.h
    85 +++ b/src/cairo-quartz.h
    86 @@ -57,6 +57,12 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
    87  cairo_public CGContextRef
    88  cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
    90 +cairo_public CGContextRef
    91 +cairo_quartz_get_cg_context_with_clip (cairo_t *cr);
    92 +
    93 +cairo_public void
    94 +cairo_quartz_finish_cg_context_with_clip (cairo_t *cr);
    95 +
    96  #if CAIRO_HAS_QUARTZ_FONT
    98  /*
    99 diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
   100 index d4575a3..c10e134 100644
   101 --- a/src/cairo-win32-surface.c
   102 +++ b/src/cairo-win32-surface.c
   103 @@ -52,7 +52,9 @@
   104  #include "cairo-win32-private.h"
   105  #include "cairo-scaled-font-subsets-private.h"
   106  #include "cairo-surface-fallback-private.h"
   107 -
   108 +#include "cairo-surface-clipper-private.h"
   109 +#include "cairo-gstate-private.h"
   110 +#include "cairo-private.h"
   111  #include <wchar.h>
   112  #include <windows.h>
   114 @@ -1914,6 +1916,61 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
   115      return NULL;
   116  }
   118 +
   119 +HDC
   120 +cairo_win32_get_dc_with_clip (cairo_t *cr)
   121 +{
   122 +    cairo_surface_t *surface = cr->gstate->target;
   123 +    cairo_clip_t clip;
   124 +    _cairo_clip_init_copy(&clip, &cr->gstate->clip);
   125 +
   126 +    if (_cairo_surface_is_win32 (surface)){
   127 +	cairo_win32_surface_t *winsurf = (cairo_win32_surface_t *) surface;
   128 +	cairo_region_t *clip_region = NULL;
   129 +	cairo_status_t status;
   130 +
   131 +	if (clip.path) {
   132 +	    status = _cairo_clip_get_region (&clip, &clip_region);
   133 +	    assert (status != CAIRO_INT_STATUS_NOTHING_TO_DO);
   134 +	    if (status) {
   135 +		_cairo_clip_fini(&clip);
   136 +		return NULL;
   137 +	    }
   138 +	}
   139 +	_cairo_win32_surface_set_clip_region (winsurf, clip_region);
   140 +
   141 +	_cairo_clip_fini(&clip);
   142 +	return winsurf->dc;
   143 +    }
   144 +
   145 +    if (_cairo_surface_is_paginated (surface)) {
   146 +	cairo_surface_t *target;
   147 +
   148 +	target = _cairo_paginated_surface_get_target (surface);
   149 +
   150 +#ifndef CAIRO_OMIT_WIN32_PRINTING
   151 +	if (_cairo_surface_is_win32_printing (target)) {
   152 +	    cairo_status_t status;
   153 +	    cairo_win32_surface_t *winsurf = (cairo_win32_surface_t *) target;
   154 +
   155 +	    status = _cairo_surface_clipper_set_clip (&winsurf->clipper, &clip);
   156 +
   157 +	    _cairo_clip_fini(&clip);
   158 +
   159 +	    if (status)
   160 +		return NULL;
   161 +
   162 +	    return winsurf->dc;
   163 +	}
   164 +#endif
   165 +    }
   166 +
   167 +    _cairo_clip_fini(&clip);
   168 +    return NULL;
   169 +}
   170 +
   171 +
   172 +
   173  /**
   174   * cairo_win32_surface_get_image
   175   * @surface: a #cairo_surface_t
   176 diff --git a/src/cairo-win32.h b/src/cairo-win32.h
   177 index 7d04d2a..c304f92 100644
   178 --- a/src/cairo-win32.h
   179 +++ b/src/cairo-win32.h
   180 @@ -65,6 +65,9 @@ cairo_win32_surface_create_with_dib (cairo_format_t format,
   181  cairo_public HDC
   182  cairo_win32_surface_get_dc (cairo_surface_t *surface);
   184 +cairo_public HDC
   185 +cairo_win32_get_dc_with_clip (cairo_t *cr);
   186 +
   187  cairo_public cairo_surface_t *
   188  cairo_win32_surface_get_image (cairo_surface_t *surface);

mercurial