Bug 545892 - Always pass WM_NCPAINT events to the default event procedure. r=bent...
[mozilla-central.git] / gfx / cairo / d2d.patch
blob83db386254d016333d83becbbb99e917518c441c
1 commit 4a412c0b144ed1fdde668e0e91241bac8bedd579
2 Author: Jeff Muizelaar <jmuizelaar@mozilla.com>
3 Date: Sun Jan 24 14:04:33 2010 -0500
5 d2d
7 diff --git a/src/cairo-fixed-private.h b/src/cairo-fixed-private.h
8 index c299def..a37ca6a 100644
9 --- a/src/cairo-fixed-private.h
10 +++ b/src/cairo-fixed-private.h
11 @@ -50,6 +50,7 @@
13 #define CAIRO_FIXED_ONE ((cairo_fixed_t)(1 << CAIRO_FIXED_FRAC_BITS))
14 #define CAIRO_FIXED_ONE_DOUBLE ((double)(1 << CAIRO_FIXED_FRAC_BITS))
15 +#define CAIRO_FIXED_ONE_FLOAT ((float)(1 << CAIRO_FIXED_FRAC_BITS))
16 #define CAIRO_FIXED_EPSILON ((cairo_fixed_t)(1))
18 #define CAIRO_FIXED_FRAC_MASK (((cairo_fixed_unsigned_t)(-1)) >> (CAIRO_FIXED_BITS - CAIRO_FIXED_FRAC_BITS))
19 @@ -141,6 +142,12 @@ _cairo_fixed_to_double (cairo_fixed_t f)
20 return ((double) f) / CAIRO_FIXED_ONE_DOUBLE;
23 +static inline float
24 +_cairo_fixed_to_float (cairo_fixed_t f)
26 + return ((float) f) / CAIRO_FIXED_ONE_FLOAT;
29 static inline int
30 _cairo_fixed_is_integer (cairo_fixed_t f)
32 diff --git a/src/cairo-win32-private.h b/src/cairo-win32-private.h
33 index b9926bb..ba57595 100644
34 --- a/src/cairo-win32-private.h
35 +++ b/src/cairo-win32-private.h
36 @@ -231,4 +231,19 @@ inline BOOL ModifyWorldTransform(HDC hdc, CONST XFORM * lpxf, DWORD mode) { retu
38 #endif
40 +#ifdef CAIRO_HAS_DWRITE_FONT
41 +CAIRO_BEGIN_DECLS
43 +cairo_public cairo_int_status_t
44 +cairo_dwrite_show_glyphs_on_surface(void *surface,
45 + cairo_operator_t op,
46 + const cairo_pattern_t *source,
47 + cairo_glyph_t *glyphs,
48 + int num_glyphs,
49 + cairo_scaled_font_t *scaled_font,
50 + cairo_rectangle_int_t *extents);
53 +CAIRO_END_DECLS
54 +#endif /* CAIRO_HAS_DWRITE_FONT */
55 #endif /* CAIRO_WIN32_PRIVATE_H */
56 diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
57 index 0dc5e76..bee00b1 100644
58 --- a/src/cairo-win32-surface.c
59 +++ b/src/cairo-win32-surface.c
60 @@ -1547,152 +1547,158 @@ _cairo_win32_surface_show_glyphs (void *surface,
61 int *remaining_glyphs)
63 #if defined(CAIRO_HAS_WIN32_FONT) && !defined(WINCE)
64 - cairo_win32_surface_t *dst = surface;
66 - WORD glyph_buf_stack[STACK_GLYPH_SIZE];
67 - WORD *glyph_buf = glyph_buf_stack;
68 - int dxy_buf_stack[2 * STACK_GLYPH_SIZE];
69 - int *dxy_buf = dxy_buf_stack;
71 - BOOL win_result = 0;
72 - int i, j;
73 + if (scaled_font->backend->type == CAIRO_FONT_TYPE_DWRITE) {
74 +#ifdef CAIRO_HAS_DWRITE_FONT
75 + return cairo_dwrite_show_glyphs_on_surface(surface, op, source, glyphs, num_glyphs, scaled_font, clip);
76 +#endif
77 + } else {
78 + cairo_win32_surface_t *dst = surface;
80 + WORD glyph_buf_stack[STACK_GLYPH_SIZE];
81 + WORD *glyph_buf = glyph_buf_stack;
82 + int dxy_buf_stack[2 * STACK_GLYPH_SIZE];
83 + int *dxy_buf = dxy_buf_stack;
85 - cairo_solid_pattern_t *solid_pattern;
86 - COLORREF color;
87 + BOOL win_result = 0;
88 + int i, j;
90 - cairo_matrix_t device_to_logical;
91 + cairo_solid_pattern_t *solid_pattern;
92 + COLORREF color;
94 - int start_x, start_y;
95 - double user_x, user_y;
96 - int logical_x, logical_y;
97 - unsigned int glyph_index_option;
98 + cairo_matrix_t device_to_logical;
100 - /* We can only handle win32 fonts */
101 - if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_WIN32)
102 - return CAIRO_INT_STATUS_UNSUPPORTED;
103 + int start_x, start_y;
104 + double user_x, user_y;
105 + int logical_x, logical_y;
106 + unsigned int glyph_index_option;
108 - /* We can only handle opaque solid color sources */
109 - if (!_cairo_pattern_is_opaque_solid(source))
110 - return CAIRO_INT_STATUS_UNSUPPORTED;
111 + /* We can only handle win32 fonts */
112 + if (cairo_scaled_font_get_type (scaled_font) != CAIRO_FONT_TYPE_WIN32)
113 + return CAIRO_INT_STATUS_UNSUPPORTED;
115 - /* We can only handle operator SOURCE or OVER with the destination
116 - * having no alpha */
117 - if ((op != CAIRO_OPERATOR_SOURCE && op != CAIRO_OPERATOR_OVER) ||
118 - (dst->format != CAIRO_FORMAT_RGB24))
119 - return CAIRO_INT_STATUS_UNSUPPORTED;
120 + /* We can only handle opaque solid color sources */
121 + if (!_cairo_pattern_is_opaque_solid(source))
122 + return CAIRO_INT_STATUS_UNSUPPORTED;
124 - /* If we have a fallback mask clip set on the dst, we have
125 - * to go through the fallback path, but only if we're not
126 - * doing this for printing */
127 - if (clip != NULL) {
128 - if ((dst->flags & CAIRO_WIN32_SURFACE_FOR_PRINTING) == 0) {
129 - cairo_region_t *clip_region;
130 - cairo_status_t status;
131 + /* We can only handle operator SOURCE or OVER with the destination
132 + * having no alpha */
133 + if ((op != CAIRO_OPERATOR_SOURCE && op != CAIRO_OPERATOR_OVER) ||
134 + (dst->format != CAIRO_FORMAT_RGB24))
135 + return CAIRO_INT_STATUS_UNSUPPORTED;
137 - status = _cairo_clip_get_region (clip, &clip_region);
138 - assert (status != CAIRO_INT_STATUS_NOTHING_TO_DO);
139 - if (status)
140 - return status;
141 + /* If we have a fallback mask clip set on the dst, we have
142 + * to go through the fallback path, but only if we're not
143 + * doing this for printing */
144 + if (clip != NULL) {
145 + if ((dst->flags & CAIRO_WIN32_SURFACE_FOR_PRINTING) == 0) {
146 + cairo_region_t *clip_region;
147 + cairo_status_t status;
149 + status = _cairo_clip_get_region (clip, &clip_region);
150 + assert (status != CAIRO_INT_STATUS_NOTHING_TO_DO);
151 + if (status)
152 + return status;
154 - _cairo_win32_surface_set_clip_region (surface, clip_region);
155 + _cairo_win32_surface_set_clip_region (surface, clip_region);
160 - solid_pattern = (cairo_solid_pattern_t *)source;
161 - color = RGB(((int)solid_pattern->color.red_short) >> 8,
162 - ((int)solid_pattern->color.green_short) >> 8,
163 - ((int)solid_pattern->color.blue_short) >> 8);
164 + solid_pattern = (cairo_solid_pattern_t *)source;
165 + color = RGB(((int)solid_pattern->color.red_short) >> 8,
166 + ((int)solid_pattern->color.green_short) >> 8,
167 + ((int)solid_pattern->color.blue_short) >> 8);
169 - cairo_win32_scaled_font_get_device_to_logical(scaled_font, &device_to_logical);
170 + cairo_win32_scaled_font_get_device_to_logical(scaled_font, &device_to_logical);
172 - SaveDC(dst->dc);
173 + SaveDC(dst->dc);
175 - cairo_win32_scaled_font_select_font(scaled_font, dst->dc);
176 - SetTextColor(dst->dc, color);
177 - SetTextAlign(dst->dc, TA_BASELINE | TA_LEFT);
178 - SetBkMode(dst->dc, TRANSPARENT);
179 + cairo_win32_scaled_font_select_font(scaled_font, dst->dc);
180 + SetTextColor(dst->dc, color);
181 + SetTextAlign(dst->dc, TA_BASELINE | TA_LEFT);
182 + SetBkMode(dst->dc, TRANSPARENT);
184 - if (num_glyphs > STACK_GLYPH_SIZE) {
185 - glyph_buf = (WORD *) _cairo_malloc_ab (num_glyphs, sizeof(WORD));
186 - dxy_buf = (int *) _cairo_malloc_abc (num_glyphs, sizeof(int), 2);
188 + if (num_glyphs > STACK_GLYPH_SIZE) {
189 + glyph_buf = (WORD *) _cairo_malloc_ab (num_glyphs, sizeof(WORD));
190 + dxy_buf = (int *) _cairo_malloc_abc (num_glyphs, sizeof(int), 2);
193 - /* It is vital that dx values for dxy_buf are calculated from the delta of
194 - * _logical_ x coordinates (not user x coordinates) or else the sum of all
195 - * previous dx values may start to diverge from the current glyph's x
196 - * coordinate due to accumulated rounding error. As a result strings could
197 - * be painted shorter or longer than expected. */
198 + /* It is vital that dx values for dxy_buf are calculated from the delta of
199 + * _logical_ x coordinates (not user x coordinates) or else the sum of all
200 + * previous dx values may start to diverge from the current glyph's x
201 + * coordinate due to accumulated rounding error. As a result strings could
202 + * be painted shorter or longer than expected. */
204 - user_x = glyphs[0].x;
205 - user_y = glyphs[0].y;
206 + user_x = glyphs[0].x;
207 + user_y = glyphs[0].y;
209 - cairo_matrix_transform_point(&device_to_logical,
210 - &user_x, &user_y);
211 + cairo_matrix_transform_point(&device_to_logical,
212 + &user_x, &user_y);
214 - logical_x = _cairo_lround (user_x);
215 - logical_y = _cairo_lround (user_y);
216 + logical_x = _cairo_lround (user_x);
217 + logical_y = _cairo_lround (user_y);
219 - start_x = logical_x;
220 - start_y = logical_y;
221 + start_x = logical_x;
222 + start_y = logical_y;
224 - for (i = 0, j = 0; i < num_glyphs; ++i, j = 2 * i) {
225 - glyph_buf[i] = (WORD) glyphs[i].index;
226 - if (i == num_glyphs - 1) {
227 - dxy_buf[j] = 0;
228 - dxy_buf[j+1] = 0;
229 - } else {
230 - double next_user_x = glyphs[i+1].x;
231 - double next_user_y = glyphs[i+1].y;
232 - int next_logical_x, next_logical_y;
233 + for (i = 0, j = 0; i < num_glyphs; ++i, j = 2 * i) {
234 + glyph_buf[i] = (WORD) glyphs[i].index;
235 + if (i == num_glyphs - 1) {
236 + dxy_buf[j] = 0;
237 + dxy_buf[j+1] = 0;
238 + } else {
239 + double next_user_x = glyphs[i+1].x;
240 + double next_user_y = glyphs[i+1].y;
241 + int next_logical_x, next_logical_y;
243 - cairo_matrix_transform_point(&device_to_logical,
244 - &next_user_x, &next_user_y);
245 + cairo_matrix_transform_point(&device_to_logical,
246 + &next_user_x, &next_user_y);
248 - next_logical_x = _cairo_lround (next_user_x);
249 - next_logical_y = _cairo_lround (next_user_y);
250 + next_logical_x = _cairo_lround (next_user_x);
251 + next_logical_y = _cairo_lround (next_user_y);
253 - dxy_buf[j] = _cairo_lround (next_logical_x - logical_x);
254 - dxy_buf[j+1] = _cairo_lround (logical_y - next_logical_y);
255 - /* note that GDI coordinate system is inverted */
256 + dxy_buf[j] = _cairo_lround (next_logical_x - logical_x);
257 + dxy_buf[j+1] = _cairo_lround (logical_y - next_logical_y);
258 + /* note that GDI coordinate system is inverted */
260 - logical_x = next_logical_x;
261 - logical_y = next_logical_y;
264 + logical_x = next_logical_x;
265 + logical_y = next_logical_y;
269 - /* Using glyph indices for a Type 1 font does not work on a
270 - * printer DC. The win32 printing surface will convert the the
271 - * glyph indices of Type 1 fonts to the unicode values.
272 - */
273 - if ((dst->flags & CAIRO_WIN32_SURFACE_FOR_PRINTING) &&
274 - _cairo_win32_scaled_font_is_type1 (scaled_font))
276 - glyph_index_option = 0;
278 - else
280 - glyph_index_option = ETO_GLYPH_INDEX;
282 + /* Using glyph indices for a Type 1 font does not work on a
283 + * printer DC. The win32 printing surface will convert the the
284 + * glyph indices of Type 1 fonts to the unicode values.
285 + */
286 + if ((dst->flags & CAIRO_WIN32_SURFACE_FOR_PRINTING) &&
287 + _cairo_win32_scaled_font_is_type1 (scaled_font))
289 + glyph_index_option = 0;
291 + else
293 + glyph_index_option = ETO_GLYPH_INDEX;
296 - win_result = ExtTextOutW(dst->dc,
297 - start_x,
298 - start_y,
299 - glyph_index_option | ETO_PDY,
300 - NULL,
301 - glyph_buf,
302 - num_glyphs,
303 - dxy_buf);
304 - if (!win_result) {
305 - _cairo_win32_print_gdi_error("_cairo_win32_surface_show_glyphs(ExtTextOutW failed)");
307 + win_result = ExtTextOutW(dst->dc,
308 + start_x,
309 + start_y,
310 + glyph_index_option | ETO_PDY,
311 + NULL,
312 + glyph_buf,
313 + num_glyphs,
314 + dxy_buf);
315 + if (!win_result) {
316 + _cairo_win32_print_gdi_error("_cairo_win32_surface_show_glyphs(ExtTextOutW failed)");
319 - RestoreDC(dst->dc, -1);
320 + RestoreDC(dst->dc, -1);
322 - if (glyph_buf != glyph_buf_stack) {
323 - free(glyph_buf);
324 - free(dxy_buf);
325 + if (glyph_buf != glyph_buf_stack) {
326 + free(glyph_buf);
327 + free(dxy_buf);
329 + return (win_result) ? CAIRO_STATUS_SUCCESS : CAIRO_INT_STATUS_UNSUPPORTED;
331 - return (win_result) ? CAIRO_STATUS_SUCCESS : CAIRO_INT_STATUS_UNSUPPORTED;
332 #else
333 return CAIRO_INT_STATUS_UNSUPPORTED;
334 #endif
335 diff --git a/src/cairo-win32.h b/src/cairo-win32.h
336 index 6b86d4e..fcf20b8 100644
337 --- a/src/cairo-win32.h
338 +++ b/src/cairo-win32.h
339 @@ -109,6 +109,63 @@ cairo_win32_scaled_font_get_device_to_logical (cairo_scaled_font_t *scaled_font,
341 #endif /* CAIRO_HAS_WIN32_FONT */
343 +#if CAIRO_HAS_DWRITE_FONT
346 + * Win32 DirectWrite font support
347 + */
348 +cairo_public cairo_font_face_t *
349 +cairo_dwrite_font_face_create_for_dwrite_fontface(void *dwrite_font, void *dwrite_font_face);
351 +#endif /* CAIRO_HAS_DWRITE_FONT */
353 +#if CAIRO_HAS_D2D_SURFACE
355 +/**
356 + * Create a D2D surface for an HWND
358 + * \param wnd Handle for the window
359 + * \return New cairo surface
360 + */
361 +cairo_public cairo_surface_t *
362 +cairo_d2d_surface_create_for_hwnd(HWND wnd);
364 +/**
365 + * Create a D2D surface of a certain size.
367 + * \param format Cairo format of the surface
368 + * \param width Width of the surface
369 + * \param height Height of the surface
370 + * \return New cairo surface
371 + */
372 +cairo_public cairo_surface_t *
373 +cairo_d2d_surface_create(cairo_format_t format,
374 + int width,
375 + int height);
377 +/**
378 + * Present the backbuffer for a surface create for an HWND. This needs
379 + * to be called when the owner of the original window surface wants to
380 + * actually present the executed drawing operations to the screen.
382 + * \param surface D2D surface.
383 + */
384 +void cairo_d2d_present_backbuffer(cairo_surface_t *surface);
386 +/**
387 + * Scroll the surface, this only moves the surface graphics, it does not
388 + * actually scroll child windows or anything like that. Nor does it invalidate
389 + * that area of the window.
391 + * \param surface The d2d surface this operation should apply to.
392 + * \param x The x delta for the movement
393 + * \param y The y delta for the movement
394 + * \param clip The clip rectangle, the is the 'part' of the surface that needs
395 + * scrolling.
396 + */
397 +void cairo_d2d_scroll(cairo_surface_t *surface, int x, int y, cairo_rectangle_t *clip);
398 +#endif
400 CAIRO_END_DECLS
402 #else /* CAIRO_HAS_WIN32_SURFACE */
403 diff --git a/src/cairo.h b/src/cairo.h
404 index 3a8b8a6..21827aa 100644
405 --- a/src/cairo.h
406 +++ b/src/cairo.h
407 @@ -1370,7 +1370,8 @@ typedef enum _cairo_font_type {
408 CAIRO_FONT_TYPE_FT,
409 CAIRO_FONT_TYPE_WIN32,
410 CAIRO_FONT_TYPE_QUARTZ,
411 - CAIRO_FONT_TYPE_USER
412 + CAIRO_FONT_TYPE_USER,
413 + CAIRO_FONT_TYPE_DWRITE
414 } cairo_font_type_t;
416 cairo_public cairo_font_type_t
417 @@ -2009,7 +2010,8 @@ typedef enum _cairo_surface_type {
418 CAIRO_SURFACE_TYPE_TEE,
419 CAIRO_SURFACE_TYPE_XML,
420 CAIRO_SURFACE_TYPE_SKIA,
421 - CAIRO_SURFACE_TYPE_DDRAW
422 + CAIRO_SURFACE_TYPE_DDRAW,
423 + CAIRO_SURFACE_TYPE_D2D
424 } cairo_surface_type_t;
426 cairo_public cairo_surface_type_t
427 diff --git a/src/cairoint.h b/src/cairoint.h
428 index b942b4b..58850ab 100644
429 --- a/src/cairoint.h
430 +++ b/src/cairoint.h
431 @@ -587,6 +587,12 @@ extern const cairo_private struct _cairo_font_face_backend _cairo_win32_font_fac
433 #endif
435 +#if CAIRO_HAS_DWRITE_FONT
437 +extern const cairo_private struct _cairo_font_face_backend _cairo_dwrite_font_face_backend;
439 +#endif
441 #if CAIRO_HAS_QUARTZ_FONT
443 extern const cairo_private struct _cairo_font_face_backend _cairo_quartz_font_face_backend;
444 @@ -932,7 +938,12 @@ typedef struct _cairo_traps {
445 #define CAIRO_FT_FONT_FAMILY_DEFAULT ""
446 #define CAIRO_USER_FONT_FAMILY_DEFAULT "@cairo:"
448 -#if CAIRO_HAS_WIN32_FONT
449 +#if CAIRO_HAS_DWRITE_FONT
451 +#define CAIRO_FONT_FAMILY_DEFAULT CAIRO_WIN32_FONT_FAMILY_DEFAULT
452 +#define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_dwrite_font_face_backend
454 +#elif CAIRO_HAS_WIN32_FONT
456 #define CAIRO_FONT_FAMILY_DEFAULT CAIRO_WIN32_FONT_FAMILY_DEFAULT
457 #define CAIRO_FONT_FACE_BACKEND_DEFAULT &_cairo_win32_font_face_backend
458 @@ -2617,7 +2628,7 @@ cairo_private int
459 _cairo_ucs4_to_utf8 (uint32_t unicode,
460 char *utf8);
462 -#if CAIRO_HAS_WIN32_FONT || CAIRO_HAS_QUARTZ_FONT || CAIRO_HAS_PDF_OPERATORS
463 +#if CAIRO_HAS_WIN32_FONT || CAIRO_HAS_QUARTZ_FONT || CAIRO_HAS_PDF_OPERATORS || CAIRO_HAS_DW_FONT
464 # define CAIRO_HAS_UTF8_TO_UTF16 1
465 #endif
466 #if CAIRO_HAS_UTF8_TO_UTF16