DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (31ec81b5d7bb)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
commit 857df0583365228150b3319475efc43b22077d06
Author: Jeff Muizelaar <jmuizelaar@mozilla.com>
Date:   Tue Apr 20 15:43:54 2010 -0400

    native clipping

diff --git a/src/cairo-quartz-surface.c b/src/cairo-quartz-surface.c
index df063bf..819e53e 100644
--- a/src/cairo-quartz-surface.c
+++ b/src/cairo-quartz-surface.c
@@ -39,6 +39,8 @@
 
 #include "cairo-quartz-private.h"
 #include "cairo-surface-clipper-private.h"
+#include "cairo-gstate-private.h"
+#include "cairo-private.h"
 
 #include <dlfcn.h>
 
@@ -3095,6 +3097,61 @@ cairo_quartz_surface_get_cg_context (cairo_surface_t *surface)
     return quartz->cgContext;
 }
 
+CGContextRef
+cairo_quartz_get_cg_context_with_clip (cairo_t *cr)
+{
+
+    cairo_surface_t *surface = cr->gstate->target;
+    cairo_clip_t *clip = &cr->gstate->clip;
+    cairo_status_t status;
+
+    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
+
+    if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
+	return NULL;
+
+    if (!clip->path) {
+	if (clip->all_clipped) {
+	    /* Save the state before we set an empty clip rect so that
+	     * our previous clip will be restored */
+	    CGContextSaveGState (quartz->cgContext);
+
+	    /* _cairo_surface_clipper_set_clip doesn't deal with
+	     * clip->all_clipped because drawing is normally discarded earlier */
+	    CGRect empty = {{0,0}, {0,0}};
+	    CGContextClipToRect (quartz->cgContext, empty);
+
+	    return quartz->cgContext;
+	}
+
+	/* an empty clip is represented by NULL */
+	clip = NULL;
+    }
+
+    status = _cairo_surface_clipper_set_clip (&quartz->clipper, clip);
+
+    /* Save the state after we set the clip so that it persists
+     * after we restore */
+    CGContextSaveGState (quartz->cgContext);
+
+    if (unlikely (status))
+	return NULL;
+
+    return quartz->cgContext;
+}
+
+void
+cairo_quartz_finish_cg_context_with_clip (cairo_t *cr)
+{
+    cairo_surface_t *surface = cr->gstate->target;
+
+    cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
+
+    if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
+	return;
+
+    CGContextRestoreGState (quartz->cgContext);
+}
 
 /* Debug stuff */
 
diff --git a/src/cairo-quartz.h b/src/cairo-quartz.h
index e8b71ba..aa1cdd2 100644
--- a/src/cairo-quartz.h
+++ b/src/cairo-quartz.h
@@ -57,6 +57,12 @@ cairo_quartz_surface_create_for_cg_context (CGContextRef cgContext,
 cairo_public CGContextRef
 cairo_quartz_surface_get_cg_context (cairo_surface_t *surface);
 
+cairo_public CGContextRef
+cairo_quartz_get_cg_context_with_clip (cairo_t *cr);
+
+cairo_public void
+cairo_quartz_finish_cg_context_with_clip (cairo_t *cr);
+
 #if CAIRO_HAS_QUARTZ_FONT
 
 /*
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index d4575a3..c10e134 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -52,7 +52,9 @@
 #include "cairo-win32-private.h"
 #include "cairo-scaled-font-subsets-private.h"
 #include "cairo-surface-fallback-private.h"
-
+#include "cairo-surface-clipper-private.h"
+#include "cairo-gstate-private.h"
+#include "cairo-private.h"
 #include <wchar.h>
 #include <windows.h>
 
@@ -1914,6 +1916,61 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface)
     return NULL;
 }
 
+
+HDC
+cairo_win32_get_dc_with_clip (cairo_t *cr)
+{
+    cairo_surface_t *surface = cr->gstate->target;
+    cairo_clip_t clip;
+    _cairo_clip_init_copy(&clip, &cr->gstate->clip);
+
+    if (_cairo_surface_is_win32 (surface)){
+	cairo_win32_surface_t *winsurf = (cairo_win32_surface_t *) surface;
+	cairo_region_t *clip_region = NULL;
+	cairo_status_t status;
+
+	if (clip.path) {
+	    status = _cairo_clip_get_region (&clip, &clip_region);
+	    assert (status != CAIRO_INT_STATUS_NOTHING_TO_DO);
+	    if (status) {
+		_cairo_clip_fini(&clip);
+		return NULL;
+	    }
+	}
+	_cairo_win32_surface_set_clip_region (winsurf, clip_region);
+
+	_cairo_clip_fini(&clip);
+	return winsurf->dc;
+    }
+
+    if (_cairo_surface_is_paginated (surface)) {
+	cairo_surface_t *target;
+
+	target = _cairo_paginated_surface_get_target (surface);
+
+#ifndef CAIRO_OMIT_WIN32_PRINTING
+	if (_cairo_surface_is_win32_printing (target)) {
+	    cairo_status_t status;
+	    cairo_win32_surface_t *winsurf = (cairo_win32_surface_t *) target;
+
+	    status = _cairo_surface_clipper_set_clip (&winsurf->clipper, &clip);
+
+	    _cairo_clip_fini(&clip);
+
+	    if (status)
+		return NULL;
+
+	    return winsurf->dc;
+	}
+#endif
+    }
+
+    _cairo_clip_fini(&clip);
+    return NULL;
+}
+
+
+
 /**
  * cairo_win32_surface_get_image
  * @surface: a #cairo_surface_t
diff --git a/src/cairo-win32.h b/src/cairo-win32.h
index 7d04d2a..c304f92 100644
--- a/src/cairo-win32.h
+++ b/src/cairo-win32.h
@@ -65,6 +65,9 @@ cairo_win32_surface_create_with_dib (cairo_format_t format,
 cairo_public HDC
 cairo_win32_surface_get_dc (cairo_surface_t *surface);
 
+cairo_public HDC
+cairo_win32_get_dc_with_clip (cairo_t *cr);
+
 cairo_public cairo_surface_t *
 cairo_win32_surface_get_image (cairo_surface_t *surface);