Bug 545892 - Always pass WM_NCPAINT events to the default event procedure. r=bent...
[mozilla-central.git] / gfx / cairo / native-clipping.patch
blob171998fe7c3f148ff6cbf949c3e33650347ee7f9
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;
24 +CGContextRef
25 +cairo_quartz_get_cg_context_with_clip (cairo_t *cr)
28 + cairo_surface_t *surface = cr->gstate->target;
29 + cairo_clip_t *clip = &cr->gstate->clip;
30 + cairo_status_t status;
32 + cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
34 + if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
35 + return NULL;
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);
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);
48 + return quartz->cgContext;
49 + }
51 + /* an empty clip is represented by NULL */
52 + clip = NULL;
53 + }
55 + status = _cairo_surface_clipper_set_clip (&quartz->clipper, clip);
57 + /* Save the state after we set the clip so that it persists
58 + * after we restore */
59 + CGContextSaveGState (quartz->cgContext);
61 + if (unlikely (status))
62 + return NULL;
64 + return quartz->cgContext;
67 +void
68 +cairo_quartz_finish_cg_context_with_clip (cairo_t *cr)
70 + cairo_surface_t *surface = cr->gstate->target;
72 + cairo_quartz_surface_t *quartz = (cairo_quartz_surface_t*)surface;
74 + if (cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_QUARTZ)
75 + return;
77 + CGContextRestoreGState (quartz->cgContext);
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);
93 +cairo_public void
94 +cairo_quartz_finish_cg_context_with_clip (cairo_t *cr);
96 #if CAIRO_HAS_QUARTZ_FONT
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"
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;
119 +HDC
120 +cairo_win32_get_dc_with_clip (cairo_t *cr)
122 + cairo_surface_t *surface = cr->gstate->target;
123 + cairo_clip_t clip;
124 + _cairo_clip_init_copy(&clip, &cr->gstate->clip);
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;
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;
139 + _cairo_win32_surface_set_clip_region (winsurf, clip_region);
141 + _cairo_clip_fini(&clip);
142 + return winsurf->dc;
145 + if (_cairo_surface_is_paginated (surface)) {
146 + cairo_surface_t *target;
148 + target = _cairo_paginated_surface_get_target (surface);
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;
155 + status = _cairo_surface_clipper_set_clip (&winsurf->clipper, &clip);
157 + _cairo_clip_fini(&clip);
159 + if (status)
160 + return NULL;
162 + return winsurf->dc;
164 +#endif
167 + _cairo_clip_fini(&clip);
168 + return NULL;
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);
187 cairo_public cairo_surface_t *
188 cairo_win32_surface_get_image (cairo_surface_t *surface);