gfx/cairo/native-clipping.patch

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial