1 /* Cairo - a vector graphics library with display and print output
3 * Copyright © 2005 Red Hat, Inc.
4 * Copyright © 2009 Intel Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it either under the terms of the GNU Lesser General Public
8 * License version 2.1 as published by the Free Software Foundation
9 * (the "LGPL") or, at your option, under the terms of the Mozilla
10 * Public License Version 1.1 (the "MPL"). If you do not alter this
11 * notice, a recipient may use your version of this file under either
12 * the MPL or the LGPL.
14 * You should have received a copy of the LGPL along with this library
15 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17 * You should have received a copy of the MPL along with this library
18 * in the file COPYING-MPL-1.1
20 * The contents of this file are subject to the Mozilla Public License
21 * Version 1.1 (the "License"); you may not use this file except in
22 * compliance with the License. You may obtain a copy of the License at
23 * http://www.mozilla.org/MPL/
25 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27 * the specific language governing rights and limitations.
29 * The Original Code is the cairo graphics library.
31 * The Initial Developer of the Original Code is Red Hat, Inc.
34 * Chris Wilson <chris@chris-wilson.co.uk>
37 #ifndef CAIRO_XCB_PRIVATE_H
38 #define CAIRO_XCB_PRIVATE_H
40 #include "cairo-xcb.h"
44 #include "cairo-cache-private.h"
45 #include "cairo-compiler-private.h"
46 #include "cairo-device-private.h"
47 #include "cairo-error-private.h"
48 #include "cairo-freelist-private.h"
49 #include "cairo-list-private.h"
50 #include "cairo-mutex-private.h"
51 #include "cairo-pattern-private.h"
52 #include "cairo-reference-count-private.h"
53 #include "cairo-scaled-font-private.h"
54 #include "cairo-spans-private.h"
55 #include "cairo-surface-private.h"
58 #include <xcb/render.h>
59 #include <xcb/xcbext.h>
62 #define XLIB_COORD_MAX 32767
64 /* maximum number of cached GC's */
65 #define GC_CACHE_SIZE 4
67 #define CAIRO_XCB_RENDER_AT_LEAST(major, minor) \
68 ((XCB_RENDER_MAJOR_VERSION > major) || \
69 ((XCB_RENDER_MAJOR_VERSION == major) && (XCB_RENDER_MINOR_VERSION >= minor)))
71 typedef struct _cairo_xcb_connection cairo_xcb_connection_t;
72 typedef struct _cairo_xcb_font cairo_xcb_font_t;
73 typedef struct _cairo_xcb_screen cairo_xcb_screen_t;
74 typedef struct _cairo_xcb_surface cairo_xcb_surface_t;
75 typedef struct _cairo_xcb_picture cairo_xcb_picture_t;
76 typedef struct _cairo_xcb_shm_mem_pool cairo_xcb_shm_mem_pool_t;
77 typedef struct _cairo_xcb_shm_info cairo_xcb_shm_info_t;
79 struct _cairo_xcb_shm_info {
80 cairo_xcb_connection_t *connection;
85 cairo_xcb_shm_mem_pool_t *pool;
86 xcb_get_input_focus_cookie_t sync;
90 struct _cairo_xcb_surface {
92 cairo_image_surface_t *fallback;
93 cairo_boxes_t fallback_damage;
95 cairo_xcb_connection_t *connection;
96 cairo_xcb_screen_t *screen;
98 xcb_drawable_t drawable;
99 cairo_bool_t owns_pixmap;
101 cairo_bool_t deferred_clear;
102 cairo_color_t deferred_clear_color;
108 xcb_render_picture_t picture;
109 xcb_render_pictformat_t xrender_format;
110 pixman_format_code_t pixman_format;
116 struct _cairo_xcb_picture {
117 cairo_surface_t base;
119 cairo_xcb_screen_t *screen;
120 xcb_render_picture_t picture;
121 xcb_render_pictformat_t xrender_format;
122 pixman_format_code_t pixman_format;
126 cairo_extend_t extend;
127 cairo_filter_t filter;
128 cairo_bool_t has_component_alpha;
129 xcb_render_transform_t transform;
137 #if CAIRO_HAS_XLIB_XCB_FUNCTIONS
138 typedef struct _cairo_xlib_xcb_surface {
139 cairo_surface_t base;
141 cairo_xcb_surface_t *xcb;
143 /* original settings for query */
148 } cairo_xlib_xcb_surface_t;
153 GLYPHSET_INDEX_ARGB32,
159 typedef struct _cairo_xcb_font_glyphset_free_glyphs {
160 xcb_render_glyphset_t glyphset;
162 xcb_render_glyph_t glyph_indices[128];
163 } cairo_xcb_font_glyphset_free_glyphs_t;
165 typedef struct _cairo_xcb_font_glyphset_info {
166 xcb_render_glyphset_t glyphset;
167 cairo_format_t format;
168 xcb_render_pictformat_t xrender_format;
169 cairo_xcb_font_glyphset_free_glyphs_t *pending_free_glyphs;
170 } cairo_xcb_font_glyphset_info_t;
172 struct _cairo_xcb_font {
173 cairo_scaled_font_private_t base;
174 cairo_scaled_font_t *scaled_font;
175 cairo_xcb_connection_t *connection;
176 cairo_xcb_font_glyphset_info_t glyphset_info[NUM_GLYPHSETS];
180 struct _cairo_xcb_screen {
181 cairo_xcb_connection_t *connection;
183 xcb_screen_t *xcb_screen;
185 xcb_gcontext_t gc[GC_CACHE_SIZE];
186 uint8_t gc_depths[GC_CACHE_SIZE];
188 cairo_surface_t *stock_colors[CAIRO_STOCK_NUM_COLORS];
190 cairo_surface_t *picture;
193 int solid_cache_size;
195 cairo_cache_t linear_pattern_cache;
196 cairo_cache_t radial_pattern_cache;
197 cairo_freelist_t pattern_cache_entry_freelist;
200 cairo_list_t surfaces;
201 cairo_list_t pictures;
204 struct _cairo_xcb_connection {
205 cairo_device_t device;
207 xcb_connection_t *xcb_connection;
209 xcb_render_pictformat_t standard_formats[5];
210 cairo_hash_table_t *xrender_formats;
211 cairo_hash_table_t *visual_to_xrender_format;
213 unsigned int maximum_request_length;
215 unsigned int original_flags;
219 const xcb_setup_t *root;
220 const xcb_query_extension_reply_t *render;
221 const xcb_query_extension_reply_t *shm;
223 cairo_list_t free_xids;
224 cairo_freepool_t xid_pool;
226 cairo_mutex_t shm_mutex;
227 cairo_list_t shm_pools;
228 cairo_list_t shm_pending;
229 cairo_freepool_t shm_info_freelist;
231 cairo_mutex_t screens_mutex;
232 cairo_list_t screens;
240 CAIRO_XCB_HAS_RENDER = 0x0001,
241 CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES = 0x0002,
242 CAIRO_XCB_RENDER_HAS_COMPOSITE = 0x0004,
243 CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS = 0x0008,
244 CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS = 0x0010,
245 CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM = 0x0020,
246 CAIRO_XCB_RENDER_HAS_FILTERS = 0x0040,
247 CAIRO_XCB_RENDER_HAS_PDF_OPERATORS = 0x0080,
248 CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT = 0x0100,
249 CAIRO_XCB_RENDER_HAS_GRADIENTS = 0x0200,
251 CAIRO_XCB_HAS_SHM = 0x80000000,
253 CAIRO_XCB_RENDER_MASK = CAIRO_XCB_HAS_RENDER |
254 CAIRO_XCB_RENDER_HAS_FILL_RECTANGLES |
255 CAIRO_XCB_RENDER_HAS_COMPOSITE |
256 CAIRO_XCB_RENDER_HAS_COMPOSITE_TRAPEZOIDS |
257 CAIRO_XCB_RENDER_HAS_COMPOSITE_GLYPHS |
258 CAIRO_XCB_RENDER_HAS_PICTURE_TRANSFORM |
259 CAIRO_XCB_RENDER_HAS_FILTERS |
260 CAIRO_XCB_RENDER_HAS_PDF_OPERATORS |
261 CAIRO_XCB_RENDER_HAS_EXTENDED_REPEAT |
262 CAIRO_XCB_RENDER_HAS_GRADIENTS,
263 CAIRO_XCB_SHM_MASK = CAIRO_XCB_HAS_SHM
266 #define CAIRO_XCB_SHM_SMALL_IMAGE 8192
268 cairo_private extern const cairo_surface_backend_t _cairo_xcb_surface_backend;
270 cairo_private cairo_xcb_connection_t *
271 _cairo_xcb_connection_get (xcb_connection_t *connection);
273 static inline cairo_xcb_connection_t *
274 _cairo_xcb_connection_reference (cairo_xcb_connection_t *connection)
276 return (cairo_xcb_connection_t *) cairo_device_reference (&connection->device);
279 cairo_private xcb_render_pictformat_t
280 _cairo_xcb_connection_get_xrender_format (cairo_xcb_connection_t *connection,
281 pixman_format_code_t pixman_format);
283 cairo_private xcb_render_pictformat_t
284 _cairo_xcb_connection_get_xrender_format_for_visual (cairo_xcb_connection_t *connection,
285 const xcb_visualid_t visual);
287 static inline cairo_status_t cairo_warn
288 _cairo_xcb_connection_acquire (cairo_xcb_connection_t *connection)
290 return cairo_device_acquire (&connection->device);
293 cairo_private uint32_t
294 _cairo_xcb_connection_get_xid (cairo_xcb_connection_t *connection);
297 _cairo_xcb_connection_put_xid (cairo_xcb_connection_t *connection,
301 _cairo_xcb_connection_release (cairo_xcb_connection_t *connection)
303 cairo_device_release (&connection->device);
307 _cairo_xcb_connection_destroy (cairo_xcb_connection_t *connection)
309 cairo_device_destroy (&connection->device);
312 cairo_private cairo_int_status_t
313 _cairo_xcb_connection_allocate_shm_info (cairo_xcb_connection_t *display,
315 cairo_bool_t might_reuse,
316 cairo_xcb_shm_info_t **shm_info_out);
319 _cairo_xcb_shm_info_destroy (cairo_xcb_shm_info_t *shm_info);
322 _cairo_xcb_connection_shm_mem_pools_flush (cairo_xcb_connection_t *connection);
325 _cairo_xcb_connection_shm_mem_pools_fini (cairo_xcb_connection_t *connection);
328 _cairo_xcb_font_close (cairo_xcb_font_t *font);
330 cairo_private cairo_xcb_screen_t *
331 _cairo_xcb_screen_get (xcb_connection_t *connection,
332 xcb_screen_t *screen);
335 _cairo_xcb_screen_finish (cairo_xcb_screen_t *screen);
337 cairo_private xcb_gcontext_t
338 _cairo_xcb_screen_get_gc (cairo_xcb_screen_t *screen,
339 xcb_drawable_t drawable,
343 _cairo_xcb_screen_put_gc (cairo_xcb_screen_t *screen, int depth, xcb_gcontext_t gc);
345 cairo_private cairo_status_t
346 _cairo_xcb_screen_store_linear_picture (cairo_xcb_screen_t *screen,
347 const cairo_linear_pattern_t *linear,
348 cairo_surface_t *picture);
350 cairo_private cairo_surface_t *
351 _cairo_xcb_screen_lookup_linear_picture (cairo_xcb_screen_t *screen,
352 const cairo_linear_pattern_t *linear);
354 cairo_private cairo_status_t
355 _cairo_xcb_screen_store_radial_picture (cairo_xcb_screen_t *screen,
356 const cairo_radial_pattern_t *radial,
357 cairo_surface_t *picture);
359 cairo_private cairo_surface_t *
360 _cairo_xcb_screen_lookup_radial_picture (cairo_xcb_screen_t *screen,
361 const cairo_radial_pattern_t *radial);
363 cairo_private cairo_surface_t *
364 _cairo_xcb_surface_create_similar_image (void *abstrct_other,
365 cairo_format_t format,
369 cairo_private cairo_surface_t *
370 _cairo_xcb_surface_create_similar (void *abstract_other,
371 cairo_content_t content,
375 cairo_private cairo_surface_t *
376 _cairo_xcb_surface_create_internal (cairo_xcb_screen_t *screen,
377 xcb_drawable_t drawable,
378 cairo_bool_t owns_pixmap,
379 pixman_format_code_t pixman_format,
380 xcb_render_pictformat_t xrender_format,
384 cairo_private_no_warn cairo_bool_t
385 _cairo_xcb_surface_get_extents (void *abstract_surface,
386 cairo_rectangle_int_t *extents);
388 cairo_private cairo_int_status_t
389 _cairo_xcb_render_compositor_paint (const cairo_compositor_t *compositor,
390 cairo_composite_rectangles_t *extents);
392 cairo_private cairo_int_status_t
393 _cairo_xcb_render_compositor_mask (const cairo_compositor_t *compositor,
394 cairo_composite_rectangles_t *extents);
396 cairo_private cairo_int_status_t
397 _cairo_xcb_render_compositor_stroke (const cairo_compositor_t *compositor,
398 cairo_composite_rectangles_t *extents,
399 const cairo_path_fixed_t *path,
400 const cairo_stroke_style_t *style,
401 const cairo_matrix_t *ctm,
402 const cairo_matrix_t *ctm_inverse,
404 cairo_antialias_t antialias);
406 cairo_private cairo_int_status_t
407 _cairo_xcb_render_compositor_fill (const cairo_compositor_t *compositor,
408 cairo_composite_rectangles_t *extents,
409 const cairo_path_fixed_t *path,
410 cairo_fill_rule_t fill_rule,
412 cairo_antialias_t antialias);
414 cairo_private cairo_int_status_t
415 _cairo_xcb_render_compositor_glyphs (const cairo_compositor_t *compositor,
416 cairo_composite_rectangles_t *extents,
417 cairo_scaled_font_t *scaled_font,
418 cairo_glyph_t *glyphs,
420 cairo_bool_t overlap);
422 _cairo_xcb_surface_scaled_font_fini (cairo_scaled_font_t *scaled_font);
425 _cairo_xcb_surface_scaled_glyph_fini (cairo_scaled_glyph_t *scaled_glyph,
426 cairo_scaled_font_t *scaled_font);
428 cairo_private cairo_status_t
429 _cairo_xcb_surface_clear (cairo_xcb_surface_t *dst);
431 cairo_private cairo_status_t
432 _cairo_xcb_surface_core_copy_boxes (cairo_xcb_surface_t *dst,
433 const cairo_pattern_t *src_pattern,
434 const cairo_rectangle_int_t *extents,
435 const cairo_boxes_t *boxes);
437 cairo_private cairo_status_t
438 _cairo_xcb_surface_core_fill_boxes (cairo_xcb_surface_t *dst,
439 const cairo_color_t *color,
440 cairo_boxes_t *boxes);
442 cairo_private xcb_pixmap_t
443 _cairo_xcb_connection_create_pixmap (cairo_xcb_connection_t *connection,
445 xcb_drawable_t drawable,
450 _cairo_xcb_connection_free_pixmap (cairo_xcb_connection_t *connection,
451 xcb_pixmap_t pixmap);
453 cairo_private xcb_gcontext_t
454 _cairo_xcb_connection_create_gc (cairo_xcb_connection_t *connection,
455 xcb_drawable_t drawable,
460 _cairo_xcb_connection_free_gc (cairo_xcb_connection_t *connection,
464 _cairo_xcb_connection_change_gc (cairo_xcb_connection_t *connection,
470 _cairo_xcb_connection_copy_area (cairo_xcb_connection_t *connection,
482 _cairo_xcb_connection_put_image (cairo_xcb_connection_t *connection,
494 _cairo_xcb_connection_put_subimage (cairo_xcb_connection_t *connection,
508 cairo_private cairo_status_t
509 _cairo_xcb_connection_get_image (cairo_xcb_connection_t *connection,
515 xcb_get_image_reply_t **reply);
518 _cairo_xcb_connection_poly_fill_rectangle (cairo_xcb_connection_t *connection,
521 uint32_t num_rectangles,
522 xcb_rectangle_t *rectangles);
524 cairo_private cairo_status_t
525 _cairo_xcb_shm_image_create (cairo_xcb_connection_t *connection,
526 pixman_format_code_t pixman_format,
527 int width, int height,
528 cairo_image_surface_t **image_out,
529 cairo_xcb_shm_info_t **shm_info_out);
531 #if CAIRO_HAS_XCB_SHM_FUNCTIONS
532 cairo_private uint32_t
533 _cairo_xcb_connection_shm_attach (cairo_xcb_connection_t *connection,
535 cairo_bool_t readonly);
538 _cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection,
541 uint16_t total_width,
542 uint16_t total_height,
553 cairo_private cairo_status_t
554 _cairo_xcb_connection_shm_get_image (cairo_xcb_connection_t *connection,
564 _cairo_xcb_connection_shm_detach (cairo_xcb_connection_t *connection,
568 _cairo_xcb_connection_shm_put_image (cairo_xcb_connection_t *connection,
571 uint16_t total_width,
572 uint16_t total_height,
588 _cairo_xcb_connection_render_create_picture (cairo_xcb_connection_t *connection,
589 xcb_render_picture_t picture,
590 xcb_drawable_t drawable,
591 xcb_render_pictformat_t format,
593 uint32_t *value_list);
596 _cairo_xcb_connection_render_change_picture (cairo_xcb_connection_t *connection,
597 xcb_render_picture_t picture,
599 uint32_t *value_list);
602 _cairo_xcb_connection_render_set_picture_clip_rectangles (cairo_xcb_connection_t *connection,
603 xcb_render_picture_t picture,
604 int16_t clip_x_origin,
605 int16_t clip_y_origin,
606 uint32_t rectangles_len,
607 xcb_rectangle_t *rectangles);
610 _cairo_xcb_connection_render_free_picture (cairo_xcb_connection_t *connection,
611 xcb_render_picture_t picture);
614 _cairo_xcb_connection_render_composite (cairo_xcb_connection_t *connection,
616 xcb_render_picture_t src,
617 xcb_render_picture_t mask,
618 xcb_render_picture_t dst,
629 _cairo_xcb_connection_render_trapezoids (cairo_xcb_connection_t *connection,
631 xcb_render_picture_t src,
632 xcb_render_picture_t dst,
633 xcb_render_pictformat_t mask_format,
637 xcb_render_trapezoid_t *traps);
640 _cairo_xcb_connection_render_create_glyph_set (cairo_xcb_connection_t *connection,
641 xcb_render_glyphset_t id,
642 xcb_render_pictformat_t format);
645 _cairo_xcb_connection_render_free_glyph_set (cairo_xcb_connection_t *connection,
646 xcb_render_glyphset_t glyphset);
649 _cairo_xcb_connection_render_add_glyphs (cairo_xcb_connection_t *connection,
650 xcb_render_glyphset_t glyphset,
653 xcb_render_glyphinfo_t *glyphs,
658 _cairo_xcb_connection_render_free_glyphs (cairo_xcb_connection_t *connection,
659 xcb_render_glyphset_t glyphset,
661 xcb_render_glyph_t *glyphs);
664 _cairo_xcb_connection_render_composite_glyphs_8 (cairo_xcb_connection_t *connection,
666 xcb_render_picture_t src,
667 xcb_render_picture_t dst,
668 xcb_render_pictformat_t mask_format,
669 xcb_render_glyphset_t glyphset,
672 uint32_t glyphcmds_len,
676 _cairo_xcb_connection_render_composite_glyphs_16 (cairo_xcb_connection_t *connection,
678 xcb_render_picture_t src,
679 xcb_render_picture_t dst,
680 xcb_render_pictformat_t mask_format,
681 xcb_render_glyphset_t glyphset,
684 uint32_t glyphcmds_len,
688 _cairo_xcb_connection_render_composite_glyphs_32 (cairo_xcb_connection_t *connection,
690 xcb_render_picture_t src,
691 xcb_render_picture_t dst,
692 xcb_render_pictformat_t mask_format,
693 xcb_render_glyphset_t glyphset,
696 uint32_t glyphcmds_len,
700 _cairo_xcb_connection_render_fill_rectangles (cairo_xcb_connection_t *connection,
702 xcb_render_picture_t dst,
703 xcb_render_color_t color,
705 xcb_rectangle_t *rects);
708 _cairo_xcb_connection_render_set_picture_transform (cairo_xcb_connection_t *connection,
709 xcb_render_picture_t picture,
710 xcb_render_transform_t *transform);
713 _cairo_xcb_connection_render_set_picture_filter (cairo_xcb_connection_t *connection,
714 xcb_render_picture_t picture,
718 xcb_render_fixed_t *values);
721 _cairo_xcb_connection_render_create_solid_fill (cairo_xcb_connection_t *connection,
722 xcb_render_picture_t picture,
723 xcb_render_color_t color);
726 _cairo_xcb_connection_render_create_linear_gradient (cairo_xcb_connection_t *connection,
727 xcb_render_picture_t picture,
728 xcb_render_pointfix_t p1,
729 xcb_render_pointfix_t p2,
731 xcb_render_fixed_t *stops,
732 xcb_render_color_t *colors);
735 _cairo_xcb_connection_render_create_radial_gradient (cairo_xcb_connection_t *connection,
736 xcb_render_picture_t picture,
737 xcb_render_pointfix_t inner,
738 xcb_render_pointfix_t outer,
739 xcb_render_fixed_t inner_radius,
740 xcb_render_fixed_t outer_radius,
742 xcb_render_fixed_t *stops,
743 xcb_render_color_t *colors);
746 _cairo_xcb_connection_render_create_conical_gradient (cairo_xcb_connection_t *c,
747 xcb_render_picture_t picture,
748 xcb_render_pointfix_t center,
749 xcb_render_fixed_t angle,
751 xcb_render_fixed_t *stops,
752 xcb_render_color_t *colors);
754 cairo_private cairo_xcb_picture_t *
755 _cairo_xcb_gaussian_filter (cairo_xcb_surface_t *target,
756 cairo_xcb_picture_t *orig_pict,
757 const cairo_pattern_t *pattern);
759 #if CAIRO_HAS_XLIB_XCB_FUNCTIONS
760 slim_hidden_proto (cairo_xcb_surface_create);
761 slim_hidden_proto (cairo_xcb_surface_create_for_bitmap);
762 slim_hidden_proto (cairo_xcb_surface_create_with_xrender_format);
763 slim_hidden_proto (cairo_xcb_surface_set_size);
764 slim_hidden_proto (cairo_xcb_surface_set_drawable);
765 slim_hidden_proto (cairo_xcb_device_debug_get_precision);
766 slim_hidden_proto_no_warn (cairo_xcb_device_debug_set_precision);
767 slim_hidden_proto_no_warn (cairo_xcb_device_debug_cap_xrender_version);
770 #endif /* CAIRO_XCB_PRIVATE_H */